Structured logger for Uniplaces Go projects.
import logger "github.com/uniplaces/go-logger"
Initializing the logger requires a config as parameter where you can set which is the current environment and the desired log level.
logger.Init(logger.NewConfig("staging", "warning"))
Note: make sure you call Init
only once and as early as possible in your program.
Since the logger is implemented as a singleton, you can access it anywhere.
logger.Debug("debug message")
logger.Error(errors.New("error message"))
logger.
Builder().
AddField("test", "value").
AddContextField("foo", "bar").
Debug("debug message")
// Normal field
logger.AddDefaultField("normal-field", "normal_field_value", false)
// Context field
logger.AddDefaultField("context-field", "context_field_value", true)
This project's main focus is to bring a common standard to our Go projects's logs and, as such, please try to follow these guidelines when using this logger:
Example: when trying to fetch something from dynamodb and it fails.
In this case, contextual logging would include the ID of the object you're trying to fetch.
Note: avoid using this when handling sensitive information!
Logs should be specific and easy to trace back, so generic error logging should be avoided.