lg

package module
v0.0.0-...-0f198d4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2015 License: MIT Imports: 11 Imported by: 1

README

lg

Structured Logging Api

Thoughts on Logging for Servers

The ideal case is that a well structured (i.e. JSON) messages gets recorded to a central log repository on a different machine that provides search (i.e. Logstash and ElasticSearch). As long as all log messages are guaranteed to be well formatted this works great. However, an erroneous unformatted message can cause problems for readers expecting JSON. Therefore, a strategy to handle this situation is to only have unexpected messages (i.e. Panics) go to stderr and capture these unstructured errors in a separate file in the operational environment such as using runit's default logging for this.
The rest of the structured logging can go to a structured only destination, such as a file or external system.

There are 2 primary contexts to consume logs.

  1. A human logged into a machine an running commands locally on that machine.
    • tail a human readable format
    • have a separate file for alerts such that they are not lost when there are many log messages
  2. Centralized logging and search server.
    • Requires a consistent format. (i.e. all entries are JSON)
      • Structured Stream
      • Unstructured Stream
    • Can handle a large volume of messages, due to search.

Documentation

Index

Constants

View Source
const (
	KindPanic   = "panic"
	KindError   = "error"
	KindWarn    = "warn"
	KindInform  = "inform"
	KindVerbose = "verbose"

	KindTimeout   = "timeout"
	KindConnect   = "connect"
	KindMarshal   = "marshal"
	KindUnmarshal = "unmarshal"
)

Variables

This section is empty.

Functions

func AddReceiver

func AddReceiver(r LogReceiver)

func DisableLog

func DisableLog()

DisableLog disables all library log output

func Error

func Error(m string, err error, kv ...KV)

func FlushLog

func FlushLog()

Call this before app shutdown

func Inform

func Inform(m string, kv ...KV)

func Message

func Message(m *LogMessage)

func Panic

func Panic(m string, err error, kv ...KV) interface{}

func SetLogWriter

func SetLogWriter(writer io.Writer) error

SetLogWriter uses a specified io.Writer to output library log. Use this func if you are not using Seelog logging system in your app.

func Use

func Use(l LevelLogger)

func UseLogger

func UseLogger(newLogger seelog.LoggerInterface)

UseLogger uses a specified seelog.LoggerInterface to output library log. Use this func if you are using Seelog logging system in your app.

func Verbose

func Verbose(m string, kv ...KV)

func Warn

func Warn(m string, kv ...KV)

Types

type Config

type Config interface {
	LogFolder() string     //path to logging folder
	MaxAge() time.Duration //min age 1 day?
	MaxBackups() int
	MaxSizeMB() int //TODO: use custom datatype??
	Level() string
}

type ConsoleLog

type ConsoleLog struct {
}

func (*ConsoleLog) Levels

func (l *ConsoleLog) Levels() []Level

func (*ConsoleLog) Message

func (l *ConsoleLog) Message(m *LogMessage)

type KV

type KV map[string]interface{}

type Kind

type Kind string

type Level

type Level uint8
const (
	LevelAll Level = iota
	LevelVerbose
	LevelInform
	LevelWarn
	LevelError
	LevelPanic
)

type LevelLogger

type LevelLogger interface {
	// usage panic(lg.Panic("crap!", err))
	Panic(m string, err error, kv ...KV) interface{}
	Error(m string, err error, kv ...KV) //do we have a message here?
	Warn(m string, kv ...KV)

	// lg.Inform("Server Started", lg.KV{"config", config, "port", port}
	Inform(m string, kv ...KV)

	Verbose(m string, kv ...KV) //debug

	Message(m *LogMessage)

	AddReceiver(r LogReceiver)
}

type LogConfig

type LogConfig struct {
	Folder    string
	MaxAge    time.Duration //1 day
	MaxFiles  int
	MaxSizeMB int
	Level     string

	CrashFilename string //crash-2015-04-30_T02-23-00-234.log
	MainFilename  string //current
	AlertFilename string //alert.log
}

type LogMessage

type LogMessage struct {
	Message string `json:"message"`
	Details KV     `json:"details,omitempty"`
	Level   Level  `json:"level,omitempty"`
	Kind    Kind   `json:"kind,omitempty"`

	// Options
	// 1. traceuid
	// 2. spanuid
	// 3. line #
	// 4. file name
	// 5. func name
	Correlate map[string]string `json:"correlate,omitempty"`
	// contains filtered or unexported fields
}

type LogReceiver

type LogReceiver interface {
	Message(m *LogMessage)
	Levels() []Level
}

type Logger

type Logger interface {
	LevelLogger
	// MarshalFail occurs when an object fails to marshal.
	// Solving a Marshal failure requires discovering which object type and what data was
	// in that instance that could have caused the failure. This is why the interface requires
	// the object
	MarshalFail(m string, obj interface{}, err error)
	// UnmarshalFail occures when a stream is unable to be unmarshalled.
	// Solving a unmarshal failure requires knowing what object type, which field, and
	// what's wrong with the source data that causes the problem
	UnmarshalFail(m string, data []byte, err error)

	Timeout(m string, err error, kv ...KV)
	ConnectFail(m string, err error, kv ...KV)
}

type LogrusReceiver

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

func (*LogrusReceiver) Current

func (l *LogrusReceiver) Current() *logrus.Logger

Current - return the current Logrus instance to customize

func (*LogrusReceiver) Levels

func (l *LogrusReceiver) Levels() []Level

func (*LogrusReceiver) Message

func (l *LogrusReceiver) Message(m *LogMessage)

type MultiLog

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

func (*MultiLog) AddReceiver

func (l *MultiLog) AddReceiver(r LogReceiver)

func (*MultiLog) ConnectFail

func (l *MultiLog) ConnectFail(m string, err error, kv ...KV)

func (*MultiLog) Error

func (l *MultiLog) Error(m string, err error, kv ...KV)

func (*MultiLog) Inform

func (l *MultiLog) Inform(m string, kv ...KV)

func (*MultiLog) MarshalFail

func (l *MultiLog) MarshalFail(m string, obj interface{}, err error)

func (*MultiLog) Message

func (l *MultiLog) Message(m *LogMessage)

func (*MultiLog) Panic

func (l *MultiLog) Panic(m string, err error, kv ...KV) interface{}

func (*MultiLog) Timeout

func (l *MultiLog) Timeout(m string, err error, kv ...KV)

func (*MultiLog) UnmarshalFail

func (l *MultiLog) UnmarshalFail(m string, data []byte, err error)

func (*MultiLog) Verbose

func (l *MultiLog) Verbose(m string, kv ...KV)

func (*MultiLog) Warn

func (l *MultiLog) Warn(m string, kv ...KV)

type NoOpLogger

type NoOpLogger struct {
}

func NewNoOpLogger

func NewNoOpLogger() *NoOpLogger

func (*NoOpLogger) AddReceiver

func (l *NoOpLogger) AddReceiver(r LogReceiver)

func (*NoOpLogger) Error

func (l *NoOpLogger) Error(m string, err error, kv ...KV)

func (*NoOpLogger) Inform

func (l *NoOpLogger) Inform(m string, kv ...KV)

func (*NoOpLogger) Message

func (l *NoOpLogger) Message(m *LogMessage)

func (*NoOpLogger) Panic

func (l *NoOpLogger) Panic(m string, err error, kv ...KV) interface{}

func (*NoOpLogger) Verbose

func (l *NoOpLogger) Verbose(m string, kv ...KV)

func (*NoOpLogger) Warn

func (l *NoOpLogger) Warn(m string, kv ...KV)

type RequstLogger

type RequstLogger interface {
	Capture(service string, name string, args map[string]string, duration int, outcome bool)
}

type SeeLog

type SeeLog struct {
}

func (*SeeLog) Levels

func (l *SeeLog) Levels() []Level

func (*SeeLog) Message

func (l *SeeLog) Message(m *LogMessage)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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