onelog: github.com/francoispqt/onelog Index | Files | Directories

package onelog

import "github.com/francoispqt/onelog"

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

Package Files

entry.go levels.go logger.go onelog.go

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

var ALL = uint8(INFO | DEBUG | WARN | ERROR | FATAL)

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

func LevelKey Uses

func LevelKey(s string)

LevelKey sets the key for the level field.

func LevelText Uses

func LevelText(level uint8, txt string)

LevelText personalises the text for a specific level.

func MsgKey Uses

func MsgKey(s string)

MsgKey sets the key for the message field.

type ChainEntry Uses

type ChainEntry struct {
    Entry
    // contains filtered or unexported fields
}

ChainEntry is for chaining calls to the entry.

func (ChainEntry) Any Uses

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 Uses

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 Uses

func (e ChainEntry) Bool(k string, v bool) ChainEntry

Bool adds a bool to the log entry.

func (ChainEntry) Err Uses

func (e ChainEntry) Err(k string, v error) ChainEntry

Err adds an error to the log entry.

func (ChainEntry) Float Uses

func (e ChainEntry) Float(k string, v float64) ChainEntry

Float adds a float64 to the log entry.

func (ChainEntry) Int Uses

func (e ChainEntry) Int(k string, v int) ChainEntry

Int adds an int to the log entry.

func (ChainEntry) Int64 Uses

func (e ChainEntry) Int64(k string, v int64) ChainEntry

Int64 adds an int64 to the log entry.

func (ChainEntry) Object Uses

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 Uses

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 Uses

func (e ChainEntry) String(k, v string) ChainEntry

String adds a string to the log entry.

func (ChainEntry) Write Uses

func (e ChainEntry) Write()

Info logs an entry with INFO level.

type Encoder Uses

type Encoder = gojay.Encoder

Encoder is an alias to gojay.Encoder.

type Entry Uses

type Entry struct {
    Level   uint8
    Message string
    // contains filtered or unexported fields
}

Entry is the structure wrapping a pointer to the current encoder. It provides easy API to work with GoJay's encoder.

func (Entry) Array Uses

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) Bool Uses

func (e Entry) Bool(k string, v bool) Entry

Bool adds a bool to the log entry.

func (Entry) Err Uses

func (e Entry) Err(k string, v error) Entry

Err adds an error to the log entry.

func (Entry) Float Uses

func (e Entry) Float(k string, v float64) Entry

Float adds a float64 to the log entry.

func (Entry) Int Uses

func (e Entry) Int(k string, v int) Entry

Int adds an int to the log entry.

func (Entry) Int64 Uses

func (e Entry) Int64(k string, v int64) Entry

Int64 adds an int64 to the log entry.

func (Entry) Object Uses

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 Uses

func (e Entry) ObjectFunc(k string, v func(Entry)) Entry

ObjectFunc adds an object to the log entry by calling a function.

func (Entry) String Uses

func (e Entry) String(k, v string) Entry

String adds a string to the log entry.

type ExitFunc Uses

type ExitFunc func(int)

ExitFunc is used to exit the app, `os.Exit()` is set as default on `New()`

type Logger Uses

type Logger struct {
    ExitFn ExitFunc
    // contains filtered or unexported fields
}

Logger is the type representing a logger.

func New Uses

func New(w io.Writer, levels uint8) *Logger

New returns a fresh onelog Logger with default values.

func NewContext Uses

func NewContext(w io.Writer, levels uint8, contextName string) *Logger

NewContext returns a fresh onelog Logger with default values and context name set to provided contextName value.

func (*Logger) Caller Uses

func (l *Logger) Caller(n int) string

Caller returns the caller in the stack trace, skipped n times.

func (*Logger) Debug Uses

func (l *Logger) Debug(msg string)

Debug logs an entry with DEBUG level.

func (*Logger) DebugWith Uses

func (l *Logger) DebugWith(msg string) ChainEntry

DebugWith return ChainEntry with DEBUG level.

func (*Logger) DebugWithFields Uses

func (l *Logger) DebugWithFields(msg string, fields func(Entry))

DebugWithFields logs an entry with DEBUG level and custom fields.

func (*Logger) Error Uses

func (l *Logger) Error(msg string)

Error logs an entry with ERROR level

func (*Logger) ErrorWith Uses

func (l *Logger) ErrorWith(msg string) ChainEntry

ErrorWith returns a ChainEntry with ERROR level.

func (*Logger) ErrorWithFields Uses

func (l *Logger) ErrorWithFields(msg string, fields func(Entry))

ErrorWithFields logs an entry with ERROR level and custom fields.

func (*Logger) Fatal Uses

func (l *Logger) Fatal(msg string)

Fatal logs an entry with FATAL level.

func (*Logger) FatalWith Uses

func (l *Logger) FatalWith(msg string) ChainEntry

FatalWith returns a ChainEntry with FATAL level.

func (*Logger) FatalWithFields Uses

func (l *Logger) FatalWithFields(msg string, fields func(Entry))

FatalWithFields logs an entry with FATAL level and custom fields.

func (*Logger) Hook Uses

func (l *Logger) Hook(h func(Entry)) *Logger

Hook sets a hook to run for all log entries to add generic fields

func (*Logger) Info Uses

func (l *Logger) Info(msg string)

Info logs an entry with INFO level.

func (*Logger) InfoWith Uses

func (l *Logger) InfoWith(msg string) ChainEntry

InfoWith return an ChainEntry with INFO level.

func (*Logger) InfoWithFields Uses

func (l *Logger) InfoWithFields(msg string, fields func(Entry))

InfoWithFields logs an entry with INFO level and custom fields.

func (*Logger) Warn Uses

func (l *Logger) Warn(msg string)

Warn logs an entry with WARN level.

func (*Logger) WarnWith Uses

func (l *Logger) WarnWith(msg string) ChainEntry

WarnWith returns a ChainEntry with WARN level

func (*Logger) WarnWithFields Uses

func (l *Logger) WarnWithFields(msg string, fields func(Entry))

WarnWithFields logs an entry with WARN level and custom fields.

func (*Logger) With Uses

func (l *Logger) With(f func(Entry)) *Logger

With copies the current Logger and adds it a given context by running func f.

func (*Logger) WithContext Uses

func (l *Logger) WithContext(contextName string) *Logger

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.

type Object Uses

type Object = gojay.EncodeObjectFunc

Object is an alias to gojay.EncodeObjectFunc.

Directories

PathSynopsis
log

Package onelog imports 6 packages (graph) and is imported by 5 packages. Updated 2019-03-07. Refresh now. Tools for package owners.