logger

package module
v0.0.0-...-ddea612 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 11 Imported by: 0

README

go-logger

Build Status Coverage Status

A package with logger implementation for Go. Contains Travix-specific fields

Benchmarks

Benchmark_Logger/DebugLog-12              196723              5344 ns/op            3331 B/op         31 allocs/op
Benchmark_Logger/DebugStrLog-12           235294              5613 ns/op            3299 B/op         33 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AppGroup   string
	AppName    string
	AppVersion string
	HostName   string
	LogLevel   Level
	// contains filtered or unexported fields
}

Config initial arguments to create logger

func NewLoggerConfig

func NewLoggerConfig() Config

NewLoggerConfig setups default options for the logger

type Level

type Level uint8

Level defines log levels.

const (
	// DebugLevel defines debug log level.
	DebugLevel Level = iota
	// InfoLevel defines info log level.
	InfoLevel
	// WarnLevel defines warn log level.
	WarnLevel
	// ErrorLevel defines error log level.
	ErrorLevel
	// FatalLevel defines fatal log level.
	FatalLevel
	// PanicLevel defines panic log level.
	PanicLevel
	// NoLevel defines an absent log level.
	NoLevel
	// Disabled disables the logger.
	Disabled
)

func ParseLogLevel

func ParseLogLevel(str string) Level

ParseLogLevel parses text log level to object

func (Level) String

func (l Level) String() string

type Logger

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

Logger is used to write log messages.

func NewLogger

func NewLogger(cfg Config) Logger

NewLogger sets and returns a new global-level logger.

func Nop

func Nop() Logger

Nop returns a disabled logger for which all operation are no-op.

func (Logger) Bool

func (l Logger) Bool(key string, b bool) Logger

Bool adds the field key with val as a bool to the Message.

func (Logger) Bytes

func (l Logger) Bytes(key string, val []byte) Logger

Bytes adds the field key with val as a string to the Logger.

Runes outside of normal ASCII ranges will be hex-encoded in the resulting JSON.

func (Logger) Debug

func (l Logger) Debug(msgType string) Message

Debug starts a new message with debug level.

func (Logger) Error

func (l Logger) Error(errorcode string) Message

Error starts a new message with error level.

func (Logger) Float64

func (l Logger) Float64(key string, f float64) Logger

Float64 adds the field key with val as a float64 to the Logger.

func (Logger) GetLogLevel

func (l Logger) GetLogLevel() string

GetLogLevel returns the log level of the Logger.

func (Logger) Info

func (l Logger) Info(msgType string) Message

Info starts a new message with info level.

func (Logger) Int

func (l Logger) Int(key string, i int) Logger

Int adds the field key with val as an int to the Logger.

func (Logger) IsDebugLevel

func (l Logger) IsDebugLevel() bool

IsDebugLevel returns true if the current logger has debug level.

func (Logger) JSON

func (l Logger) JSON(key string, val interface{}) Logger

JSON adds the field key with val as JSON-encoded to the Logger.

func (Logger) Str

func (l Logger) Str(key, val string) Logger

Str adds the field key with val as a string to the Logger.

func (Logger) Warn

func (l Logger) Warn(msgType string) Message

Warn starts a new message with warn level.

func (Logger) With

func (l Logger) With() Logger

With clones the current Logger to be used within a separate context.

func (Logger) WithLevel

func (l Logger) WithLevel(logLevel Level) Logger

WithLevel clones the current logger within a separate context and with the specified log level.

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents a log message with a particular log level.

func (Message) Bool

func (m Message) Bool(key string, b bool) Message

Bool adds the field key with val as a bool to the Message.

func (Message) Bytes

func (m Message) Bytes(key string, val []byte) Message

Bytes adds the field key with val as a string to the Message.

Runes outside of normal ASCII ranges will be hex-encoded in the resulting JSON.

func (Message) Float64

func (m Message) Float64(key string, f float64) Message

Float64 adds the field key with val as a float64 to the Message.

func (Message) Int

func (m Message) Int(key string, i int) Message

Int adds the field key with val as an int to the Message.

func (Message) JSON

func (m Message) JSON(key string, val interface{}) Message

JSON adds the field key with val as JSON-encoded to the Message.

func (Message) Log

func (m Message) Log(msg string)

Log sends the Message with msg added as the message field if not empty

func (Message) LogErr

func (m Message) LogErr(err error)

LogErr sends the Message with the error

func (Message) LogJSON

func (m Message) LogJSON(msg string, obj interface{})

LogJSON sends the Message with the obj added as JSON-encoded in the message field event.

func (Message) LogMsg

func (m Message) LogMsg(shortMsg, msg string)

LogMsg sends the Message with shortmsg added as the message field and msg in the payload

func (Message) Logf

func (m Message) Logf(format string, v ...interface{})

Logf sends the Message with formatted msg added as the message field if not empty event.

func (Message) Str

func (m Message) Str(key, val string) Message

Str adds the field key with val as a string to the Message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL