Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Std = New(LevelInfo)
Default Logger variable named "Std" creates a shared logger at "Info" threshold writing to os.Stdout — sensible defaults for most use cases. API design — two layers instance API + convenience API.
Can be replaced for testing or custom configuration.
Functions ¶
Types ¶
type JSONFormatter ¶
type JSONFormatter struct{}
type JSON Formatter formats log entries as JSON objects
type Level ¶
type Level byte
Level represents an available logging level
const ( /* LevelDebug represents the lowest level of log, mostly used for debugging purposes */ LevelDebug Level = iota /* LevelInfo represents the logging level for valuable insights. */ LevelInfo /* LevelError represents the highest logging level for tracing errors. */ LevelWarning /* LevelWarning represents the logging level for tracing warnings.*/ LevelError )
type LogEntry ¶
type LogEntry struct {
Time time.Time `json:"time"`
/* Raw time, formatters decide format */
Level Level `json:"level"`
Message string `json:"message"`
File string `json:"file"`
Line int `json:"line"`
}
Fields like threshold and output start with lowercase letters so they remain unexported (private). Users will interact with them only through the "New" function and methods like "Debugf", "Infof",etc.
"LogEntry" is the exported structure of the log entry to represent the log message in JSON format. It's fields are still controlled by the logger. LogEntry contains all information about a log event. It is passed by value to formatters; fields are exported for marshalling.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is used to log information about the program's execution. It is thread-safe and can be used concurrently. It is also configurable and can be used to log to different outputs and with different formats. It is also used to log at different levels of severity. Users can create multiple loggers with different configurations.
func New ¶
"New" function returns a logger ready to log at the required threshold.
"New" accepts optional configuration functions.
func (*Logger) Debugf ¶
"Debugf" method formats and prints a message if the log level is "Debug" or higher.
func (*Logger) Infof ¶
"Infof" method formats and prints a message if the lig level is "Info" or higher.
type Option ¶
type Option func(*Logger)
Option defines a functional option for the logger
func WithFormatter ¶
func WithOutput ¶
WithOutPut return a confirmation function that sets the output of logs.
type TextFormatter ¶
type TextFormatter struct{}
TextFormatter formats log entries as human readable plain text