Documentation
¶
Index ¶
- Constants
- Variables
- func GetFlushFrequencyFromEnvironment() time.Duration
- func Gettid() int
- type FileStream
- type GCPStream
- type Level
- type Logger
- func Create(name string, parameters ...interface{}) *Logger
- func CreateIfNil(logger *Logger, name string) *Logger
- func CreateWithDestination(name string, destinations ...string) *Logger
- func CreateWithStream(name string, streams ...Streamer) *Logger
- func FromContext(context context.Context) (*Logger, error)
- func Must(log *Logger, err error) *Logger
- func (log *Logger) Child(topic, scope interface{}, params ...interface{}) *Logger
- func (log *Logger) Debugf(msg string, args ...interface{})
- func (log *Logger) Errorf(msg string, args ...interface{})
- func (log *Logger) Fatalf(msg string, args ...interface{})
- func (log *Logger) Flush()
- func (log *Logger) GetRecord(key string) interface{}
- func (l *Logger) HttpHandler() func(http.Handler) http.Handler
- func (log *Logger) Infof(msg string, args ...interface{})
- func (log *Logger) Record(key string, value interface{}) *Logger
- func (log *Logger) Recordf(key, value string, args ...interface{}) *Logger
- func (log *Logger) Records(params ...interface{}) *Logger
- func (log *Logger) Scope(value interface{}) *Logger
- func (log *Logger) ShouldWrite(level Level) bool
- func (log Logger) String() string
- func (l *Logger) ToContext(parent context.Context) context.Context
- func (log *Logger) Topic(value interface{}) *Logger
- func (log *Logger) Tracef(msg string, args ...interface{})
- func (log *Logger) Warnf(msg string, args ...interface{})
- func (log *Logger) Write(record Record) error
- type MultiStream
- type NilStream
- type Record
- type StackDriverStream
- type StderrStream
- type StdoutStream
- type Streamer
Examples ¶
Constants ¶
const ContextKey key = iota + 12583
ContextKey is the key for logger child stored in Context
Variables ¶
var VERSION = "1.1.2" + commit
VERSION is the version of this application
Functions ¶
func GetFlushFrequencyFromEnvironment ¶
GetFlushFrequencyFromEnvironment fetches the flush frequency from the environment
the frequency should be like https://golang.org/pkg/time/#ParseDuration or an ISO8601 duration. If not set, the frequency will be 5 minutes
Types ¶
type FileStream ¶
type FileStream struct { *json.Encoder Path string FilterLevel Level Unbuffered bool // contains filtered or unexported fields }
FileStream is the Stream that writes to a file
Any record with a level < FilterLevel will be written
func (*FileStream) Flush ¶
func (stream *FileStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*FileStream) ShouldWrite ¶
func (stream *FileStream) ShouldWrite(level Level) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
func (FileStream) String ¶
func (stream FileStream) String() string
String gets a string version
implements the fmt.Stringer interface
func (*FileStream) Write ¶
func (stream *FileStream) Write(record Record) (err error)
Write writes the given Record
implements logger.Stream
type GCPStream ¶
GCPStream is the Stream that writes to the standard output
func (*GCPStream) Flush ¶
func (stream *GCPStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*GCPStream) ShouldWrite ¶
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
type Level ¶
type Level byte
func GetLevelFromRecord ¶
func (Level) ShouldWrite ¶
ShouldWrite tells if the current level is writeable when compared to the given filter level
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a Logger that creates Bunyan's compatible logs (see: https://github.com/trentm/node-bunyan)
func CreateIfNil ¶
CreateIfNil creates a new Logger if the given Logger is nil, otherwise return the said Logger
func CreateWithDestination ¶
CreateWithDestination creates a new Logger streaming to the given destination(s)
func CreateWithStream ¶
CreateWithStream creates a new Logger streaming to the given stream or list of streams
func FromContext ¶
FromContext retrieves the Logger stored in the context
func (*Logger) Errorf ¶
Errorf traces a message at the ERROR Level If the last argument is an error, a Record is added and the error string is added to the message
func (*Logger) Fatalf ¶
Fatalf traces a message at the FATAL Level If the last argument is an error, a Record is added and the error string is added to the message
func (*Logger) Flush ¶
func (log *Logger) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*Logger) HttpHandler ¶
HttpHandler function will wrap an http handler with extra logging information
func (*Logger) Records ¶
Records adds key, value pairs as Record objects E.g.: log.Records("key1", value1, "key2", value2)
The key should be castable to a string If the last value is missing, its key is ignored
func (*Logger) ShouldWrite ¶
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
type MultiStream ¶
type MultiStream struct {
// contains filtered or unexported fields
}
MultiStream is the Stream that writes to several streams
func (*MultiStream) Flush ¶
func (stream *MultiStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*MultiStream) ShouldWrite ¶
func (stream *MultiStream) ShouldWrite(level Level) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
func (MultiStream) String ¶
func (stream MultiStream) String() string
String gets a string version
implements the fmt.Stringer interface
func (*MultiStream) Write ¶
func (stream *MultiStream) Write(record Record) error
Write writes the given Record
implements logger.Stream
type NilStream ¶
type NilStream struct { }
NilStream is the Stream that writes nowhere
Example ¶
stream := &logger.NilStream{} if err := stream.Write(logger.NewRecord().Set("bello", "banana").Set("だれ", "Me")); err != nil { os.Stdout.WriteString(err.Error() + "\n") } if stream.ShouldWrite(logger.ALWAYS) { os.Stdout.WriteString("This should not be seen\n") } stream.Flush()
Output:
func (*NilStream) Flush ¶
func (stream *NilStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*NilStream) ShouldWrite ¶
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
type Record ¶
type Record map[string]interface{}
Record is the map that contains all records of a log entry
If the value at a key is a func() interface the func will be called when the record is marshaled
func (Record) MarshalJSON ¶
MarshalJSON marshals this into JSON
func (Record) Merge ¶
Merge merges a source Record into this Record
values already set in this record cannot be overriden
func (*Record) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into this
type StackDriverStream ¶
type StackDriverStream struct { LogID string ProjectID string FilterLevel Level // contains filtered or unexported fields }
GCPStream is the Stream that writes to the standard output
func (*StackDriverStream) Flush ¶
func (stream *StackDriverStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*StackDriverStream) ShouldWrite ¶
func (stream *StackDriverStream) ShouldWrite(level Level) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
func (StackDriverStream) String ¶
func (stream StackDriverStream) String() string
String gets a string version
implements the fmt.Stringer interface
func (*StackDriverStream) Write ¶
func (stream *StackDriverStream) Write(record Record) (err error)
Write writes the given Record
implements logger.Stream
type StderrStream ¶
StderrStream is the Stream that writes to the standard output
Example ¶
output := CaptureStderr(func() { stream := &logger.StderrStream{} if err := stream.Write(logger.NewRecord().Set("bello", "banana").Set("だれ", "Me")); err != nil { os.Stderr.WriteString(err.Error() + "\n") } if stream.ShouldWrite(logger.TRACE) { os.Stderr.WriteString("This should not be seen, stream Filter: " + stream.FilterLevel.String() + "\n") } stream.Flush() }) fmt.Println(output)
Output: {"bello":"banana","だれ":"Me"}
func (*StderrStream) Flush ¶
func (stream *StderrStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*StderrStream) ShouldWrite ¶
func (stream *StderrStream) ShouldWrite(level Level) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
func (StderrStream) String ¶
func (stream StderrStream) String() string
String gets a string version
implements the fmt.Stringer interface
func (*StderrStream) Write ¶
func (stream *StderrStream) Write(record Record) error
Write writes the given Record
implements logger.Stream
type StdoutStream ¶
type StdoutStream struct { *json.Encoder FilterLevel Level Unbuffered bool // contains filtered or unexported fields }
StdoutStream is the Stream that writes to the standard output
Example ¶
stream := &logger.StdoutStream{} if err := stream.Write(logger.NewRecord().Set("bello", "banana").Set("だれ", "Me")); err != nil { os.Stdout.WriteString(err.Error() + "\n") } if stream.ShouldWrite(logger.TRACE) { os.Stdout.WriteString("This should not be seen, stream Filter: " + stream.FilterLevel.String() + "\n") } if err := stream.Write(logger.NewRecord().Set("bello", "banana").Set("level", logger.ERROR)); err != nil { os.Stdout.WriteString(err.Error() + "\n") } stream.Flush()
Output: {"bello":"banana","だれ":"Me"} {"bello":"banana","level":50}
func (*StdoutStream) Flush ¶
func (stream *StdoutStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Stream
func (*StdoutStream) ShouldWrite ¶
func (stream *StdoutStream) ShouldWrite(level Level) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Stream
func (StdoutStream) String ¶
func (stream StdoutStream) String() string
String gets a string version
implements the fmt.Stringer interface
func (*StdoutStream) Write ¶
func (stream *StdoutStream) Write(record Record) error
Write writes the given Record
implements logger.Stream
type Streamer ¶
Streamer is the interface a Logger writes to
func CreateMultiStream ¶ added in v1.1.1
func CreateStreamWithDestination ¶ added in v1.1.0
CreateStreamWithDestination creates a new Streamer from a list of strings