astilog
goal is to provide an implementation of astilog.CompleteLogger interface while restricting dependencies to astilog only.
It doesn't provide a global logger anymore since it should be a project-based decision and libs need an instance of astilog.CompleteLogger
provided to them anyway.
It doesn't use logrus
anymore since most of its features were not used. As a result astilog
is now much simpler and quicker since it only implements a subset of logrus
features.
Run the following command:
$ go get github.com/asticode/go-astilog
// Create logger
l := astilog.New(astilog.Configuration{
AppName: "myapp",
Format: astilog.FormatText,
Level: astilog.LevelWarn,
Out: astilog.OutStderr,
Source: true,
})
// Make sure to close the logger properly
defer l.Close()
// Parse flags
flag.Parse()
// Create logger
l := astilog.NewFromFlags()
// Make sure to close the logger properly
defer l.Close()
l.Debug("this is a log message")
l.Infof("this is a %s message", "log")
// Add field to the context
ctx = astilog.ContextWithField(ctx, "key", "value")
// Log with context
l.DebugC(ctx, "this is a log message")
l.InfoCf(ctx, "this is a %s message", "log")
l.WithFields(map[string]interface{}{
"k1": "v1",
"k2": "v2",
})
Set the Filename
option to your file path.
Set the Out
option to syslog
or astilog.OutSyslog
if you're setting it in GO.
Set the Out
option to stderr
or astilog.OutStderr
if you're setting it in GO.
Set the Out
option to stdout
or astilog.OutStdout
if you're setting it in GO.
Set the Format
option to text
or astilog.FormatText
.
Set the Format
option to json
or astilog.FormatJSON
.
Set the AppName
option with your app name to see it in the logs.
Set the MessageKey
option with your key to update the json
key for the message field. Default is msg
.
Set the Source
option to true
to see the file:line
that called the log function.
Set the TimestampFormat
option with your time format. If left empty, the duration since the beginning of the run will be logged.