Documentation ¶
Overview ¶
Package onelog is a fast, low allocation and modular JSON logger.
It uses github.com/francoispqt/gojay as JSON encoder.
Basic usage:
import "github.com/francoispqt/onelog/log" log.Info("hello world !") // {"level":"info","message":"hello world !", "time":1494567715}
You can create your own logger:
import "github.com/francoispqt/onelog var logger = onelog.New(os.Stdout, onelog.ALL) func main() { logger.Info("hello world !") // {"level":"info","message":"hello world !"} }
Index ¶
- Constants
- Variables
- func LevelKey(s string)
- func LevelText(level uint8, txt string)
- func MsgKey(s string)
- type ChainEntry
- func (e ChainEntry) Any(k string, obj interface{}) ChainEntry
- func (e ChainEntry) Array(k string, obj gojay.MarshalerJSONArray) ChainEntry
- func (e ChainEntry) Bool(k string, v bool) ChainEntry
- func (e ChainEntry) Err(k string, v error) ChainEntry
- func (e ChainEntry) Float(k string, v float64) ChainEntry
- func (e ChainEntry) Int(k string, v int) ChainEntry
- func (e ChainEntry) Int64(k string, v int64) ChainEntry
- func (e ChainEntry) Object(k string, obj gojay.MarshalerJSONObject) ChainEntry
- func (e ChainEntry) ObjectFunc(k string, v func(Entry)) ChainEntry
- func (e ChainEntry) String(k, v string) ChainEntry
- func (e ChainEntry) Write()
- type Encoder
- type Entry
- func (e Entry) Array(k string, obj gojay.MarshalerJSONArray) Entry
- func (e Entry) Bool(k string, v bool) Entry
- func (e Entry) Err(k string, v error) Entry
- func (e Entry) Float(k string, v float64) Entry
- func (e Entry) Int(k string, v int) Entry
- func (e Entry) Int64(k string, v int64) Entry
- func (e Entry) Object(k string, obj gojay.MarshalerJSONObject) Entry
- func (e Entry) ObjectFunc(k string, v func(Entry)) Entry
- func (e Entry) String(k, v string) Entry
- type ExitFunc
- type Logger
- func (l *Logger) Caller(n int) string
- func (l *Logger) Debug(msg string)
- func (l *Logger) DebugWith(msg string) ChainEntry
- func (l *Logger) DebugWithFields(msg string, fields func(Entry))
- func (l *Logger) Error(msg string)
- func (l *Logger) ErrorWith(msg string) ChainEntry
- func (l *Logger) ErrorWithFields(msg string, fields func(Entry))
- func (l *Logger) Fatal(msg string)
- func (l *Logger) FatalWith(msg string) ChainEntry
- func (l *Logger) FatalWithFields(msg string, fields func(Entry))
- func (l *Logger) Hook(h func(Entry)) *Logger
- func (l *Logger) Info(msg string)
- func (l *Logger) InfoWith(msg string) ChainEntry
- func (l *Logger) InfoWithFields(msg string, fields func(Entry))
- func (l *Logger) Warn(msg string)
- func (l *Logger) WarnWith(msg string) ChainEntry
- func (l *Logger) WarnWithFields(msg string, fields func(Entry))
- func (l *Logger) With(f func(Entry)) *Logger
- func (l *Logger) WithContext(contextName string) *Logger
- type Object
Constants ¶
const ( // INFO is the numeric code for INFO log level INFO = uint8(0x1) // DEBUG is the numeric code for DEBUG log level DEBUG = uint8(0x2) // WARN is the numeric code for WARN log level WARN = uint8(0x4) // ERROR is the numeric code for ERROR log level ERROR = uint8(0x8) // FATAL is the numeric code for FATAL log level FATAL = uint8(0x10) )
Variables ¶
ALL is a shortcut to INFO | DEBUG | WARN | ERROR | FATAL to enable all logging levels
var Levels = make([]string, 256)
Levels is the mapping between int log levels and their string value
Functions ¶
Types ¶
type ChainEntry ¶
type ChainEntry struct { Entry // contains filtered or unexported fields }
ChainEntry is for chaining calls to the entry.
func (ChainEntry) Any ¶
func (e ChainEntry) Any(k string, obj interface{}) ChainEntry
Any adds anything stuff to the log entry based on it's type
func (ChainEntry) Array ¶
func (e ChainEntry) Array(k string, obj gojay.MarshalerJSONArray) ChainEntry
Array adds an object to the log entry by passing an implementation of gojay.MarshalerJSONObject.
func (ChainEntry) Bool ¶
func (e ChainEntry) Bool(k string, v bool) ChainEntry
Bool adds a bool to the log entry.
func (ChainEntry) Err ¶
func (e ChainEntry) Err(k string, v error) ChainEntry
Err adds an error to the log entry.
func (ChainEntry) Float ¶
func (e ChainEntry) Float(k string, v float64) ChainEntry
Float adds a float64 to the log entry.
func (ChainEntry) Int ¶
func (e ChainEntry) Int(k string, v int) ChainEntry
Int adds an int to the log entry.
func (ChainEntry) Int64 ¶
func (e ChainEntry) Int64(k string, v int64) ChainEntry
Int64 adds an int64 to the log entry.
func (ChainEntry) Object ¶
func (e ChainEntry) Object(k string, obj gojay.MarshalerJSONObject) ChainEntry
Object adds an object to the log entry by passing an implementation of gojay.MarshalerJSONObject.
func (ChainEntry) ObjectFunc ¶
func (e ChainEntry) ObjectFunc(k string, v func(Entry)) ChainEntry
ObjectFunc adds an object to the log entry by calling a function.
func (ChainEntry) String ¶
func (e ChainEntry) String(k, v string) ChainEntry
String adds a string to the log entry.
type Entry ¶
Entry is the structure wrapping a pointer to the current encoder. It provides easy API to work with GoJay's encoder.
func (Entry) Array ¶
func (e Entry) Array(k string, obj gojay.MarshalerJSONArray) Entry
Array adds an object to the log entry by passing an implementation of gojay.MarshalerJSONObject.
func (Entry) Object ¶
func (e Entry) Object(k string, obj gojay.MarshalerJSONObject) Entry
Object adds an object to the log entry by passing an implementation of gojay.MarshalerJSONObject.
func (Entry) ObjectFunc ¶
ObjectFunc adds an object to the log entry by calling a function.
type ExitFunc ¶
type ExitFunc func(int)
ExitFunc is used to exit the app, `os.Exit()` is set as default on `New()`
type Logger ¶
type Logger struct { ExitFn ExitFunc // contains filtered or unexported fields }
Logger is the type representing a logger.
func NewContext ¶
NewContext returns a fresh onelog Logger with default values and context name set to provided contextName value.
func (*Logger) DebugWith ¶
func (l *Logger) DebugWith(msg string) ChainEntry
DebugWith return ChainEntry with DEBUG level.
func (*Logger) DebugWithFields ¶
DebugWithFields logs an entry with DEBUG level and custom fields.
func (*Logger) ErrorWith ¶
func (l *Logger) ErrorWith(msg string) ChainEntry
ErrorWith returns a ChainEntry with ERROR level.
func (*Logger) ErrorWithFields ¶
ErrorWithFields logs an entry with ERROR level and custom fields.
func (*Logger) FatalWith ¶
func (l *Logger) FatalWith(msg string) ChainEntry
FatalWith returns a ChainEntry with FATAL level.
func (*Logger) FatalWithFields ¶
FatalWithFields logs an entry with FATAL level and custom fields.
func (*Logger) InfoWith ¶
func (l *Logger) InfoWith(msg string) ChainEntry
InfoWith return an ChainEntry with INFO level.
func (*Logger) InfoWithFields ¶
InfoWithFields logs an entry with INFO level and custom fields.
func (*Logger) WarnWith ¶
func (l *Logger) WarnWith(msg string) ChainEntry
WarnWith returns a ChainEntry with WARN level
func (*Logger) WarnWithFields ¶
WarnWithFields logs an entry with WARN level and custom fields.
func (*Logger) WithContext ¶
WithContext copies current logger enforcing all entry fields to be set into a map with the contextName set as the key name for giving map. This allows allocating all future uses of the logging methods to follow such formatting. The only exception are values provided by added hooks which will remain within the root level of generated json.