Documentation ¶
Index ¶
- Constants
- Variables
- func GetFlushFrequencyFromEnvironment() time.Duration
- func Gettid() int
- type FileStream
- type GCPStream
- type Level
- type Logger
- func Create(name string) *Logger
- func CreateIfNil(logger *Logger, name string) *Logger
- func CreateWithDestination(name, destination string) *Logger
- func CreateWithStream(name string, stream 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.0.0" + commit
VERSION is the version of this application
Functions ¶
func GetFlushFrequencyFromEnvironment ¶
GetFlushFrequencyFromEnvironment fetches the flush frequency from the environment
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
func CreateWithStream ¶
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
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
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{} record := logger.NewRecord().Set("bello", "banana").Set("だれ", "Me") err := stream.Write(record) if err != nil { os.Stdout.WriteString(err.Error() + "\n") } stream.Flush()
Output: {"bello":"banana","だれ":"Me"}
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