Documentation ¶
Index ¶
- Variables
- func GetFlushFrequencyFromEnvironment() time.Duration
- func Redact(value interface{}) string
- func RedactAll[T Redactable](items []T) []any
- func RedactWithHash(value interface{}) string
- func RedactWithPrefixedHash(prefix string, value interface{}) string
- type BufferPool
- type BunyanConverter
- type CloudWatchConverter
- type Converter
- type FileStream
- func (stream *FileStream) Close()
- func (stream *FileStream) FilterLess()
- func (stream *FileStream) FilterMore()
- func (stream *FileStream) Flush()
- func (stream *FileStream) GetFilterLevels() LevelSet
- func (stream *FileStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *FileStream) ShouldLogSourceInfo() bool
- func (stream *FileStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream *FileStream) String() string
- func (stream *FileStream) Write(record *Record) (err error)
- type FilterModifier
- type FilterSetter
- type Level
- type LevelSet
- func (set LevelSet) Get(topic, scope string) (level Level)
- func (levels LevelSet) GetDefault() Level
- func (set *LevelSet) Set(level Level, topic, scope string)
- func (set *LevelSet) SetDefault(level Level)
- func (set LevelSet) ShouldWrite(level Level, topic, scope string) bool
- func (set LevelSet) String() string
- type Logger
- func (log *Logger) AddDestinations(destinations ...any)
- func (log *Logger) AsStandardLog(level ...Level) *stdlog.Logger
- func (log *Logger) Child(topic, scope interface{}, params ...interface{}) *Logger
- func (log *Logger) Close()
- 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) FilterLess()
- func (log *Logger) FilterMore()
- func (log *Logger) Flush()
- func (log *Logger) GetFilterLevels() LevelSet
- func (log *Logger) GetRecord(key string) interface{}
- func (log *Logger) GetScope() string
- func (log *Logger) GetTopic() string
- func (l *Logger) HttpHandler() func(http.Handler) http.Handler
- func (log *Logger) Infof(msg string, args ...interface{})
- func (log *Logger) Memory()
- func (log *Logger) Memoryf(msg string, args ...interface{})
- func (log *Logger) Memoryl(level Level)
- func (log *Logger) Memorylf(level Level, msg string, args ...interface{})
- func (log *Logger) Record(key string, value interface{}) *Logger
- func (log *Logger) RecordWithKeysToRedact(key string, value interface{}, keyToRedact ...string) *Logger
- func (log *Logger) Recordf(key, value string, args ...interface{}) *Logger
- func (log *Logger) Records(params ...interface{}) *Logger
- func (log *Logger) ResetDestinations(destinations ...any)
- func (log *Logger) Scope(scope interface{}) *Logger
- func (log *Logger) SetFilterLevel(level Level, parameters ...string)
- func (log *Logger) ShouldLogSourceInfo() bool
- func (log *Logger) ShouldWrite(level Level, topic, scope string) bool
- func (log Logger) String() string
- func (l *Logger) TimeFunc(message string, code func())
- func (l *Logger) TimeFuncE(message string, code func() error) error
- func (l *Logger) TimeFuncV(message string, code func() interface{}) interface{}
- func (l *Logger) TimeFuncVE(message string, code func() (interface{}, error)) (interface{}, error)
- func (l *Logger) ToContext(parent context.Context) context.Context
- func (log *Logger) Topic(topic 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
- func (log *Logger) Writer(level ...Level) io.Writer
- type LoggerCarrier
- type MapPool
- type MultiStream
- func (stream *MultiStream) Close()
- func (stream *MultiStream) FilterLess()
- func (stream *MultiStream) FilterMore()
- func (stream *MultiStream) Flush()
- func (stream *MultiStream) GetFilterLevels() LevelSet
- func (stream *MultiStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *MultiStream) ShouldLogSourceInfo() bool
- func (stream *MultiStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream MultiStream) String() string
- func (stream *MultiStream) Write(record *Record) error
- type NilStream
- func (stream *NilStream) Close()
- func (stream *NilStream) FilterLess()
- func (stream *NilStream) FilterMore()
- func (stream *NilStream) Flush()
- func (stream *NilStream) GetFilterLevels() LevelSet
- func (stream *NilStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *NilStream) ShouldLogSourceInfo() bool
- func (stream *NilStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream NilStream) String() string
- func (stream *NilStream) Write(record *Record) error
- type PinoConverter
- type Record
- func (record *Record) AddKeysToRedact(keys ...string) *Record
- func (record *Record) Close()
- func (record *Record) Delete(key string) *Record
- func (record *Record) Find(key string) (value interface{}, found bool)
- func (record *Record) Get(key string) interface{}
- func (record Record) MarshalJSON() ([]byte, error)
- func (record *Record) Merge(source *Record) *Record
- func (record *Record) Reset()
- func (record *Record) Set(key string, value interface{}) *Record
- func (record *Record) UnmarshalJSON(payload []byte) error
- type Redactable
- type RedactableWithKeys
- type Redactor
- type StackDriverConverter
- type StackDriverStream
- func (stream *StackDriverStream) Close()
- func (stream *StackDriverStream) FilterLess()
- func (stream *StackDriverStream) FilterMore()
- func (stream *StackDriverStream) Flush()
- func (stream *StackDriverStream) GetFilterLevels() LevelSet
- func (stream *StackDriverStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *StackDriverStream) ShouldLogSourceInfo() bool
- func (stream *StackDriverStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream *StackDriverStream) String() string
- func (stream *StackDriverStream) Write(record *Record) (err error)
- type StderrStream
- func (stream *StderrStream) Close()
- func (stream *StderrStream) FilterLess()
- func (stream *StderrStream) FilterMore()
- func (stream *StderrStream) Flush()
- func (stream *StderrStream) GetFilterLevels() LevelSet
- func (stream *StderrStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *StderrStream) ShouldLogSourceInfo() bool
- func (stream *StderrStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream *StderrStream) String() string
- func (stream *StderrStream) Write(record *Record) (err error)
- type StdoutStream
- func (stream *StdoutStream) Close()
- func (stream *StdoutStream) FilterLess()
- func (stream *StdoutStream) FilterMore()
- func (stream *StdoutStream) Flush()
- func (stream *StdoutStream) GetFilterLevels() LevelSet
- func (stream *StdoutStream) SetFilterLevel(level Level, parameters ...string)
- func (stream *StdoutStream) ShouldLogSourceInfo() bool
- func (stream *StdoutStream) ShouldWrite(level Level, topic, scope string) bool
- func (stream *StdoutStream) String() string
- func (stream *StdoutStream) Write(record *Record) error
- type Streamer
Constants ¶
This section is empty.
Variables ¶
var ( // AMEXRedactor is a Redactor that will redact AMEX Numbers AMEXRedactor = core.Must(NewRedactor(`3[47]\d{2}[- ]*\d{6}[- ]*\d{5}`)) // DinersClubRedactor is a Redactor that will redact Diners Club Numbers DinersClubRedactor = core.Must(NewRedactor(`3(?:0[0-5]|[68][0-9])\d[- ]*\d{4}[- ]*\d{4}[- ]*\d{2}`)) // DiscoverRedactor is a Redactor that will redact Discover Numbers DiscoverRedactor = core.Must(NewRedactor(`6(?:011|5[0-9]{2})[- ]*\d{4}[- ]*\d{4}[- ]*\d{4}`)) // JCBRedactor is a Redactor that will redact JCB Numbers JCBRedactor = core.Must(NewRedactor(`(?:2131|1800|35\d{2})[- ]*\d{4}[- ]*\d{4}[- ]*\d{4}`)) // MasterCardRedactor is a Redactor that will redact MasterCard Numbers MasterCardRedactor = core.Must(NewRedactor(`(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[- ]*\d{4}[- ]*\d{4}[- ]*\d{4}`)) // VISARedactor is a Redactor that will redact VISA Credit Card Numbers VISARedactor = core.Must(NewRedactor(`4\d{3}[- ]*\d{4}[- ]*\d{4}[- ]*\d{4}`)) // CreditCardRedactor is a Redactor that will redact Credit Card Numbers CreditCardRedactor = AMEXRedactor.Merge(DinersClubRedactor, DiscoverRedactor, JCBRedactor, MasterCardRedactor, VISARedactor) // PhoneRedactor is a Redactor that will redact Phone Numbers PhoneRedactor = core.Must(NewRedactor(`(\+?[0-9]{1,3}[-. ]?[0-9]{3}[-. ]?[0-9]{3}[-. ]?[0-9]{4})|(\+?[0-9]{1,3}[-. ]?[0-9.\-]+)`)) // EmailRedactor is a Redactor that will redact Email Addresses EmailRedactor = core.Must(NewRedactor(`[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4}`)) // IPRedactor is a Redactor that will redact IP Addresses (v4 and v6) IPRedactor = core.Must(NewRedactor(`(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|([0-9a-fA-F:]{2,39})`)) // IPV4Redactor is a Redactor that will redact IP v4 Addresses IPV4Redactor = core.Must(NewRedactor(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`)) // IPV6Redactor is a Redactor that will redact IP v6 Addresses IPV6Redactor = core.Must(NewRedactor(`[0-9a-fA-F:]{2,39}`)) // MACRedactor is a Redactor that will redact MAC Addresses MACRedactor = core.Must(NewRedactor(`([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})`)) )
var VERSION = "1.7.5" + 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
func Redact ¶ added in v1.6.3
func Redact(value interface{}) string
Redact redacts a stringable value
func RedactAll ¶ added in v1.7.5
func RedactAll[T Redactable](items []T) []any
RedactAll redacts all items in a slice of redactable items
func RedactWithHash ¶ added in v1.6.3
func RedactWithHash(value interface{}) string
RedactWithHash redacts a value with a hash
func RedactWithPrefixedHash ¶ added in v1.6.3
RedactWithPrefixedHash redacts a value with a prefix and a hash
Types ¶
type BufferPool ¶ added in v1.6.5
func NewBufferPool ¶ added in v1.6.5
func NewBufferPool() *BufferPool
NewBufferPool creates a new BufferPool
func (*BufferPool) Get ¶ added in v1.6.5
func (pool *BufferPool) Get() (buffer *bytes.Buffer)
Get selects an arbitrary Buffer from the Pool, removes it from the Pool, and returns it to the caller.
func (*BufferPool) Put ¶ added in v1.6.5
func (pool *BufferPool) Put(buffer *bytes.Buffer)
Put adds a Buffer to the Pool.
type BunyanConverter ¶ added in v1.3.0
type BunyanConverter struct { }
BunyanConverter is the default Converter
func (*BunyanConverter) Convert ¶ added in v1.3.0
func (converter *BunyanConverter) Convert(record *Record) *Record
Convert converts the Record into a Bunyan compatible Record
type CloudWatchConverter ¶ added in v1.5.0
type CloudWatchConverter struct { }
CloudWatchConverter is used to convert a Record for AWS CloudWatch
func (*CloudWatchConverter) Convert ¶ added in v1.5.0
func (converter *CloudWatchConverter) Convert(record *Record) *Record
Convert converts the Record into a StackDriver compatible Record
type Converter ¶ added in v1.3.0
Converter is used to convert a Record into another format
func GetConverterFromEnvironment ¶ added in v1.3.0
func GetConverterFromEnvironment() Converter
GetConverterFromEnvironment fetches the Converter from the environment
type FileStream ¶
type FileStream struct { Path string Converter Converter FilterLevels LevelSet Unbuffered bool SourceInfo 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) Close ¶ added in v1.3.0
func (stream *FileStream) Close()
Close closes the stream
implements logger.Streamer
func (*FileStream) FilterLess ¶ added in v1.5.0
func (stream *FileStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*FileStream) FilterMore ¶ added in v1.5.0
func (stream *FileStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*FileStream) Flush ¶
func (stream *FileStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*FileStream) GetFilterLevels ¶ added in v1.6.9
func (stream *FileStream) GetFilterLevels() LevelSet
GetFilterLevels gets the filter levels
implements logger.Streamer
func (*FileStream) SetFilterLevel ¶ added in v1.3.0
func (stream *FileStream) SetFilterLevel(level Level, parameters ...string)
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*FileStream) ShouldLogSourceInfo ¶ added in v1.5.4
func (stream *FileStream) ShouldLogSourceInfo() bool
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*FileStream) ShouldWrite ¶
func (stream *FileStream) ShouldWrite(level Level, topic, scope string) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
func (*FileStream) String ¶
func (stream *FileStream) String() string
String gets a string version
implements fmt.Stringer
func (*FileStream) Write ¶
func (stream *FileStream) Write(record *Record) (err error)
Write writes the given Record
implements logger.Streamer
type FilterModifier ¶ added in v1.5.0
type FilterModifier interface { // FilterMore tells the stream to filter more FilterMore() // FilterLess tells the stream to filter less FilterLess() }
FilterModifier describes objects that can modify their Filter Level
type FilterSetter ¶ added in v1.5.0
type FilterSetter interface { // SetFilterLevel sets the filter level // // If present, the first parameter is the topic. // // If present, the second parameter is the scope. SetFilterLevel(level Level, parameters ...string) }
FilterSetter describes objects that can set their Filter Level
The Filter Level is the level that will be used to filter what gets written to the Stream: Records with a level lower than the filter level will not be written
type Level ¶
type Level byte
Level represents the log Level The higher the value the more chances to write in the Stream
const ( // UNSET level means the level is not yet set UNSET Level = iota * 10 // TRACE level should be used for entries that should be used by the developer of the app/package only TRACE // DEBUG level should be used for detailed logging as they tend to be noisy DEBUG // INFO level should be used as the standard level. Entries that really mean something to most people should go there INFO // WARN level should be used when the code considers a situation as not optimal but it can live with it WARN // ERROR level should be used when the code encounters an issue and normal flow is disrupted ERROR // FATAL level should be used when the code eoncounters an issue it cannot recover from FATAL // ALWAYS level should be used for entries that should always be logged, like app version, etc. ALWAYS Level = 255 // NEVER level should be used for entries that should never be logged NEVER Level = 1 )
func GetLevelFromRecord ¶
GetLevelFromRecord retrieves the level from the given Record
func (Level) Next ¶ added in v1.5.0
Next returns the Level that follows the current one
If level is ALWAYS, it will return ALWAYS ¶
Example: TRACE.Next() will return DEBUG
func (Level) Previous ¶ added in v1.5.0
Previous returns the Level that precedes the current one
If level is NEVER, it will return NEVER ¶
Example: DEBUG.Previous() will return TRACE
func (Level) ShouldWrite ¶
ShouldWrite tells if the current level is writeable when compared to the given filter level
To be writeable, the current level must be higher than the filter level
type LevelSet ¶ added in v1.6.0
type LevelSet map[topicscope]Level
LevelSet is a set of levels organized by topic and scope
func NewLevelSet ¶ added in v1.6.0
NewLevelSet creates a new LevelSet with a default level
func ParseLevels ¶ added in v1.6.0
ParseLevels parses a string and returns a LevelSet
func ParseLevelsFromEnvironment ¶ added in v1.6.0
func ParseLevelsFromEnvironment() (levels LevelSet)
ParseLevelsFromEnvironment parses the levels from the environment variable LOG_LEVEL
If LOG_LEVEL is not set, it will return a LevelSet with the default level (INFO)
If the environment variable DEBUG is set to 1 (or yes, on, true), the default level in the LevelSet will be DEBUG
func (LevelSet) GetDefault ¶ added in v1.6.0
GetDefault gets the default level
func (*LevelSet) SetDefault ¶ added in v1.6.0
SetDefault sets the level for any topic and any scope
func (LevelSet) ShouldWrite ¶ added in v1.6.0
ShouldWrite Tells if the given Level, Topic, and Scope should be written
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 FromContext ¶
FromContext retrieves the Logger stored in the context
Sources are either LoggerCarrier implemenations or Logger/*Logger objects.
The first source that is a match is returned.
func (*Logger) AddDestinations ¶ added in v1.6.9
AddDestinations adds destinations to the Logger
func (*Logger) AsStandardLog ¶ added in v1.3.7
AsStandardLog gets a standard GO logger
func (*Logger) Close ¶ added in v1.3.0
func (log *Logger) Close()
Close closes the logger's stream
implements logger.Streamer
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) FilterLess ¶ added in v1.5.0
func (log *Logger) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*Logger) FilterMore ¶ added in v1.5.0
func (log *Logger) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*Logger) Flush ¶
func (log *Logger) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*Logger) GetFilterLevels ¶ added in v1.6.9
GetFilterLevels gets the filter levels of the streamer
implements logger.Streamer
func (*Logger) HttpHandler ¶
HttpHandler function will wrap an http handler with extra logging information
func (*Logger) Memory ¶ added in v1.3.11
func (log *Logger) Memory()
Memory traces memory usage at the TRACE Level
func (*Logger) Memoryf ¶ added in v1.3.11
Memoryf traces memory usage at the TRACE level with a given message
func (*Logger) Memorylf ¶ added in v1.3.11
Memorylf traces memory usage at the given level and with the given message
func (*Logger) RecordWithKeysToRedact ¶ added in v1.7.0
func (log *Logger) RecordWithKeysToRedact(key string, value interface{}, keyToRedact ...string) *Logger
RecordWithKeysToRedact adds the given Record to the Log
func (*Logger) Records ¶
Records adds key, value pairs as Record objects
The key should be castable to a string. If the last value is missing, its key is ignored
E.g.: log.Records("key1", value1, "key2", value2)
func (*Logger) ResetDestinations ¶ added in v1.6.9
ResetDestinations resets the destinations to the Logger
If no destinations are given, nothing happens
func (*Logger) SetFilterLevel ¶ added in v1.3.0
SetFilterLevel sets the filter level of the streamer
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*Logger) ShouldLogSourceInfo ¶ added in v1.5.4
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*Logger) ShouldWrite ¶
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
func (*Logger) TimeFuncE ¶ added in v1.5.4
TimeFuncE will log the duration of the given function call that returns an error
func (*Logger) TimeFuncV ¶ added in v1.5.4
TimeFuncV will log the duration of the given function call that returns a value
func (*Logger) TimeFuncVE ¶ added in v1.5.4
TimeFuncVE will log the duration of the given function call that returns a value and an error
type LoggerCarrier ¶ added in v1.6.3
type LoggerCarrier interface {
GetLogger() *Logger
}
LoggerCarrier describes structs that carry a Logger
type MapPool ¶ added in v1.6.5
type MultiStream ¶
type MultiStream struct {
// contains filtered or unexported fields
}
MultiStream is the Stream that writes to several streams
func (*MultiStream) Close ¶ added in v1.3.0
func (stream *MultiStream) Close()
Close closes the stream
implements logger.Streamer
func (*MultiStream) FilterLess ¶ added in v1.5.0
func (stream *MultiStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*MultiStream) FilterMore ¶ added in v1.5.0
func (stream *MultiStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*MultiStream) Flush ¶
func (stream *MultiStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*MultiStream) GetFilterLevels ¶ added in v1.6.9
func (stream *MultiStream) GetFilterLevels() LevelSet
GetFilterLevels gets the filter levels
If the multi stream contains at least one stream, it returns the filter levels of the first stream ¶
implements logger.Streamer
func (*MultiStream) SetFilterLevel ¶ added in v1.3.0
func (stream *MultiStream) SetFilterLevel(level Level, parameters ...string)
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*MultiStream) ShouldLogSourceInfo ¶ added in v1.5.4
func (stream *MultiStream) ShouldLogSourceInfo() bool
ShouldLogSourceInfo tells if the source info should be logged
If at least one stream returns true, the stream should write the record ¶
implements logger.Streamer
func (*MultiStream) ShouldWrite ¶
func (stream *MultiStream) ShouldWrite(level Level, topic, scope string) bool
ShouldWrite tells if the given level should be written to this stream
If at least one stream returns true, the stream should write the record ¶
implements logger.Streamer
func (MultiStream) String ¶
func (stream MultiStream) String() string
String gets a string version
implements fmt.Stringer
func (*MultiStream) Write ¶
func (stream *MultiStream) Write(record *Record) error
Write writes the given Record
implements logger.Streamer
type NilStream ¶
type NilStream struct { }
NilStream is the Stream that writes nowhere
func (*NilStream) Close ¶ added in v1.3.0
func (stream *NilStream) Close()
Close closes the stream
implements logger.Streamer
func (*NilStream) FilterLess ¶ added in v1.5.0
func (stream *NilStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*NilStream) FilterMore ¶ added in v1.5.0
func (stream *NilStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*NilStream) Flush ¶
func (stream *NilStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*NilStream) GetFilterLevels ¶ added in v1.6.9
GetFilterLevels gets the filter levels
implements logger.Streamer
func (*NilStream) SetFilterLevel ¶ added in v1.3.0
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*NilStream) ShouldLogSourceInfo ¶ added in v1.5.4
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*NilStream) ShouldWrite ¶
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
type PinoConverter ¶ added in v1.3.0
type PinoConverter struct { }
PinoConverter is used to convert Records to be read by pino
func (*PinoConverter) Convert ¶ added in v1.3.0
func (converter *PinoConverter) Convert(record *Record) *Record
Convert converts the Record into a Pino compatible Record
type Record ¶
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 NewPooledRecord ¶ added in v1.6.5
func NewPooledRecord() (record *Record, release func())
NewPooledRecord creates a new empty record
func (*Record) AddKeysToRedact ¶ added in v1.7.0
AddKeysToRedact adds keys to redact
func (*Record) Close ¶ added in v1.6.5
func (record *Record) Close()
Close returns the record to the pool
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 overridden
func (*Record) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into this
type Redactable ¶ added in v1.4.0
type Redactable interface {
Redact() interface{}
}
Redactable can be used by structs that want to redact their fields
When the Logger writes the Record contains a Redactable, it will call Redact
type RedactableWithKeys ¶ added in v1.7.0
type RedactableWithKeys interface {
Redact(key ...string) interface{}
}
RedactableWithKeys can be used by structs that want to redact their fields
When the Logger writes the Record contains a RedactableWithKeys, it will call Redact
type Redactor ¶ added in v1.4.0
func NewRedactor ¶ added in v1.4.0
func (Redactor) Merge ¶ added in v1.7.1
Merge merges the Redactor with other Redactors
The other Redactors can be strings, Redactor, *Redactor or fmt.Stringers
type StackDriverConverter ¶ added in v1.3.0
type StackDriverConverter struct { }
StackDriverConverter is used to convert a Record for StackDriver
func (*StackDriverConverter) Convert ¶ added in v1.3.0
func (converter *StackDriverConverter) Convert(record *Record) *Record
Convert converts the Record into a StackDriver compatible Record
type StackDriverStream ¶
type StackDriverStream struct { LogID string Parent string KeyFilename string Key interface{} Converter Converter FilterLevels LevelSet SourceInfo bool // contains filtered or unexported fields }
StackDriverStream is the Stream that writes to the standard output
implements logger.Streamer
func (*StackDriverStream) Close ¶ added in v1.3.0
func (stream *StackDriverStream) Close()
Close closes the stream
implements logger.Streamer
func (*StackDriverStream) FilterLess ¶ added in v1.5.0
func (stream *StackDriverStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*StackDriverStream) FilterMore ¶ added in v1.5.0
func (stream *StackDriverStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*StackDriverStream) Flush ¶
func (stream *StackDriverStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*StackDriverStream) GetFilterLevels ¶ added in v1.6.9
func (stream *StackDriverStream) GetFilterLevels() LevelSet
GetFilterLevels gets the filter levels
implements logger.Streamer
func (*StackDriverStream) SetFilterLevel ¶ added in v1.3.0
func (stream *StackDriverStream) SetFilterLevel(level Level, parameters ...string)
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*StackDriverStream) ShouldLogSourceInfo ¶ added in v1.5.4
func (stream *StackDriverStream) ShouldLogSourceInfo() bool
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*StackDriverStream) ShouldWrite ¶
func (stream *StackDriverStream) ShouldWrite(level Level, topic, scope string) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
func (*StackDriverStream) String ¶
func (stream *StackDriverStream) String() string
String gets a string version
implements fmt.Stringer
func (*StackDriverStream) Write ¶
func (stream *StackDriverStream) Write(record *Record) (err error)
Write writes the given Record
implements logger.Streamer
type StderrStream ¶
type StderrStream struct { Converter Converter FilterLevels LevelSet SourceInfo bool // contains filtered or unexported fields }
StderrStream is the Stream that writes to the standard error
func (*StderrStream) Close ¶ added in v1.3.0
func (stream *StderrStream) Close()
Close closes the stream
implements logger.Streamer
func (*StderrStream) FilterLess ¶ added in v1.5.0
func (stream *StderrStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*StderrStream) FilterMore ¶ added in v1.5.0
func (stream *StderrStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*StderrStream) Flush ¶
func (stream *StderrStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*StderrStream) GetFilterLevels ¶ added in v1.6.9
func (stream *StderrStream) GetFilterLevels() LevelSet
GetFilterLevels gets the filter levels
implements logger.Streamer
func (*StderrStream) SetFilterLevel ¶ added in v1.3.0
func (stream *StderrStream) SetFilterLevel(level Level, parameters ...string)
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*StderrStream) ShouldLogSourceInfo ¶ added in v1.5.4
func (stream *StderrStream) ShouldLogSourceInfo() bool
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*StderrStream) ShouldWrite ¶
func (stream *StderrStream) ShouldWrite(level Level, topic, scope string) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
func (*StderrStream) String ¶
func (stream *StderrStream) String() string
String gets a string version
implements fmt.Stringer
func (*StderrStream) Write ¶
func (stream *StderrStream) Write(record *Record) (err error)
Write writes the given Record
implements logger.Streamer
type StdoutStream ¶
type StdoutStream struct { Converter Converter FilterLevels LevelSet Unbuffered bool SourceInfo bool // contains filtered or unexported fields }
StdoutStream is the Stream that writes to the standard output
func (*StdoutStream) Close ¶ added in v1.3.0
func (stream *StdoutStream) Close()
Close closes the stream
implements logger.Streamer
func (*StdoutStream) FilterLess ¶ added in v1.5.0
func (stream *StdoutStream) FilterLess()
FilterLess tells the stream to filter less
The stream will filter less if it is not already at the lowest level. Which means more log messages will be written to the stream
Example: if the stream is at INFO, it will be filtering at DEBUG
implements logger.FilterModifier
func (*StdoutStream) FilterMore ¶ added in v1.5.0
func (stream *StdoutStream) FilterMore()
FilterMore tells the stream to filter more
The stream will filter more if it is not already at the highest level. Which means less log messages will be written to the stream
Example: if the stream is at DEBUG, it will be filtering at INFO
implements logger.FilterModifier
func (*StdoutStream) Flush ¶
func (stream *StdoutStream) Flush()
Flush flushes the stream (makes sure records are actually written)
implements logger.Streamer
func (*StdoutStream) GetFilterLevels ¶ added in v1.6.9
func (stream *StdoutStream) GetFilterLevels() LevelSet
GetFilterLevels gets the filter levels
implements logger.Streamer
func (*StdoutStream) SetFilterLevel ¶ added in v1.3.0
func (stream *StdoutStream) SetFilterLevel(level Level, parameters ...string)
SetFilterLevel sets the filter level
If present, the first parameter is the topic.
If present, the second parameter is the scope.
implements logger.FilterSetter
func (*StdoutStream) ShouldLogSourceInfo ¶ added in v1.5.4
func (stream *StdoutStream) ShouldLogSourceInfo() bool
ShouldLogSourceInfo tells if the source info should be logged
implements logger.Streamer
func (*StdoutStream) ShouldWrite ¶
func (stream *StdoutStream) ShouldWrite(level Level, topic, scope string) bool
ShouldWrite tells if the given level should be written to this stream
implements logger.Streamer
func (*StdoutStream) String ¶
func (stream *StdoutStream) String() string
String gets a string version
implements fmt.Stringer
func (*StdoutStream) Write ¶
func (stream *StdoutStream) Write(record *Record) error
Write writes the given Record
implements logger.Streamer
type Streamer ¶
type Streamer interface { // Write writes the given Record Write(record *Record) error // ShouldWrite tells if the given level should be written to this stream ShouldWrite(level Level, topic, scope string) bool // ShouldLogSourceInfo tells if the source info should be logged ShouldLogSourceInfo() bool // Flush flushes the stream (makes sure records are actually written) Flush() // Close closes the stream Close() // GetFilterLevels gets the FilterLevels GetFilterLevels() LevelSet }
Streamer is the interface a Logger writes to
func CreateMultiStream ¶ added in v1.1.1
CreateMultiStream creates a MultiStream that contains all given Streamer objects
func CreateStream ¶ added in v1.6.0
CreateStreamWithDestination creates a new Streamer from a list of strings
"stdout" will create a StdoutStream
"stderr" will create a StderrStream
"nil", "null" will create a NilStream
"stackdriver" will create a StackDriverStream
"gcp", "googlecloud", "google" will create a StdoutStream, unbuffered, with the StackDriverConverter
"file:///path/to/file" or "path/to/file", "/path/to/file" will create a FileStream on the given location
If more than one string is given, a MultiStream of all Streams from strings is created.
If the environment variable DEBUG is set to 1, all Streams are created unbuffered.
If the list is empty, the environment variable LOG_DESTINATION is used.
Source Files ¶
- bufferpool.go
- converter.go
- converter_bunyan.go
- converter_cloudwatch.go
- converter_pino.go
- converter_stackdriver.go
- doc.go
- gettid-linux.go
- level.go
- level_set.go
- logger-context.go
- logger-http.go
- logger-standardlog.go
- logger-time.go
- logger.go
- logger_carrier.go
- mappool.go
- record.go
- redact.go
- redactable.go
- redactor.go
- stream-file.go
- stream-logger.go
- stream-multistream.go
- stream-nil.go
- stream-stackdriver.go
- stream-stderr.go
- stream-stdout.go
- stream.go
- topicscope.go
- version.go
- writer.go