logger

package
v5.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: GPL-3.0 Imports: 15 Imported by: 140

Documentation

Overview

Package logger implements a multi-output leveled logger.

Other packages use tagged logger to send log messages to shared (process-wide) logging engine. The shared logging engine dispatches to multiple log systems. The log level can be set separately per log system.

Logging is asynchronous and does not block the caller. Message formatting is performed by the caller goroutine to avoid incorrect logging of mutable state.

Index

Examples

Constants

View Source
const (
	Error = iota + 1
	Warn
	Info
	Core
	Debug
	Detail

	Ridiculousness = 100
)
View Source
const (
	MLOGJSON mlogFormatT
)

Variables

View Source
var (
	ErrUnkownMLogFormat = errors.New("unknown mlog format")

	MLogStringToFormat = map[string]mlogFormatT{
		"plain": mLOGPlain,
		"kv":    mLOGKV,
		"json":  MLOGJSON,
	}
)

Functions

func AddLogSystem

func AddLogSystem(sys LogSystem)

AddLogSystem starts printing messages to the given LogSystem.

func ColorBlue

func ColorBlue(s string) (coloredString string)

func ColorGreen

func ColorGreen(s string) (coloredString string)

func ColorMagenta

func ColorMagenta(s string) (coloredString string)

func ColorRed

func ColorRed(s string) (coloredString string)

func ColorYellow

func ColorYellow(s string) (coloredString string)

func CreateMLogFile

func CreateMLogFile(t time.Time) (f *os.File, filename string, err error)

CreateMLogFile creates a new log file and returns the file and its filename, which contains tag ("INFO", "FATAL", etc.) and t. If the file is created successfully, create also attempts to update the symlink for that tag, ignoring errors.

func Flush

func Flush()

Flush waits until all current log messages have been dispatched to the active log systems.

func GetMLogDir

func GetMLogDir() string

func GetMLogFormat

func GetMLogFormat() mlogFormatT

func GetMLogRegistryActive

func GetMLogRegistryActive() map[mlogComponent]*Logger

GetMlogRegistryActive returns copy of all active components mapping

func GetMLogRegistryAvailable

func GetMLogRegistryAvailable() map[mlogComponent][]*MLogT

GetMlogRegistryAvailable returns copy of all registered components mapping

func MLogRegisterActive

func MLogRegisterActive(component mlogComponent)

MLogRegisterActive registers a component for mlogging. Only registered loggers will write to mlog file.

func MLogRegisterAvailable

func MLogRegisterAvailable(name string, lines []*MLogT) mlogComponent

MLogRegisterAvailable is called for each log component variable from a package/mlog.go file as they set up their mlog vars. It registers an mlog component as Available.

func MLogRegisterComponentsFromContext

func MLogRegisterComponentsFromContext(s string) error

MLogRegisterComponentsFromContext receives a comma-separated string of desired mlog components. It returns an error if the specified mlog component is unavailable. For each available component, the desires mlog components are registered as active, creating new loggers for each. If the string begins with '!', the function will remove the following components from the default list

func MlogEnabled

func MlogEnabled() bool

func Reset

func Reset()

Reset removes all active log systems. It blocks until all current messages have been delivered.

func SetMLogDir

func SetMLogDir(str string)

SetMLogDir sets the mlog directory, into which one mlog file per session will be written.

func SetMLogFormat

func SetMLogFormat(format mlogFormatT)

func SetMLogFormatFromString

func SetMLogFormatFromString(formatString string) error

func SetMlogEnabled

func SetMlogEnabled(b bool)

Types

type EthChainNewHead added in v0.8.4

type EthChainNewHead struct {
	BlockHash     string   `json:"block_hash"`
	BlockNumber   *big.Int `json:"block_number"`
	ChainHeadHash string   `json:"chain_head_hash"`
	BlockPrevHash string   `json:"block_prev_hash"`
	LogEvent
}

func (*EthChainNewHead) EventName added in v0.8.4

func (l *EthChainNewHead) EventName() string

type EthChainReceivedNewBlock added in v0.8.4

type EthChainReceivedNewBlock struct {
	BlockHash     string   `json:"block_hash"`
	BlockNumber   *big.Int `json:"block_number"`
	ChainHeadHash string   `json:"chain_head_hash"`
	BlockPrevHash string   `json:"block_prev_hash"`
	RemoteId      string   `json:"remote_id"`
	LogEvent
}

func (*EthChainReceivedNewBlock) EventName added in v0.8.4

func (l *EthChainReceivedNewBlock) EventName() string

type EthMinerNewBlock added in v0.8.4

type EthMinerNewBlock struct {
	BlockHash     string   `json:"block_hash"`
	BlockNumber   *big.Int `json:"block_number"`
	ChainHeadHash string   `json:"chain_head_hash"`
	BlockPrevHash string   `json:"block_prev_hash"`
	LogEvent
}

func (*EthMinerNewBlock) EventName added in v0.8.4

func (l *EthMinerNewBlock) EventName() string

type EthTxReceived added in v0.8.4

type EthTxReceived struct {
	TxHash   string `json:"tx_hash"`
	RemoteId string `json:"remote_id"`
	LogEvent
}

func (*EthTxReceived) EventName added in v0.8.4

func (l *EthTxReceived) EventName() string

type JsonLog added in v0.8.4

type JsonLog interface {
	EventName() string
}

type JsonLogger added in v0.8.4

type JsonLogger struct {
	Coinbase string
}

func NewJsonLogger added in v0.8.4

func NewJsonLogger() *JsonLogger

func (*JsonLogger) LogJson added in v0.8.4

func (logger *JsonLogger) LogJson(v JsonLog)

type LogEvent added in v0.8.4

type LogEvent struct {
	// Guid string      `json:"guid"`
	Ts utctime8601 `json:"ts"`
}

type LogLevel

type LogLevel uint32
const (
	// Standard log levels
	Silence LogLevel = iota
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	DebugDetailLevel
)

type LogMsg added in v0.9.17

type LogMsg interface {
	Level() LogLevel
	fmt.Stringer
}

type LogStarting added in v0.8.4

type LogStarting struct {
	ClientString    string `json:"client_impl"`
	ProtocolVersion int    `json:"eth_version"`
	LogEvent
}

func (*LogStarting) EventName added in v0.8.4

func (l *LogStarting) EventName() string

type LogSystem

type LogSystem interface {
	LogPrint(LogMsg)
	GetLogger() *log.Logger
}

LogSystem is implemented by log output devices. All methods can be called concurrently from multiple goroutines.

Example
filename := "test.log"
file, _ := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, os.ModePerm)
fileLog := NewStdLogSystem(file, 0, WarnLevel)
AddLogSystem(fileLog)

stdoutLog := NewStdLogSystem(os.Stdout, 0, WarnLevel)
AddLogSystem(stdoutLog)

NewLogger("TAG").Warnln("reactor meltdown") // writes to both logs
Output:

func BuildNewMLogSystem

func BuildNewMLogSystem(datadir string, logFile string, logLevel int, flags int, withTimestamp bool) LogSystem

func New added in v0.8.4

func New(datadir string, logFile string, logLevel int, flags int) LogSystem

func NewJSONsystem added in v0.9.17

func NewJSONsystem(datadir string, logFile string) LogSystem

func NewJsonLogSystem added in v0.9.17

func NewJsonLogSystem(writer io.Writer) LogSystem

NewJSONLogSystem creates a LogSystem that prints to the given writer without adding extra information irrespective of loglevel only if message is JSON type

type Logger

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

A Logger prints messages prefixed by a given tag. It provides named Printf and Println style methods for all loglevels. Each ethereum component should have its own logger with a unique prefix.

Example
logger := NewLogger("TAG")
logger.Infoln("so awesome")            // prints [TAG] so awesome
logger.Infof("this %q is raw", "coin") // prints [TAG] this "coin" is raw
Output:

func NewLogger

func NewLogger(tag string) *Logger

func (*Logger) DebugDetailf

func (logger *Logger) DebugDetailf(format string, v ...interface{})

DebugDetailf writes a message with DebugDetailLevel.

func (*Logger) DebugDetailln

func (logger *Logger) DebugDetailln(v ...interface{})

DebugDetailln writes a message with DebugDetailLevel.

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, v ...interface{})

Debugf writes a message with DebugLevel.

func (*Logger) Debugln

func (logger *Logger) Debugln(v ...interface{})

Debugln writes a message with DebugLevel.

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, v ...interface{})

Errorf writes a message with ErrorLevel.

func (*Logger) Errorln

func (logger *Logger) Errorln(v ...interface{})

Errorln writes a message with ErrorLevel.

func (*Logger) Fatalf

func (logger *Logger) Fatalf(format string, v ...interface{})

Fatalf writes a message with ErrorLevel and exits the program.

func (*Logger) Fatalln

func (logger *Logger) Fatalln(v ...interface{})

Fatalln writes a message with ErrorLevel and exits the program.

func (*Logger) GetTag

func (logger *Logger) GetTag() string

GetTag is a getter function to expose the logger's tag

func (*Logger) Infof

func (logger *Logger) Infof(format string, v ...interface{})

Infof writes a message with InfoLevel.

func (*Logger) Infoln

func (logger *Logger) Infoln(v ...interface{})

Infoln writes a message with InfoLevel.

func (*Logger) SendFormatted

func (l *Logger) SendFormatted(format mlogFormatT, level LogLevel, msg *MLogT, c mlogComponent)

func (*Logger) Sendf added in v0.9.17

func (logger *Logger) Sendf(level LogLevel, format string, v ...interface{})

func (*Logger) Sendln added in v0.9.17

func (logger *Logger) Sendln(level LogLevel, v ...interface{})

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, v ...interface{})

Warnf writes a message with WarnLevel.

func (*Logger) Warnln

func (logger *Logger) Warnln(v ...interface{})

Warnln writes a message with WarnLevel.

type MLogDetailT

type MLogDetailT struct {
	Owner string      `json:"owner"`
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

MLogDetailT defines an mlog LINE DETAILS

func (*MLogDetailT) AsDocumentation

func (m *MLogDetailT) AsDocumentation() *MLogDetailT

func (*MLogDetailT) EventName

func (m *MLogDetailT) EventName() string

type MLogSystem

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

func NewMLogSystem

func NewMLogSystem(writer io.Writer, flags int, level LogLevel, withTimestamp bool) *MLogSystem

func (*MLogSystem) GetLogLevel

func (m *MLogSystem) GetLogLevel() LogLevel

func (*MLogSystem) GetLogger

func (m *MLogSystem) GetLogger() *log.Logger

func (*MLogSystem) LogPrint

func (m *MLogSystem) LogPrint(msg LogMsg)

func (*MLogSystem) NewFile

func (m *MLogSystem) NewFile() io.Writer

type MLogT

type MLogT struct {
	sync.Mutex
	// TODO: can remove these json tags, since we have a custom MarshalJSON fn
	Description string        `json:"-"`
	Receiver    string        `json:"receiver"`
	Verb        string        `json:"verb"`
	Subject     string        `json:"subject"`
	Details     []MLogDetailT `json:"details"`
}

MLogT defines an mlog LINE

func (*MLogT) AssignDetails

func (m *MLogT) AssignDetails(detailVals ...interface{}) *MLogT

AssignDetails is a setter function for setting values for pre-existing details. It accepts a variadic number of empty interfaces. If the number of arguments does not match the number of established details for the receiving MLogT, it will fatal error. Arguments MUST be provided in the order in which they should be applied to the slice of existing details.

func (*MLogT) EventName

func (m *MLogT) EventName() string

EventName implements the JsonMsg interface in case wanting to use existing half-established json logging system

func (*MLogT) FormatDocumentation

func (m *MLogT) FormatDocumentation(cmp mlogComponent) (out string)

FormatDocumentation prints wiki-ready documentation for all available component mlog LINES. Output should be in markdown.

func (*MLogT) FormatJSON

func (m *MLogT) FormatJSON(c mlogComponent) []byte

func (*MLogT) FormatJSONExample

func (m *MLogT) FormatJSONExample(c mlogComponent) []byte

func (*MLogT) FormatKV

func (m *MLogT) FormatKV() (out string)

func (*MLogT) FormatPlain

func (m *MLogT) FormatPlain() (out string)

func (*MLogT) MarshalJSON

func (m *MLogT) MarshalJSON(c mlogComponent) ([]byte, error)

func (*MLogT) Send

func (msg *MLogT) Send(c mlogComponent)

SendMLog writes enabled component mlogs to file if the component is registered active.

type P2PConnected added in v0.8.4

type P2PConnected struct {
	RemoteId            string `json:"remote_id"`
	RemoteAddress       string `json:"remote_addr"`
	RemoteVersionString string `json:"remote_version_string"`
	NumConnections      int    `json:"num_connections"`
	LogEvent
}

func (*P2PConnected) EventName added in v0.8.4

func (l *P2PConnected) EventName() string

type P2PDisconnected added in v0.8.4

type P2PDisconnected struct {
	NumConnections int    `json:"num_connections"`
	RemoteId       string `json:"remote_id"`
	LogEvent
}

func (*P2PDisconnected) EventName added in v0.8.4

func (l *P2PDisconnected) EventName() string

type StdLogSystem added in v0.9.17

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

func NewStdLogSystem

func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem

NewStdLogSystem creates a LogSystem that prints to the given writer. The flag values are defined package log.

func (*StdLogSystem) GetLogLevel added in v0.9.17

func (t *StdLogSystem) GetLogLevel() LogLevel

func (*StdLogSystem) GetLogger

func (t *StdLogSystem) GetLogger() *log.Logger

GetLogger is unused, fulfills interface

func (*StdLogSystem) LogPrint added in v0.9.17

func (t *StdLogSystem) LogPrint(msg LogMsg)

func (*StdLogSystem) SetLogLevel added in v0.9.17

func (t *StdLogSystem) SetLogLevel(i LogLevel)

Directories

Path Synopsis
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.

Jump to

Keyboard shortcuts

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