Documentation
¶
Index ¶
- Variables
- func Debug(formatOrError interface{}, args ...interface{})
- func Dump(formatOrObject interface{}, args ...interface{})
- func Error(formatOrError interface{}, args ...interface{}) error
- func Fatal(formatOrError interface{}, args ...interface{})
- func Info(formatOrError interface{}, args ...interface{})
- func JSON(formatOrObject interface{}, args ...interface{})
- func NewBackendFormatter(b logging.Backend, f Formatter) logging.Backend
- func Panic(formatOrError interface{}, args ...interface{})
- func Request(req *http.Request, args ...interface{}) error
- func RequestOut(req *http.Request, args ...interface{}) error
- func Response(res *http.Response, args ...interface{}) error
- func SetFormatter(f Formatter)
- func SetVerbose(verbose bool)
- func Stack(args ...interface{})
- func Verbose() bool
- func Warn(formatOrError interface{}, args ...interface{})
- type Backend
- type Formatter
- type LogLevel
- type Logger
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultFormatter is the default formatter used and is only the message. DefaultFormatter = MustStringFormatter("%{message}") // GlogFormatter mimics the glog format GlogFormatter = MustStringFormatter("%{level:.1s}%{time:0102 15:04:05.999999} %{pid} %{shortfile}] %{message}") )
Functions ¶
func NewBackendFormatter ¶
NewBackendFormatter creates a new backend which makes all records that passes through it beeing formatted by the specific formatter.
func RequestOut ¶
func SetFormatter ¶
func SetFormatter(f Formatter)
SetFormatter sets the default formatter for all new backends. A backend will fetch this value once it is needed to format a record. Note that backends will cache the formatter after the first point. For now, make sure to set the formatter before logging.
func SetVerbose ¶
func SetVerbose(verbose bool)
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Custom logger backend that writes to stdout/stderr
func NewBackend ¶
NewBackend creates a new logging backend
type Formatter ¶
Formatter is the required interface for a custom log record formatter.
func MustStringFormatter ¶
MustStringFormatter is equivalent to NewStringFormatter with a call to panic on error.
func NewStringFormatter ¶
NewStringFormatter returns a new Formatter which outputs the log record as a string based on the 'verbs' specified in the format string.
The verbs:
General:
%{id} Sequence number for log message (uint64).
%{pid} Process id (int)
%{time} Time when log occurred (time.Time)
%{level} Log level (Level)
%{module} Module (string)
%{program} Basename of os.Args[0] (string)
%{message} Message (string)
%{longfile} Full file name and line number: /a/b/c/d.go:23
%{shortfile} Final file name element and line number: d.go:23
%{callpath} Callpath like main.a.b.c...c "..." meaning recursive call ~. meaning truncated path
%{color} ANSI color based on log level
For normal types, the output can be customized by using the 'verbs' defined in the fmt package, eg. '%{id:04d}' to make the id output be '%04d' as the format string.
For time.Time, use the same layout as time.Format to change the time format when output, eg "2006-01-02T15:04:05.999Z-07:00".
For the 'color' verb, the output can be adjusted to either use bold colors, i.e., '%{color:bold}' or to reset the ANSI attributes, i.e., '%{color:reset}' Note that if you use the color verb explicitly, be sure to reset it or else the color state will persist past your log message. e.g., "%{color:bold}%{time:15:04:05} %{level:-8s}%{color:reset} %{message}" will just colorize the time and level, leaving the message uncolored.
For the 'callpath' verb, the output can be adjusted to limit the printing the stack depth. i.e. '%{callpath:3}' will print '~.a.b.c'
Colors on Windows is unfortunately not supported right now and is currently a no-op.
There's also a couple of experimental 'verbs'. These are exposed to get feedback and needs a bit of tinkering. Hence, they might change in the future.
Experimental:
%{longpkg} Full package path, eg. github.com/go-logging
%{shortpkg} Base package path, eg. go-logging
%{longfunc} Full function name, eg. littleEndian.PutUint32
%{shortfunc} Base function name, eg. PutUint32
%{callpath} Call function path, eg. main.a.b.c