Documentation
¶
Index ¶
- Variables
- func AddElasticHook(config ElasticConfig)
- func AddFilenameHook()
- func AddSentryHook(dsn string)
- func DefaultForRequest(r *http.Request) *logrus.Entry
- func Get() *logrus.Entry
- func GetLogEntry(r *http.Request) logrus.FieldLogger
- func IncludeRequest(log *logrus.Entry, r *http.Request) *logrus.Entry
- func Init(config Config) (*logrus.Entry, error)
- func LogEntrySetField(r *http.Request, key string, value interface{})
- func LogEntrySetFields(r *http.Request, fields map[string]interface{})
- func NewRequestLogger(logger *logrus.Logger) func(next http.Handler) http.Handler
- type Config
- type ElasticConfig
- type Entry
- type RequestLogger
- type RequestLoggerEntry
Constants ¶
This section is empty.
Variables ¶
var Default *logrus.Entry
Default is a log.Entry singleton.
Functions ¶
func AddElasticHook ¶
func AddElasticHook(config ElasticConfig)
DEPRECATED AddElasticHook adds hook that sends all error, logs to the ElasticSearch.
func AddFilenameHook ¶
func AddFilenameHook()
AddFilenameHook adds hook that includes filename and line number into the log.
func AddSentryHook ¶
func AddSentryHook(dsn string)
AddSentryHook adds hook that sends all error, fatal and panic log lines to the sentry service.
func DefaultForRequest ¶
DefaultForRequest returns default logger with included http.Request details.
func GetLogEntry ¶
func GetLogEntry(r *http.Request) logrus.FieldLogger
func IncludeRequest ¶
IncludeRequest includes http.Request details into the log.Entry.
func LogEntrySetField ¶
func LogEntrySetFields ¶
Types ¶
type Config ¶
type Config struct {
// AppName identifier of the app.
AppName string `json:"app_name" yaml:"app_name"`
// Level is a string representation of the `lorgus.Level`.
Level string `json:"level" yaml:"level"`
// Sentry is a DSN string for sentry hook.
Sentry string `json:"sentry" yaml:"sentry"`
// AddTrace enable adding of the filename field into log.
AddTrace bool `json:"add_trace" yaml:"add_trace"`
// JSON enable json formatted output.
JSON bool `json:"json" yaml:"json"`
//Elastic is a config for the ElasticSearch hook.
Elastic *ElasticConfig `json:"elastic" yaml:"elastic"`
}
Config is a options for the initialization of the default logrus.Entry.
type ElasticConfig ¶
type ElasticConfig struct {
// URL is endpoint of the ElasticSearch node.
URL string `json:"url" yaml:"url"`
// Username for HTTP Basic Auth for the ElasticSearch node.
Username string `json:"username" yaml:"username"`
// Password for HTTP Basic Auth for the ElasticSearch node.
Password string `json:"password" yaml:"password"`
// Index is name of the index in ElasticSearch.
Index string `json:"index" yaml:"index"`
// Level is a log level for ElasticSearch events.
Level string `json:"level" yaml:"level"`
}
ElasticConfig is a set of params for the ElasticSearch node.
type Entry ¶
Entry is a type alias for `*logrus.Entry`, can be used to avoid direct import of the `logrus` package.
type RequestLogger ¶
RequestLogger is a simple, but powerful implementation of a custom structured logger backed on logrus. I encourage users to copy it, adapt it and make it their own. Also take a look at https://github.com/pressly/lg for a dedicated pkg based on this work, designed for context-based http routers.
func (*RequestLogger) NewLogEntry ¶
func (l *RequestLogger) NewLogEntry(r *http.Request) middleware.LogEntry
type RequestLoggerEntry ¶
type RequestLoggerEntry struct {
Logger logrus.FieldLogger
}
func (*RequestLoggerEntry) Panic ¶
func (l *RequestLoggerEntry) Panic(v interface{}, stack []byte)