logger

package
v0.18.6 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// FieldAuthUser - User
	FieldAuthUser = "User"
	// FieldThread - Thread number
	FieldThread = "Thread"
	// FieldSession - session number
	FieldSession = "Session"
	// FieldSessionName - session name
	FieldSessionName = "SessionName"
	// FieldAppName - app name
	FieldAppName = "AppName"
	// FieldAppGUID - app GUID
	FieldAppGUID = "AppGUID"
	// FieldTick - high def time
	FieldTick = "Tick"
	// FieldAction - action name
	FieldAction = "Action"
	// FieldResponseTime - response time
	FieldResponseTime = "ResponseTime"
	// FieldSuccess - action success
	FieldSuccess = "Success"
	// FieldWarnings - warning count
	FieldWarnings = "Warnings"
	// FieldErrors - error count
	FieldErrors = "Errors"
	// FieldStack - stack trace
	FieldStack = "Stack"
	// FieldSent - bytes sent
	FieldSent = "Sent"
	// FieldReceived - bytes received
	FieldReceived = "Received"
	// FieldLabel - action label
	FieldLabel = "Label"
	// FieldActionID - action id number
	FieldActionID = "ActionId"
	// FieldObjectType - object type
	FieldObjectType = "ObjectType"
	// FieldDetails - details string
	FieldDetails = "Details"
	// FieldInfoType - type of info logging
	FieldInfoType = "InfoType"
	// FieldRequestsSent - request counter
	FieldRequestsSent = "RequestsSent"
	// FieldTime - logging time
	FieldTime = "time"
	// FieldTimestamp - to be used for time without timezone for G3 compliance
	FieldTimestamp = "timestamp"
	// FieldLevel - logging level
	FieldLevel = "level"
	// FieldMessage - message
	FieldMessage = "message"
)

Variables

Functions

func WaitForChanClose

func WaitForChanClose(ctx context.Context, c chan interface{})

WaitForChanClose which ever comes first context cancel or c closed. Returns instantly if channel is nil.

Types

type ActionEntry

type ActionEntry struct {
	Action     string
	Label      string
	ActionID   uint64
	ObjectType string
}

ActionEntry log fields living during action

type HeaderEntry added in v0.10.0

type HeaderEntry struct {
	Key   string
	Value string
}

HeaderEntry contains a Key mapped to a regression log meta data Value.

type JSONWriter

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

JSONWriter wrapper implementing MessageWriter for zerolog

func NewJSONWriter

func NewJSONWriter(zlgr *zerolog.Logger) *JSONWriter

NewJSONWriter wrapper implementing MessageWriter for zerolog

func (*JSONWriter) Level

func (jw *JSONWriter) Level(lvl LogLevel)

Level implement MsgWriter interface

func (*JSONWriter) WriteMessage

func (jw *JSONWriter) WriteMessage(msg *LogChanMsg) error

WriteMessage implement MsgWriter interface

type Log

type Log struct {
	Closed   chan interface{}
	Settings LogSettings
	// contains filtered or unexported fields
}

Log main struct to keep track of and propagate log entries to loggers. Close finished will be signaled on Closed channel.

func NewLog

func NewLog(settings LogSettings) *Log

NewLog instance

func (*Log) AddLoggers

func (log *Log) AddLoggers(loggers ...*Logger)

AddLoggers to be used for logging

func (*Log) Close

func (log *Log) Close() error

Close functions with default timeout of 5 minutes

func (*Log) CloseWithTimeout

func (log *Log) CloseWithTimeout(timeout time.Duration) error

CloseWithTimeout functions with custom timeout

func (*Log) NewLogEntry

func (log *Log) NewLogEntry() *LogEntry

NewLogEntry create new LogEntry using current logger

func (*Log) SetDebug

func (log *Log) SetDebug()

SetDebug level on logging for all loggers

func (*Log) SetMetrics

func (log *Log) SetMetrics()

SetMetrics level on logging for all loggers

func (*Log) SetRegressionLoggerFile added in v0.10.0

func (log *Log) SetRegressionLoggerFile(fileName string) error

SetRegressionLoggerFile to be used for logging regression data to file. The file name is chosen, using `backupName`, to match the name of the standard log file.

func (*Log) SetTraffic

func (log *Log) SetTraffic()

SetTraffic level on logging for all loggers

func (*Log) StartLogger

func (log *Log) StartLogger(ctx context.Context)

StartLogger start async reading on log channel

func (*Log) Write

func (log *Log) Write(msg *LogChanMsg)

Write log message, should be done in go routine to not block

type LogChanMsg

type LogChanMsg struct {
	SessionEntry
	ActionEntry
	// contains filtered or unexported fields
}

LogChanMsg container for row to be logged

func NewEmptyLogChanMsg

func NewEmptyLogChanMsg() *LogChanMsg

NewLogChanMsg create new LogChanMsg, to be used for testing purposes

type LogEntry

type LogEntry struct {
	Session *SessionEntry
	Action  *ActionEntry
	// contains filtered or unexported fields
}

LogEntry entry used for logging

func NewLogEntry

func NewLogEntry(log *Log) *LogEntry

NewLogEntry new instance of LogEntry

func (*LogEntry) AddInterceptor

func (entry *LogEntry) AddInterceptor(level LogLevel, f func(msg *LogEntry) bool)

AddInterceptor to log entry, return false to avoid logging

func (*LogEntry) Log

func (entry *LogEntry) Log(level LogLevel, args ...interface{})

Log write log entry to log

func (*LogEntry) LogDebug

func (entry *LogEntry) LogDebug(msg string)

LogDebug log debug entry with message

func (*LogEntry) LogDebugf

func (entry *LogEntry) LogDebugf(format string, args ...interface{})

LogDebugf log debug entry with message

func (*LogEntry) LogDetail

func (entry *LogEntry) LogDetail(level LogLevel, msg, detail string)

LogDetail log message with detail

func (*LogEntry) LogError

func (entry *LogEntry) LogError(err error)

LogError log error entry

func (*LogEntry) LogErrorReport

func (entry *LogEntry) LogErrorReport(reportType string, errors, warnings uint64)

LogErrorReport log warning and error count

func (*LogEntry) LogErrorWithMsg

func (entry *LogEntry) LogErrorWithMsg(msg string, err error)

LogErrorWithMsg log error entry with message

func (*LogEntry) LogInfo

func (entry *LogEntry) LogInfo(infoType, msg string)

LogInfo log info entry

func (*LogEntry) LogRegression added in v0.10.0

func (entry *LogEntry) LogRegression(id string, data interface{}, meta map[string]interface{}) error

func (*LogEntry) LogResult

func (entry *LogEntry) LogResult(success bool, warnings, errors, sent, received, requests uint64, responsetime int64, details string)

LogResult log result entry

func (*LogEntry) LogTrafficMetric

func (entry *LogEntry) LogTrafficMetric(responseTime int64, sent, received uint64, requestID int, method, params, trafficType, msg string)

LogTrafficMetric log traffic metric entry

func (*LogEntry) Logf

func (entry *LogEntry) Logf(level LogLevel, format string, args ...interface{})

Logf write formatted log entry to log

func (*LogEntry) SetActionEntry

func (entry *LogEntry) SetActionEntry(a *ActionEntry)

SetActionEntry set new session entry

func (*LogEntry) SetSessionEntry

func (entry *LogEntry) SetSessionEntry(s *SessionEntry)

SetSessionEntry set new session entry

func (*LogEntry) ShallowCopy

func (entry *LogEntry) ShallowCopy() *LogEntry

ShallowCopy log entry, creates new log entry with pointers to exact same data, but with a new mutex

func (*LogEntry) ShouldLogDebug

func (entry *LogEntry) ShouldLogDebug() bool

ShouldLogDebug should debug info be logged

func (*LogEntry) ShouldLogRegression added in v0.10.0

func (entry *LogEntry) ShouldLogRegression() bool

ShouldLogRegression should regression data be logged

func (*LogEntry) ShouldLogTraffic

func (entry *LogEntry) ShouldLogTraffic() bool

ShouldLogTraffic should traffic be logged

func (*LogEntry) ShouldLogTrafficMetrics

func (entry *LogEntry) ShouldLogTrafficMetrics() bool

ShouldLogTrafficMetrics should traffic metrics be logged

type LogLevel

type LogLevel int

LogLevel of logging

const (
	UnknownLevel LogLevel = iota
	ResultLevel
	ErrorLevel
	WarningLevel
	InfoLevel
	MetricsLevel
	TrafficLevel
	DebugLevel
)

When adding a new level also: * Add it to the String function * Add it in the StartLogger switch case if not to be logged on info level

func (LogLevel) String

func (l LogLevel) String() string

type LogSettings

type LogSettings struct {
	Traffic    bool
	Metrics    bool
	Debug      bool
	Regression bool
}

LogSettings settings

type Logger

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

Logger container for writer and close functions

func CreateDummyLogger

func CreateDummyLogger() *Logger

CreateDummyLogger auto discarding all entries

func CreateJSONLogger

func CreateJSONLogger(writer io.Writer, closeFunc func() error) *Logger

CreateJSONLogger with io.Writer

func CreateStdoutJSONLogger

func CreateStdoutJSONLogger() *Logger

CreateStdoutJSONLogger create logger for JSON on terminal for later adding to loggers list

func CreateStdoutLogger

func CreateStdoutLogger() *Logger

CreateStdoutLogger create logger for JSON on terminal for later adding to loggers list

func CreateTSVLogger

func CreateTSVLogger(header []string, writer io.Writer, closeFunc func() error) (*Logger, error)

CreateTSVLogger with io.Writer

func NewLogger

func NewLogger(w MsgWriter) *Logger

NewLogger instance

func (*Logger) AddCloseFunc

func (logger *Logger) AddCloseFunc(f func() error)

AddCloseFunc add sub logger close function to be called upon logger close

func (*Logger) Close

func (logger *Logger) Close() error

Close logger

type MsgWriter

type MsgWriter interface {
	// WriteMessage to log
	WriteMessage(msg *LogChanMsg) error
	// Set log level
	Level(lvl LogLevel)
}

MsgWriter implement to write log entry

type RegressionLogger added in v0.10.0

type RegressionLogger interface {
	Log(dataID string, data interface{}, meta map[string]interface{}) error
}

RegressionLogger logs data associated with unique ids, with optional meta data.

type RegressionLoggerCloser added in v0.10.0

type RegressionLoggerCloser interface {
	io.Closer
	RegressionLogger
}

RegressionLoggerCloser is a closable RegressionLogger, which is typically used when writing log to file.

func NewRegressionLogger added in v0.10.0

func NewRegressionLogger(w io.WriteCloser, headerEntries ...HeaderEntry) RegressionLoggerCloser

NewRegressionLogger creates a new RegressionLoggerCloser with headerEntries written in the header of the log.

type SessionEntry

type SessionEntry struct {
	User        string
	Thread      uint64
	Session     uint64
	SessionName string
	AppName     string
	AppGUID     string
}

SessionEntry log fields living of entire session

type TSVWriter

type TSVWriter struct {
	Out    io.Writer
	Header []string
	// contains filtered or unexported fields
}

TSVWriter write log rows in tab separated format

func NewTSVWriter

func NewTSVWriter(header []string, w io.Writer) *TSVWriter

NewTSVWriter instance

func (*TSVWriter) Level

func (writer *TSVWriter) Level(lvl LogLevel)

Level implement MsgWriter interface

func (*TSVWriter) WriteHeader

func (writer *TSVWriter) WriteHeader() error

WriteHeader to Out

func (*TSVWriter) WriteMessage

func (writer *TSVWriter) WriteMessage(msg *LogChanMsg) error

WriteMessage implement MsgWriter interface

type Writer

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

Writer simple implementation of a file writer

func NewWriter

func NewWriter(name string) (*Writer, error)

NewWriter create new instance of Writer

func (*Writer) Close

func (w *Writer) Close() error

Close writer

func (Writer) Write

func (w Writer) Write(p []byte) (int, error)

Write implement io.Writer interface

Jump to

Keyboard shortcuts

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