Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StdoutAdapter is a simple file adapter that writes
	// all logs to os.Stdout using a predefined format.
	StdoutAdapter = &SimpleFileAdapter{
		File:   os.Stdout,
		Format: defaultColorFormater,
	}

	// StderrAdapter is a simple file adapter that writes
	// all logs to os.Stdout using a predefined format.
	StderrAdapter = &SimpleFileAdapter{
		File:   os.Stderr,
		Format: defaultColorFormater,
	}
)

Functions

func Critical

func Critical(msg string)

    Critical is used to log events that completely break the system. Operation connot continue. User/Admin must be informed.

    func Criticalf

    func Criticalf(format string, things ...interface{})

      Criticalf is used to log events that completely break the system. Operation connot continue. User/Admin must be informed.

      func Debug

      func Debug(msg string)

        Debug is used to log minor errors or unexpected events. These occurrences are usually not worth mentioning in itself, but they might hint at a bigger problem.

        func Debugf

        func Debugf(format string, things ...interface{})

          Debugf is used to log minor errors or unexpected events. These occurrences are usually not worth mentioning in itself, but they might hint at a bigger problem.

          func EnableScheduling

          func EnableScheduling()

            EnableScheduling enables external scheduling of the logger. This will require to manually trigger writes via TriggerWrite whenevery logs should be written. Please note that full buffers will also trigger writing. Must be called before Start() to have an effect.

            func Error

            func Error(msg string)

              Error is used to log errors that break or impair functionality. The task/process may have to be aborted and tried again later. The system is still operational. Maybe User/Admin should be informed.

              func Errorf

              func Errorf(format string, things ...interface{})

                Errorf is used to log errors that break or impair functionality. The task/process may have to be aborted and tried again later. The system is still operational.

                func GetLastUnexpectedLogs

                func GetLastUnexpectedLogs() []string

                  GetLastUnexpectedLogs returns the last 10 log lines of level Warning an up.

                  func Info

                  func Info(msg string)

                    Info is used to log mildly significant events. Should be used to inform about somewhat bigger or user affecting events that happen.

                    func Infof

                    func Infof(format string, things ...interface{})

                      Infof is used to log mildly significant events. Should be used to inform about somewhat bigger or user affecting events that happen.

                      func SetAdapter

                      func SetAdapter(a Adapter)

                        SetAdapter configures the logging adapter to use. This must be called before the log package is initialized.

                        func SetLogLevel

                        func SetLogLevel(level Severity)

                          SetLogLevel sets a new log level. Only effective after Start().

                          func SetPkgLevels

                          func SetPkgLevels(levels map[string]Severity)

                            SetPkgLevels sets individual log levels for packages. Only effective after Start().

                            func Shutdown

                            func Shutdown()

                              Shutdown writes remaining log lines and then stops the log system.

                              func Start

                              func Start() (err error)

                                Start starts the logging system. Must be called in order to see logs.

                                func Trace

                                func Trace(msg string)

                                  Trace is used to log tiny steps. Log traces to context if you can!

                                  func Tracef

                                  func Tracef(format string, things ...interface{})

                                    Tracef is used to log tiny steps. Log traces to context if you can!

                                    func TriggerWriter

                                    func TriggerWriter()

                                      TriggerWriter triggers log output writing.

                                      func TriggerWriterChannel

                                      func TriggerWriterChannel() chan struct{}

                                        TriggerWriterChannel returns the channel to trigger log writing. Returned channel will close if EnableScheduling() is not called correctly.

                                        func UnSetPkgLevels

                                        func UnSetPkgLevels()

                                          UnSetPkgLevels removes all individual log levels for packages.

                                          func Warning

                                          func Warning(msg string)

                                            Warning is used to log (potentially) bad events, but nothing broke (even a little) and there is no need to panic yet.

                                            func Warningf

                                            func Warningf(format string, things ...interface{})

                                              Warningf is used to log (potentially) bad events, but nothing broke (even a little) and there is no need to panic yet.

                                              Types

                                              type Adapter

                                              type Adapter interface {
                                              	// Write is called for each log message.
                                              	Write(msg Message, duplicates uint64)
                                              }

                                                Adapter is used to write logs.

                                                type AdapterFunc

                                                type AdapterFunc func(msg Message, duplciates uint64)

                                                  AdapterFunc is a convenience type for implementing Adapter.

                                                  func (AdapterFunc) Write

                                                  func (fn AdapterFunc) Write(msg Message, duplicates uint64)

                                                    Write implements Adapter and calls fn.

                                                    type ContextTracer

                                                    type ContextTracer struct {
                                                    	sync.Mutex
                                                    	// contains filtered or unexported fields
                                                    }

                                                      ContextTracer is attached to a context in order bind logs to a context.

                                                      func AddTracer

                                                      func AddTracer(ctx context.Context) (context.Context, *ContextTracer)

                                                        AddTracer adds a ContextTracer to the returned Context. Will return a nil ContextTracer if logging level is not set to trace. Will return a nil ContextTracer if one already exists. Will return a nil ContextTracer in case of an error. Will return a nil context if nil.

                                                        func Tracer

                                                        func Tracer(ctx context.Context) *ContextTracer

                                                          Tracer returns the ContextTracer previously added to the given Context.

                                                          func (*ContextTracer) Critical

                                                          func (tracer *ContextTracer) Critical(msg string)

                                                            Critical is used to log events that completely break the system. Operation connot continue. User/Admin must be informed.

                                                            func (*ContextTracer) Criticalf

                                                            func (tracer *ContextTracer) Criticalf(format string, things ...interface{})

                                                              Criticalf is used to log events that completely break the system. Operation connot continue. User/Admin must be informed.

                                                              func (*ContextTracer) Debug

                                                              func (tracer *ContextTracer) Debug(msg string)

                                                                Debug is used to log minor errors or unexpected events. These occurrences are usually not worth mentioning in itself, but they might hint at a bigger problem.

                                                                func (*ContextTracer) Debugf

                                                                func (tracer *ContextTracer) Debugf(format string, things ...interface{})

                                                                  Debugf is used to log minor errors or unexpected events. These occurrences are usually not worth mentioning in itself, but they might hint at a bigger problem.

                                                                  func (*ContextTracer) Error

                                                                  func (tracer *ContextTracer) Error(msg string)

                                                                    Error is used to log errors that break or impair functionality. The task/process may have to be aborted and tried again later. The system is still operational. Maybe User/Admin should be informed.

                                                                    func (*ContextTracer) Errorf

                                                                    func (tracer *ContextTracer) Errorf(format string, things ...interface{})

                                                                      Errorf is used to log errors that break or impair functionality. The task/process may have to be aborted and tried again later. The system is still operational.

                                                                      func (*ContextTracer) Info

                                                                      func (tracer *ContextTracer) Info(msg string)

                                                                        Info is used to log mildly significant events. Should be used to inform about somewhat bigger or user affecting events that happen.

                                                                        func (*ContextTracer) Infof

                                                                        func (tracer *ContextTracer) Infof(format string, things ...interface{})

                                                                          Infof is used to log mildly significant events. Should be used to inform about somewhat bigger or user affecting events that happen.

                                                                          func (*ContextTracer) Submit

                                                                          func (tracer *ContextTracer) Submit()

                                                                            Submit collected logs on the context for further processing/outputting. Does nothing if called on a nil ContextTracer.

                                                                            func (*ContextTracer) Trace

                                                                            func (tracer *ContextTracer) Trace(msg string)

                                                                              Trace is used to log tiny steps. Log traces to context if you can!

                                                                              func (*ContextTracer) Tracef

                                                                              func (tracer *ContextTracer) Tracef(format string, things ...interface{})

                                                                                Tracef is used to log tiny steps. Log traces to context if you can!

                                                                                func (*ContextTracer) Warning

                                                                                func (tracer *ContextTracer) Warning(msg string)

                                                                                  Warning is used to log (potentially) bad events, but nothing broke (even a little) and there is no need to panic yet.

                                                                                  func (*ContextTracer) Warningf

                                                                                  func (tracer *ContextTracer) Warningf(format string, things ...interface{})

                                                                                    Warningf is used to log (potentially) bad events, but nothing broke (even a little) and there is no need to panic yet.

                                                                                    type ContextTracerKey

                                                                                    type ContextTracerKey struct{}

                                                                                      ContextTracerKey is the key used for the context key/value storage.

                                                                                      type FormatFunc

                                                                                      type FormatFunc func(msg Message, duplciates uint64) string

                                                                                        FormatFunc formats msg into a string.

                                                                                        type Message

                                                                                        type Message interface {
                                                                                        	Text() string
                                                                                        	Severity() Severity
                                                                                        	Time() time.Time
                                                                                        	File() string
                                                                                        	LineNumber() int
                                                                                        }

                                                                                          Message describes a log level message and is implemented by logLine.

                                                                                          type Severity

                                                                                          type Severity uint32

                                                                                            Severity describes a log level.

                                                                                            const (
                                                                                            	TraceLevel    Severity = 1
                                                                                            	DebugLevel    Severity = 2
                                                                                            	InfoLevel     Severity = 3
                                                                                            	WarningLevel  Severity = 4
                                                                                            	ErrorLevel    Severity = 5
                                                                                            	CriticalLevel Severity = 6
                                                                                            )

                                                                                              Log Levels

                                                                                              func ParseLevel

                                                                                              func ParseLevel(level string) Severity

                                                                                                ParseLevel returns the level severity of a log level name.

                                                                                                func (Severity) String

                                                                                                func (s Severity) String() string

                                                                                                type SimpleFileAdapter

                                                                                                type SimpleFileAdapter struct {
                                                                                                	Format FormatFunc
                                                                                                	File   *os.File
                                                                                                }

                                                                                                  SimpleFileAdapter implements Adapter and writes all messages to File.

                                                                                                  func (*SimpleFileAdapter) Write

                                                                                                  func (fileAdapter *SimpleFileAdapter) Write(msg Message, duplicates uint64)

                                                                                                    Write implements Adapter and writes msg the underlying file.

                                                                                                    GOOS=linux, GOARCH=amd64