Documentation ¶
Index ¶
- Variables
- func Fastrandn(x uint32) uint32
- func IsTerminal(fd uintptr) bool
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- type ConsoleWriter
- type Event
- func (e *Event) Bool(key string, b bool) *Event
- func (e *Event) Bools(key string, b []bool) *Event
- func (e *Event) Bytes(key string, val []byte) *Event
- func (e *Event) Caller() *Event
- func (e *Event) Discard() *Event
- func (e *Event) Dur(key string, d time.Duration) *Event
- func (e *Event) Durs(key string, d []time.Duration) *Event
- func (e *Event) Enabled() bool
- func (e *Event) Err(err error) *Event
- func (e *Event) Errs(key string, errs []error) *Event
- func (e *Event) Float32(key string, f float32) *Event
- func (e *Event) Float64(key string, f float64) *Event
- func (e *Event) Floats32(key string, f []float32) *Event
- func (e *Event) Floats64(key string, f []float64) *Event
- func (e *Event) Hex(key string, val []byte) *Event
- func (e *Event) Int(key string, i int) *Event
- func (e *Event) Int16(key string, i int16) *Event
- func (e *Event) Int32(key string, i int32) *Event
- func (e *Event) Int64(key string, i int64) *Event
- func (e *Event) Int8(key string, i int8) *Event
- func (e *Event) Interface(key string, i interface{}) *Event
- func (e *Event) Msg(msg string)
- func (e *Event) Msgf(format string, v ...interface{})
- func (e *Event) RawJSON(key string, b []byte) *Event
- func (e *Event) Str(key string, val string) *Event
- func (e *Event) Strs(key string, vals []string) *Event
- func (e *Event) Time(key string, t time.Time) *Event
- func (e *Event) TimeFormat(key string, timefmt string, t time.Time) *Event
- func (e *Event) Timestamp() *Event
- func (e *Event) Uint16(key string, i uint16) *Event
- func (e *Event) Uint32(key string, i uint32) *Event
- func (e *Event) Uint64(key string, i uint64) *Event
- func (e *Event) Uint8(key string, i uint8) *Event
- type GrpcLogger
- func (l GrpcLogger) Error(args ...interface{})
- func (l GrpcLogger) Errorf(format string, args ...interface{})
- func (l GrpcLogger) Errorln(args ...interface{})
- func (l GrpcLogger) Fatal(args ...interface{})
- func (l GrpcLogger) Fatalf(format string, args ...interface{})
- func (l GrpcLogger) Fatalln(args ...interface{})
- func (l GrpcLogger) Info(args ...interface{})
- func (l GrpcLogger) Infof(format string, args ...interface{})
- func (l GrpcLogger) Infoln(args ...interface{})
- func (l GrpcLogger) V(level int) bool
- func (l GrpcLogger) Warning(args ...interface{})
- func (l GrpcLogger) Warningf(format string, args ...interface{})
- func (l GrpcLogger) Warningln(args ...interface{})
- type Level
- type LevelWriter
- type Logger
- func (l Logger) Debug() (e *Event)
- func (l Logger) Error() (e *Event)
- func (l Logger) Fatal() (e *Event)
- func (l Logger) Info() (e *Event)
- func (l Logger) Print(v ...interface{})
- func (l Logger) Printf(format string, v ...interface{})
- func (l Logger) SetLevel(level Level)
- func (l Logger) Warn() (e *Event)
- func (l Logger) WithLevel(level Level) (e *Event)
- type TSVEvent
- func (e *TSVEvent) Bool(b bool) *TSVEvent
- func (e *TSVEvent) Bytes(val []byte) *TSVEvent
- func (e *TSVEvent) Float32(f float32) *TSVEvent
- func (e *TSVEvent) Float64(f float64) *TSVEvent
- func (e *TSVEvent) Int(i int) *TSVEvent
- func (e *TSVEvent) Int16(i int16) *TSVEvent
- func (e *TSVEvent) Int32(i int32) *TSVEvent
- func (e *TSVEvent) Int64(i int64) *TSVEvent
- func (e *TSVEvent) Int8(i int8) *TSVEvent
- func (e *TSVEvent) Msg()
- func (e *TSVEvent) Str(val string) *TSVEvent
- func (e *TSVEvent) Timestamp() *TSVEvent
- func (e *TSVEvent) Uint16(i uint16) *TSVEvent
- func (e *TSVEvent) Uint32(i uint32) *TSVEvent
- func (e *TSVEvent) Uint64(i uint64) *TSVEvent
- func (e *TSVEvent) Uint8(i uint8) *TSVEvent
- type TSVLogger
- type Writer
Constants ¶
This section is empty.
Variables ¶
var DefaultLogger = Logger{ Level: DebugLevel, Caller: 0, TimeField: "", TimeFormat: "", HostField: "", Writer: &Writer{}, }
DefaultLogger is the global logger.
Functions ¶
func IsTerminal ¶
IsTerminal returns whether the given file descriptor is a terminal.
Types ¶
type ConsoleWriter ¶
type ConsoleWriter struct {
ANSIColor bool
}
ConsoleWriter parses the JSON input and writes it in an (optionally) colorized, human-friendly format to Out.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a log event. It is instanced by one of the level method of Logger and finalized by the Msg or Msgf method.
func (*Event) Errs ¶
Errs adds the field key with errs as an array of serialized errors to the event.
func (*Event) Msgf ¶
Msgf sends the event with formatted msg added as the message field if not empty.
func (*Event) TimeFormat ¶ added in v1.0.2
TimeFormat append append t formated as string using timefmt.
type GrpcLogger ¶
type GrpcLogger struct {
Logger Logger
}
GrpcLogger implements methods to satisfy interface google.golang.org/grpc/grpclog.LoggerV2.
func (GrpcLogger) Error ¶
func (l GrpcLogger) Error(args ...interface{})
Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
func (GrpcLogger) Errorf ¶
func (l GrpcLogger) Errorf(format string, args ...interface{})
Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
func (GrpcLogger) Errorln ¶
func (l GrpcLogger) Errorln(args ...interface{})
Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
func (GrpcLogger) Fatal ¶
func (l GrpcLogger) Fatal(args ...interface{})
Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.
func (GrpcLogger) Fatalf ¶
func (l GrpcLogger) Fatalf(format string, args ...interface{})
Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.
func (GrpcLogger) Fatalln ¶
func (l GrpcLogger) Fatalln(args ...interface{})
Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.
func (GrpcLogger) Info ¶
func (l GrpcLogger) Info(args ...interface{})
Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
func (GrpcLogger) Infof ¶
func (l GrpcLogger) Infof(format string, args ...interface{})
Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
func (GrpcLogger) Infoln ¶
func (l GrpcLogger) Infoln(args ...interface{})
Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
func (GrpcLogger) V ¶
func (l GrpcLogger) V(level int) bool
V reports whether verbosity level l is at least the requested verbose level.
func (GrpcLogger) Warning ¶
func (l GrpcLogger) Warning(args ...interface{})
Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
func (GrpcLogger) Warningf ¶
func (l GrpcLogger) Warningf(format string, args ...interface{})
Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
func (GrpcLogger) Warningln ¶
func (l GrpcLogger) Warningln(args ...interface{})
Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
type Level ¶
type Level uint32
Level defines log levels.
const ( // DebugLevel defines debug log level. DebugLevel Level = iota // InfoLevel defines info log level. InfoLevel // WarnLevel defines warn log level. WarnLevel // ErrorLevel defines error log level. ErrorLevel // FatalLevel defines fatal log level. FatalLevel // PanicLevel defines panic log level. PanicLevel // NoLevel defines an absent log level. NoLevel // Disabled disables the logger. Disabled )
func ParseLevel ¶
ParseLevel converts a level string into a log Level value. returns an error if the input string does not match known values.
type LevelWriter ¶
LevelWriter defines as interface a writer may implement in order to receive level information with payload.
type Logger ¶
type Logger struct { Level Level Caller int TimeField string TimeFormat string HostField string Writer io.Writer }
A Logger represents an active logging object that generates lines of JSON output to an io.Writer.
func (Logger) Print ¶
func (l Logger) Print(v ...interface{})
Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.
func (Logger) Printf ¶
Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.
type TSVEvent ¶
type TSVEvent struct {
// contains filtered or unexported fields
}
TSVEvent represents a tsv log event. It is instanced by one of TSVLogger and finalized by the Msg method.
type TSVLogger ¶
TSVLogger represents an active logging object that generates lines of TSV output to an io.Writer.
type Writer ¶
type Writer struct { Filename string MaxSize int64 MaxBackups int LocalTime bool HostName bool // contains filtered or unexported fields }
Writer is an io.WriteCloser that writes to the specified filename.
Writer opens or creates the logfile on first Write. If the file exists and is less than MaxSize megabytes, Writer will open and append to that file. If the file exists and its size is >= MaxSize megabytes, the file is renamed by putting the current time in a timestamp in the name immediately before the file's extension (or the end of the filename if there's no extension). A new log file is then created using original filename.
Whenever a write would cause the current log file exceed MaxSize megabytes, the current file is closed, renamed, and a new log file created with the original name. Thus, the filename you give Writer is always the "current" log file.
Backups use the log file name given to Writer, in the form `name.timestamp.ext` where name is the filename without the extension, timestamp is the time at which the log was rotated formatted with the time.Time format of `2006-01-02T15-04-05` and the extension is the original extension. For example, if your Writer.Filename is `/var/log/foo/server.log`, a backup created at 6:30pm on Nov 11 2016 would use the filename `/var/log/foo/server.2016-11-04T18-30-00.log`
Cleaning Up Old Log Files ¶
Whenever a new logfile gets created, old log files may be deleted. The most recent files according to the encoded timestamp will be retained, up to a number equal to MaxBackups (or all of them if MaxBackups is 0). Any files with an encoded timestamp older than MaxAge days are deleted, regardless of MaxBackups. Note that the time encoded in the timestamp is the rotation time, which may differ from the last time that file was written to.
func (*Writer) Rotate ¶
Rotate causes Logger to close the existing log file and immediately create a new one. This is a helper function for applications that want to initiate rotations outside of the normal rotation rules, such as in response to SIGHUP. After rotating, this initiates compression and removal of old log files according to the configuration.
func (*Writer) Write ¶
Write implements io.Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, renamed to include a timestamp of the current time, and a new log file is created using the original log file name. If the length of the write is greater than MaxSize, an error is returned.