Skip to content

codemodify/systemkit-logging

Repository files navigation

Logging

The missing robust, flexible, complete and advanced logging framework for Go

Check https://github.com/codemodify/systemkit-logging-tests to see usages of basic, intermediary and advanced with concurrency

How It Works

The concept is as follows:

  • LogEntry is logged and sent into a pipe
  • Each block in the transformation pipe may apply a transformation to the LogEntry and pass it along

Example A: consider the defined pipe below form left to right

What happens is that a LogEntry is sent to the first transformer in the pipe that will format the log message, then the next one will save it to a file.

PIPE Formatters Persisters
DATA LogEntry Simple File

Example B: consider the defined pipe below form left to right

What happens is that a LogEntry is sent to the first transformer in the pipe that will format the log message, then the next one will send it to an array of persisters, one will save to file and the other one will display in the console.

PIPE Formatters Mixers Persisters
DATA LogEntry Simple Multi Console, File

Example C: consider the defined pipe below form left to right

What happens is that a LogEntry is sent to the first transformer in the pipe that will send the same LogEntry, to multiple "loggers" each having their own transformation pipes. Pipe-1 will format the log entry using one formatter and then save it to a file. Pipe-2 will format the log entry using a different formatter and then send it to aws storage.

PIPE Pipe Mixers Pipes Formatters Persisters
DATA LogEntry Pipe-0 Multi Pipe-1, Pipe-2 Simple, AWS File, AWS

API

LogEntry

  Functionality Code Base
Test & Examples Test and Examples github.com/codemodify/systemkit-logging-tests
RFC 3339 Nano Formats the log as RFC 3339 github.com/codemodify/systemkit-logging-formatters-timerfc3339nano
File Logs to file github.com/codemodify/systemkit-logging-persisters-file
Console Logs to console github.com/codemodify/systemkit-logging-persisters-console
Console + Colors Logs to console with colors github.com/codemodify/systemkit-logging-persisters-consolewithcolors
Multi Logs to multiple loggers at once github.com/codemodify/systemkit-logging-mixers-multi
Async Calls a logger without blocking github.com/codemodify/systemkit-logging-mixers-async
Buffered Buffers the log as configured github.com/codemodify/systemkit-logging-mixers-buffered
Windows Event Log Logs to Windows Event Log github.com/codemodify/systemkit-logging-persisters-windowseventlog
WithFields Decorates / adds additional logging syntax "..WithFields()" github.com/codemodify/systemkit-logging-extenders-withfields
Advanced Advanced logging techniques for complex concurrency github.com/codemodify/systemkit-logging-advanced

Remarks

  • Default is emptyLogger{}
    • it is initialized in init() of the package github.com/codemodify/systemkit-logging
    • the reasoning is to enable easy adoption when writing components with conditional logging
    • consider the code differences of the blocks ONE and TWO below, ONE allows for a lot less noise
    • ONE
       import github.com/codemodify/systemkit-logging
      
       type A struct {}
       func (thisRef A) Compute {
       	logging.Debug("log line")
       }
      
       func NewA() *A {
       	return &A{}
       }
    • TWO
       import github.com/codemodify/systemkit-logging
      
       type A struct {
       	logger logging.Logger
       }
       func (thisRef A) Compute {
       	if logger.logger != {
       		thisRef.logging.Debug("log line")
       	}
       }
      
       func NewA(logger logging.Logger) *A {
       	return &A{
       		logger: logger,
       	}
       }

About

The missing robust, flexible, complete and advanced logging framework for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages