2017-05-12 05:24:39 +00:00
|
|
|
// Package log provides a global logger for zerolog.
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2017-05-20 07:22:37 +00:00
|
|
|
"context"
|
2017-08-06 02:47:55 +00:00
|
|
|
"io"
|
2017-05-12 05:24:39 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logger is the global logger.
|
|
|
|
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
|
|
|
|
|
2017-08-06 02:47:55 +00:00
|
|
|
// Output duplicates the global logger and sets w as its output.
|
|
|
|
func Output(w io.Writer) zerolog.Logger {
|
|
|
|
return Logger.Output(w)
|
|
|
|
}
|
|
|
|
|
2017-05-12 05:24:39 +00:00
|
|
|
// With creates a child logger with the field added to its context.
|
|
|
|
func With() zerolog.Context {
|
|
|
|
return Logger.With()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Level crestes a child logger with the minium accepted level set to level.
|
|
|
|
func Level(level zerolog.Level) zerolog.Logger {
|
|
|
|
return Logger.Level(level)
|
|
|
|
}
|
|
|
|
|
2017-08-29 01:52:15 +00:00
|
|
|
// Sample returns a logger with the s sampler.
|
|
|
|
func Sample(s zerolog.Sampler) zerolog.Logger {
|
|
|
|
return Logger.Sample(s)
|
2017-05-12 05:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debug starts a new message with debug level.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Debug() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Debug()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info starts a new message with info level.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Info() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Info()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warn starts a new message with warn level.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Warn() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Warn()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error starts a new message with error level.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Error() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fatal starts a new message with fatal level. The os.Exit(1) function
|
|
|
|
// is called by the Msg method.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Fatal() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Fatal()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Panic starts a new message with panic level. The message is also sent
|
|
|
|
// to the panic function.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Panic() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Panic()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log starts a new message with no level. Setting zerolog.GlobalLevel to
|
|
|
|
// zerlog.Disabled will still disable events produced by this method.
|
|
|
|
//
|
|
|
|
// You must call Msg on the returned event in order to send the event.
|
2017-05-20 02:43:59 +00:00
|
|
|
func Log() *zerolog.Event {
|
2017-05-12 05:24:39 +00:00
|
|
|
return Logger.Log()
|
|
|
|
}
|
2017-05-20 07:22:37 +00:00
|
|
|
|
2017-09-02 02:56:35 +00:00
|
|
|
// Print sends a log event using debug level and no extra field.
|
|
|
|
// Arguments are handled in the manner of fmt.Print.
|
|
|
|
func Print(v ...interface{}) {
|
|
|
|
Logger.Print(v...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Printf sends a log event using debug level and no extra field.
|
|
|
|
// Arguments are handled in the manner of fmt.Printf.
|
|
|
|
func Printf(format string, v ...interface{}) {
|
|
|
|
Logger.Printf(format, v...)
|
|
|
|
}
|
|
|
|
|
2017-05-20 07:22:37 +00:00
|
|
|
// Ctx returns the Logger associated with the ctx. If no logger
|
|
|
|
// is associated, a disabled logger is returned.
|
2017-08-30 05:53:32 +00:00
|
|
|
func Ctx(ctx context.Context) *zerolog.Logger {
|
2017-05-20 07:22:37 +00:00
|
|
|
return zerolog.Ctx(ctx)
|
|
|
|
}
|