logmanager

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 16 Imported by: 1

README

Logmanager

Go Reference Go Workflow Coverage Status Go Report Latest Release License


Table of Contents

  1. Introduction
  2. Installation
  3. Usage
  4. Contributing
  5. License

Introduction

Logmanager is yet another Go logging library.

Installation

Install using go get
 go get github.com/axiomhq/logmanager
Install from source
 git clone https://github.com/axiomhq/logmanager.git
 cd logmanager
 make 

Usage

// Simple console logger
log2console := logmanager.GetLogger("foo.bar")
log2console.Info("hello world")
log2console.Warn("it's a trap")

// Prints:
// [09:15:54.24] info  main@foo.bar main.go:10 hello world
// [09:15:54.24] warn  main@foo.bar main.go:11 it's a trap

Contributing

Feel free to submit PRs or to fill issues. Every kind of help is appreciated.

Before committing, make should run without any issues.

Kindly check our Contributing guide on how to propose bugfixes and improvements, and submitting pull requests to the project.

License

© Axiom, Inc., 2021

Distributed under MIT License (The MIT License).

See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SPrintCaller

func SPrintCaller(skip int) string

SPrintCaller returns a string with information about caller

func SPrintStack

func SPrintStack(skip, max int) string

SPrintStack will print the current stack to a returned string

func SetCustomWriters

func SetCustomWriters(writers ...Writer)

SetCustomWriters ...

Types

type ColorTheme

type ColorTheme struct {
	Module string
	Levels []string
}

ColorTheme ...

type ConsoleWriter

type ConsoleWriter struct {
}

ConsoleWriter will write out to a console

func NewConsoleWriter

func NewConsoleWriter() *ConsoleWriter

NewConsoleWriter ...

func (*ConsoleWriter) BuildTheme

func (w *ConsoleWriter) BuildTheme(module string) ColorTheme

BuildTheme ...

func (*ConsoleWriter) Log

func (w *ConsoleWriter) Log(level Level, theme ColorTheme, module, filename string, line int, timestamp time.Time, message string)

Log ...

type DiskWriter

type DiskWriter struct {
	DiskWriterConfig
	// contains filtered or unexported fields
}

DiskWriter ...

func NewDiskWriter

func NewDiskWriter(logpath string, config DiskWriterConfig) *DiskWriter

NewDiskWriter ...

func (*DiskWriter) BuildTheme

func (w *DiskWriter) BuildTheme(string) ColorTheme

BuildTheme ...

func (*DiskWriter) Close

func (w *DiskWriter) Close()

Close will end the writer

func (*DiskWriter) Log

func (w *DiskWriter) Log(level Level, _ ColorTheme, module, filename string, line int, timestamp time.Time, message string)

Log ...

type DiskWriterConfig

type DiskWriterConfig struct {
	RotateDuration  time.Duration // rotates after time.Duration since log file creation date
	MaximumLogFiles int
}

DiskWriterConfig ...

type Level

type Level uint64

Level defines the log level, from Trace to Critical

const (
	Trace Level = iota
	Debug
	Info
	Warning
	Error
	Critical
)

Levels

func (*Level) Get

func (l *Level) Get() Level

Get ...

func (*Level) Set

func (l *Level) Set(newLevel Level)

Set ...

func (*Level) String

func (l *Level) String() string

String ...

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a logmanager base logger

func GetLogger

func GetLogger(name string) Logger

GetLogger will get a logger for the specified name

func (*Logger) CheckErr

func (l *Logger) CheckErr(f func() error)

CheckErr will close closer when called, and print an error if one is returned. This function is intended to be used in defer scenarios, where the error would otherwise be lost

func (*Logger) Critical

func (l *Logger) Critical(message string, args ...interface{})

Critical ...

func (*Logger) Debug

func (l *Logger) Debug(message string, args ...interface{})

Debug ...

func (*Logger) Error

func (l *Logger) Error(message string, args ...interface{}) error

Error ...

func (*Logger) Info

func (l *Logger) Info(message string, args ...interface{})

Info ...

func (*Logger) IsDebugEnabled

func (l *Logger) IsDebugEnabled() bool

IsDebugEnabled will return if debug is enabled, for this specific logger. note this is a bad mechanism to detect a general debug build state. for that you should use build flags

func (*Logger) IsError

func (l *Logger) IsError(err error) bool

IsError is a good replacement for if err != nil { you can use if log.IsError(err) { and avoid having to write the same error logging code again and again. also much more useful error logging

func (*Logger) JSONify

func (l *Logger) JSONify(v interface{}) string

JSONify will attempt to jsonify the given structure useful for debugging shorthand for encoding/json marshalling but handling errors and conversion to string

func (*Logger) JSONifyIndent

func (l *Logger) JSONifyIndent(v interface{}) string

JSONifyIndent will attempt to jsonify the given structure - with opinionated indenting useful for debugging shorthand for encoding/json marshalling but handling errors and conversion to string

func (*Logger) Log

func (l *Logger) Log(level Level, message string, args ...interface{})

Log ...

func (*Logger) LogLevel

func (l *Logger) LogLevel() Level

LogLevel will return the current log level

func (*Logger) PrintCaller

func (l *Logger) PrintCaller(skip int)

PrintCaller prints caller of this function

func (*Logger) PrintStackTrace

func (l *Logger) PrintStackTrace()

PrintStackTrace will print the current stack out to the info logger channel

func (*Logger) Recover

func (l *Logger) Recover(v interface{}) error

Recover is intended to be used when recovering from panics, it will function similarly to IsError in that it will output a stacktrace, but it has additional handling to strip out the panic stack err is interface{} for convenience as that is what you will receieve from recover() example:

     func mycode() (err error) {
         defer func() {
				if r := logger.Recover(recover()); r != nil{
					err = r
				}
			}()
         panic(errors.New("oh no"))
         return nil
     }

in addition Recover will covert any string(er) type to an error if an error is not found

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(level Level)

SetLogLevel will set the given log level

func (*Logger) Trace

func (l *Logger) Trace(message string, args ...interface{})

Trace ...

func (*Logger) Warn

func (l *Logger) Warn(message string, args ...interface{})

Warn ...

type SyslogWriter

type SyslogWriter struct {
	// contains filtered or unexported fields
}

SyslogWriter ...

func NewSyslogWriter

func NewSyslogWriter(network, raddr string) (*SyslogWriter, error)

NewSyslogWriter returns a writer that will send log messages to a syslog server configured with the provied network, raddr strings. Passing in "" as the network will default to using default unix sockets

func (*SyslogWriter) BuildTheme

func (w *SyslogWriter) BuildTheme(module string) ColorTheme

BuildTheme ...

func (*SyslogWriter) Log

func (w *SyslogWriter) Log(level Level, _ ColorTheme, module, filename string, line int, timestamp time.Time, message string)

Log ...

type Writer

type Writer interface {
	Log(level Level, theme ColorTheme, module string, filename string, line int, timestamp time.Time, message string)
	BuildTheme(module string) ColorTheme
}

Writer defines something that accepts log input, it is expected to send it somewhere

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL