# README
log
log
is a simple wrapper for logrus.
Usage
To start use the log
package add import:
...
import (
"github.com/lancer-kit/armory/log" // imports as package "log"
)
...
- Fill config structure:
Field | Type | Description |
---|---|---|
AppName | string | identifier of the app |
Level | string | level of the logging output |
Sentry | string | dsn string for the sentry hook |
AddTrace | bool | enable the inclusion of the file name and line number in the log |
JSON | bool | enable json formatted output |
- Call init function:
logger, err := log.Init(config)
A once-initialized logrus.Entry
can then be used anywhere. To access it, use the getter:
logger := log.Get()
Example
package main
import (
"fmt"
"github.com/lancer-kit/armory/log" // imports as package "log"
)
var config = log.Config{
AppName: "my-app",
Level: "warn",
Sentry: "http://....",
AddTrace: true,
}
logger, err := log.Init(config)
if err != nil {
fmt.Println(err)
panic("unable to init log Entry")
}
logger.Info("log initialized")
logger.Error("log test error")
logger2 := log.Get()
fmt.Println(logger == logger2) // true
# Functions
AddSentryHook adds hook that sends all error, fatal and panic log lines to the sentry service.
DefaultForRequest returns default logger with included http.Request details.
Get is a getter for the `logrus.Entry` singleton.
No description provided by the author
IncludeRequest includes http.Request details into the log.Entry.
Init initializes a default logger configuration by passed configuration.
LogEntrySetField add field to logger in request context.
LogEntrySetFields add fields to logger in request context.
NewRequestLogger returns new RequestLogger middleware.
No description provided by the author
# Structs
Config is an options for the initialization of the default logrus.Entry.
NConfig is an options for the initialization of the default logrus.Entry.
RequestLogger is a simple, but powerful implementation of a custom structured logger backed on logrus.
RequestLoggerEntry is an implementation http.Request logger baked with logrus.
No description provided by the author
# Type aliases
No description provided by the author