logger

package
v0.0.0-...-1d97044 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 11 Imported by: 0

README

logger

Levels

The following table defines the log levels and messages in logger, in decreasing order of severity. The left column lists the log level designation in and the right column provides a brief description of each log level.

Level Description
Fatal Severe errors that cause premature termination.
Expect these to be immediately visible on a status console.
Error Other runtime errors or unexpected conditions.
Expect these to be immediately visible on a status console.
Critical
Warn Use of deprecated APIs, poor use of APIConfig, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong".
Expect these to be immediately visible on a status console.
Info Interesting runtime events (startup/shutdown).
Expect these to be immediately visible on a console, so be conservative and keep to a minimum.
Debug Detailed information on the flow through the system.
Expect these to be written to logs only.
Trace Most detailed information.
Expect these to be written to logs only.

Colors

The supported keys in the :colors keyword list are:

Level Color
Fatal Defaults to: Red
Error Defaults to: Red
Critical Defaults to: LightRed
Warn Defaults to: Yellow
Info Defaults to: Green
Debug Defaults to: Blue
Trace Defaults to: Magenta

See the IO.ANSI module for a list of colors and attributes.

For example, info takes precedence over debug. If your log level is set to info, info, warn, and error will be printed to the console. If your log level is set to warn, only warn and error will be printed.

Types

Type Format
Text %[levelName]s:%[name]s:%[message]s%[fields]s\n
Apache Common {host} {userIdentifier} {authUserId} [{datetime}] "{method} {request} HTTP/1.0" {responseCode} {bytes}
Apache Combined %[host]s - %[user]s %[authUserId]d [%[ASC_TIME]s] "%[method]s %[request]s HTTP/1.0" %[responseCode]d %[bytes]d "%[referrer]s" "%[agent]s"
Apache Error [{timestamp}] [{module}:{severity}] [pid {pid}:tid {threadID}] [client: %{client}] %{message}
RFC3164 {timestamp} {hostname} {application}[{pid}]: {message}
RFC5424 {version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message}
Common Log File Format %[host]s - %[user]s %[authUserId]d [%[ASC_TIME]s] "%[method]s %[request]s HTTP/1.0" %[responseCode]d %[bytes]d

Metadata

In addition to the keys provided by the user via logger.metadata/1, the following extra keys are available to the :metadata list:

Name Description
host
application The current application
module The current module
function The current function
file The current file
line The current line
pid The current process identifier
threadID
user
authUserId
method
request
responseCode
bytes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func IsEnable

func IsEnable() bool

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicln

func Panicln(args ...interface{})

func RegisterLogger

func RegisterLogger(t LogFormatterType, l *Logger) *errorAVA.Error

func Serializer

func Serializer(t serializerAVA.SerializerType) ([]byte, *errorAVA.Error)

func SetEnable

func SetEnable()

func SetFormat

func SetFormat(logFormatterType LogFormatterType) *errorAVA.Error

func SetLevel

func SetLevel(levelType LogLevelType) *errorAVA.Error

func SetOutputConsole

func SetOutputConsole(output io.Writer)

func SetOutputFile

func SetOutputFile(filename string,
	maxSize int,
	maxBackups int,
	maxAge int,
	compress bool)

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(format string, args ...interface{})

func Traceln

func Traceln(args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warnln

func Warnln(args ...interface{})

func With

func With(key string, value interface{})

func WithFields

func WithFields(fields logrus.Fields) *logrus.Entry

Types

type LogFormatterType

type LogFormatterType int32

LogFormatterType x ENUM( Text JSON ApacheCommonLog ApacheCombinedLog ApacheErrorLog RFC3164Log RFC5424Log CommonLogFileFormat Unknown )

const (
	// LogFormatterTypeText is a LogFormatterType of type Text
	LogFormatterTypeText LogFormatterType = iota
	// LogFormatterTypeJSON is a LogFormatterType of type JSON
	LogFormatterTypeJSON
	// LogFormatterTypeApacheCommonLog is a LogFormatterType of type ApacheCommonLog
	LogFormatterTypeApacheCommonLog
	// LogFormatterTypeApacheCombinedLog is a LogFormatterType of type ApacheCombinedLog
	LogFormatterTypeApacheCombinedLog
	// LogFormatterTypeApacheErrorLog is a LogFormatterType of type ApacheErrorLog
	LogFormatterTypeApacheErrorLog
	// LogFormatterTypeRFC3164Log is a LogFormatterType of type RFC3164Log
	LogFormatterTypeRFC3164Log
	// LogFormatterTypeRFC5424Log is a LogFormatterType of type RFC5424Log
	LogFormatterTypeRFC5424Log
	// LogFormatterTypeCommonLogFileFormat is a LogFormatterType of type CommonLogFileFormat
	LogFormatterTypeCommonLogFileFormat
	// LogFormatterTypeUnknown is a LogFormatterType of type Unknown
	LogFormatterTypeUnknown
)

func GetFormat

func GetFormat() LogFormatterType

func ParseLogFormatterType

func ParseLogFormatterType(name string) (LogFormatterType, *errorAVA.Error)

ParseLogFormatterType attempts to convert a string to a LogFormatterType

func (LogFormatterType) MarshalText

func (x LogFormatterType) MarshalText() ([]byte, *errorAVA.Error)

MarshalText implements the text marshaller method

func (LogFormatterType) String

func (x LogFormatterType) String() string

String implements the Stringer interface.

func (LogFormatterType) UnmarshalText

func (x LogFormatterType) UnmarshalText(text []byte) (LogFormatterType, *errorAVA.Error)

UnmarshalText implements the text unmarshaller method

type LogLevelType

type LogLevelType uint32

LogLevelType x ENUM( Panic // Panic level, highest level of severity. Logs and then calls panic with the message passed to debug, info, ... Fatal // Fatal level. Logs and then calls `logger.Exit(1)`. It will exit even if the logging level is set to Panic. Error // Error level. Logs. Used for errors that should definitely be noted. Warn // Warn level. Non-critical entries that deserve eyes. Info // Info level. General operational entries about what's going on inside the application. Debug // Debug level. Usually only enabled when debugging. Very verbose logging. Trace // Trace level. Designates finer-grained informational events than the debug. Unknown )

const (
	// LogLevelTypePanic is a LogLevelType of type Panic
	// Panic level, highest level of severity. Logs and then calls panic with the message passed to debug, info, ...
	LogLevelTypePanic LogLevelType = iota
	// LogLevelTypeFatal is a LogLevelType of type Fatal
	// Fatal level. Logs and then calls `logger.Exit(1)`. It will exit even if the logging level is set to Panic.
	LogLevelTypeFatal
	// LogLevelTypeError is a LogLevelType of type Error
	// Error level. Logs. Used for errors that should definitely be noted.
	LogLevelTypeError
	// LogLevelTypeWarn is a LogLevelType of type Warn
	// Warn level. Non-critical entries that deserve eyes.
	LogLevelTypeWarn
	// LogLevelTypeInfo is a LogLevelType of type Info
	// Info level. General operational entries about what's going on inside the application.
	LogLevelTypeInfo
	// LogLevelTypeDebug is a LogLevelType of type Debug
	// Debug level. Usually only enabled when debugging. Very verbose logging.
	LogLevelTypeDebug
	// LogLevelTypeTrace is a LogLevelType of type Trace
	// Trace level. Designates finer-grained informational events than the debug.
	LogLevelTypeTrace
	// LogLevelTypeUnknown is a LogLevelType of type Unknown
	LogLevelTypeUnknown
)

func GetLevel

func GetLevel() LogLevelType

func ParseLogLevelType

func ParseLogLevelType(name string) (LogLevelType, *errorAVA.Error)

ParseLogLevelType attempts to convert a string to a LogLevelType

func (LogLevelType) MarshalText

func (x LogLevelType) MarshalText() ([]byte, *errorAVA.Error)

MarshalText implements the text marshaller method

func (LogLevelType) String

func (x LogLevelType) String() string

String implements the Stringer interface.

func (LogLevelType) UnmarshalText

func (x LogLevelType) UnmarshalText(text []byte) (LogLevelType, *errorAVA.Error)

UnmarshalText implements the text unmarshaller method

type Logger

type Logger struct {
	Enable bool

	Level     LogLevelType
	Formatter LogFormatterType

	Output struct {
		Console bool
		File    bool
	}

	File *lumberjack.Logger

	Log *logrus.Logger

	Mux sync.Mutex
}

func GetInstance

func GetInstance() *Logger

func UseLogger

func UseLogger(t LogFormatterType) (*Logger, *errorAVA.Error)

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

debug logs a message at level debug on the standard logger.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs a message at level debug on the standard logger.

func (*Logger) Debugln

func (l *Logger) Debugln(args ...interface{})

debug logs a message at level debug on the standard logger.

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

err logs a message at level err on the standard logger.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs a message at level err on the standard logger.

func (*Logger) Errorln

func (l *Logger) Errorln(args ...interface{})

err logs a message at level err on the standard logger.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf logs a message at level Fatal on the standard logger.

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func (*Logger) GetFormat

func (l *Logger) GetFormat() LogFormatterType

func (*Logger) GetLevel

func (l *Logger) GetLevel() LogLevelType

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

info logs a message at level info on the standard logger.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs a message at level info on the standard logger.

func (*Logger) Infoln

func (l *Logger) Infoln(args ...interface{})

info logs a message at level info on the standard logger.

func (*Logger) IsDisableColors

func (l *Logger) IsDisableColors() bool

func (*Logger) IsEnable

func (l *Logger) IsEnable() bool

func (*Logger) IsForceColors

func (l *Logger) IsForceColors() bool

func (*Logger) IsValid

func (l *Logger) IsValid() *errorAVA.Error

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{})

Panicf logs a message at level Panic on the standard logger.

func (*Logger) Panicln

func (l *Logger) Panicln(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func (*Logger) Reset

func (l *Logger) Reset()

func (*Logger) Serializer

func (l *Logger) Serializer(t serializerAVA.SerializerType) ([]byte, *errorAVA.Error)

func (*Logger) SetEnable

func (l *Logger) SetEnable()

func (*Logger) SetFormat

func (l *Logger) SetFormat(logFormatterType LogFormatterType) *errorAVA.Error

func (*Logger) SetLevel

func (l *Logger) SetLevel(levelType LogLevelType) *errorAVA.Error

func (*Logger) SetOutputConsole

func (l *Logger) SetOutputConsole(output io.Writer)

SetOutput sets the logger output.

func (*Logger) SetOutputFile

func (l *Logger) SetOutputFile(filename string,
	maxSize int,
	maxBackups int,
	maxAge int,
	compress bool)

SetOutput sets the logger output.

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...interface{})

func (*Logger) Traceln

func (l *Logger) Traceln(args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func (*Logger) Warnln

func (l *Logger) Warnln(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func (*Logger) With

func (l *Logger) With(key string, value interface{}) LoggerI

func (*Logger) WithFields

func (l *Logger) WithFields(fields logrus.Fields) *logrus.Entry

WithFields takes into consideration the fields

type LoggerI

type LoggerI interface {
	Debug(...interface{})
	Debugln(...interface{})
	Debugf(string, ...interface{})

	Trace(...interface{})
	Traceln(...interface{})
	Tracef(string, ...interface{})

	Info(...interface{})
	Infoln(...interface{})
	Infof(string, ...interface{})

	Warn(...interface{})
	Warnln(...interface{})
	Warnf(string, ...interface{})

	Error(...interface{})
	Errorln(...interface{})
	Errorf(string, ...interface{})

	Fatal(...interface{})
	Fatalln(...interface{})
	Fatalf(string, ...interface{})

	Panic(...interface{})
	Panicln(...interface{})
	Panicf(format string, args ...interface{})

	WithFields(logrus.Fields) *logrus.Entry

	With(key string, value interface{}) LoggerI

	SetOutputConsole(output io.Writer)
	SetOutputFile(filename string, maxSize int, maxBackups int, maxAge int, compress bool)

	SetFormat(logFormatterType LogFormatterType) *errorAVA.Error
	GetFormat() LogFormatterType

	IsEnable() bool
	SetEnable()

	SetLevel(levelType LogLevelType) *errorAVA.Error
	GetLevel() LogLevelType

	Reset()

	IsDisableColors() bool
	IsForceColors() bool

	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

logger is the interface for loggers used in the AVA components.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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