Documentation
¶
Index ¶
- Variables
- func AnyToJSONBytes(data any) ([]byte, error)
- func AnyToJSONString(data ...any) string
- func Println(messages ...any)
- func PrintlnBoard(messages ...any)
- func PrintlnJSON(messages ...any)
- func SetDefaultLogOpts(opts LogOpts)
- type ANSICode
- type CtxLogger
- func (cl *CtxLogger) Debug(messages ...any)
- func (cl *CtxLogger) Debugf(format string, params ...any)
- func (cl *CtxLogger) Error(messages ...any)
- func (cl *CtxLogger) Errorf(format string, params ...any)
- func (cl *CtxLogger) Fatal(messages ...any)
- func (cl *CtxLogger) Fatalf(format string, params ...any)
- func (cl *CtxLogger) Info(messages ...any)
- func (cl *CtxLogger) Infof(format string, params ...any)
- func (cl *CtxLogger) Log(ansicode ANSICode, severity LogSeverity, messages ...any)
- func (cl *CtxLogger) Logf(ansicode ANSICode, severity LogSeverity, format string, params ...any)
- func (cl *CtxLogger) Trace(messages ...any)
- func (cl *CtxLogger) Tracef(format string, params ...any)
- func (cl *CtxLogger) Warn(messages ...any)
- func (cl *CtxLogger) Warnf(format string, params ...any)
- type CtxLoggerFactoryFn
- type DebugLogger
- type ErrorLogger
- type ExtraData
- type GetExtraDataFunc
- type ILogger
- type InfoLogger
- type LogLevel
- type LogLevelCfg
- type LogLevelOpts
- type LogMessage
- type LogOpts
- type LogSeverity
- type LoggerFactoryFn
Constants ¶
This section is empty.
Variables ¶
var ( ANSICodeCyan = ANSICode("\033[36m") ANSICodeLightGreen = ANSICode("\033[92m") ANSICodeOrange = ANSICode("\033[33m") ANSICodeRed = ANSICode("\033[31m") ANSICodeLightBlue = ANSICode("\033[94m") ANSICodeGray = ANSICode("\033[90m") ANSICodeBrightYellow = ANSICode("\033[93m") ANSICodeMagenta = ANSICode("\033[35m") ANSICodeReset = ANSICode("\033[0m") )
ANSICodes for colored and formatted output.
Functions ¶
func AnyToJSONBytes ¶
AnyToJSONString converts data to a JSON byte array. It supports converting a large variety of data types.
Parameters:
- data: The data to convert to JSON.
Returns:
- string: A JSON string representation of the data.
- error: An error if the data cannot be converted.
func AnyToJSONString ¶
AnyToJSONString converts data to a JSON string. It supports converting a large variety of data types. It will panic if the data cannot be converted.
Parameters:
- data: The data to convert to JSON.
Returns:
- string: A JSON string representation of the data.
func Println ¶
func Println(messages ...any)
Println formats and prints a debug colored message into stdout.
Parameters:
- messages The messages to print.
func PrintlnBoard ¶
func PrintlnBoard(messages ...any)
PrintlnBoard formats and prints a debug colored message into stdout with visible signage.
Parameters:
- messages The messages to print.
func PrintlnJSON ¶
func PrintlnJSON(messages ...any)
PrintlnJSON formats and prints a debug colored JSON message into stdout.
Parameters:
- messages The messages to print.
func SetDefaultLogOpts ¶
func SetDefaultLogOpts(opts LogOpts)
SetDefaultLogOpts overrides the the default logging configuration.
Types ¶
type CtxLogger ¶
type CtxLogger struct {
// contains filtered or unexported fields
}
CtxLogger is a logger that takes a context.
func NewCtxLogger ¶
NewCtxLogger constructs a logger, using the package-level default options if none are passed in.
Parameters:
- ctx The context to use.
- opts The optional options to use. If nil, the default options are used.
Returns:
- *ContextLogger: The logger.
func (*CtxLogger) Debug ¶
Debug prints a debug message. It will always print.
Parameters:
- messages The messages to print.
func (*CtxLogger) Debugf ¶
Debugf formats and prints a debug message. It will always print.
Parameters:
- format The format string.
- params The parameters to format.
func (*CtxLogger) Error ¶
Error prints an error message if the logging level is high enough.
Parameters:
- messages The messages to print.
func (*CtxLogger) Errorf ¶
Errorf formats and prints an error message if the logging level is high enough.
Parameters:
- format The format string.
- params The parameters to format.
func (*CtxLogger) Fatal ¶
Fatal prints a fatal message if the logging level is high enough.
Parameters:
- messages The messages to print.
func (*CtxLogger) Fatalf ¶
Fatalf formats and prints a fatal message if the logging level is high enough.
Parameters:
- format The format string.
- params The parameters to format.
func (*CtxLogger) Info ¶
Info prints an info message if the logging level is high enough.
Parameters:
- messages The messages to print.
func (*CtxLogger) Infof ¶
Infof formats and prints an info message if the logging level is high enough.
Parameters:
- format The format string.
- params The parameters to format.
func (*CtxLogger) Log ¶
func (cl *CtxLogger) Log( ansicode ANSICode, severity LogSeverity, messages ...any, )
Log prints a message with custom ANSI code and severity. It will always print.
Parameters:
- ansicode The ANSI code to use.
- severity The severity of the message.
- messages The messages to print.
func (*CtxLogger) Logf ¶
func (cl *CtxLogger) Logf( ansicode ANSICode, severity LogSeverity, format string, params ...any, )
Logf formats and prints a message. It will always print.
func (*CtxLogger) Trace ¶
Trace prints a trace message if the logging level is high enough.
Parameters:
- messages The messages to print.
func (*CtxLogger) Tracef ¶
Tracef formats and prints a trace message if the logging level is high enough.
Parameters:
- format The format string.
- params The parameters to format.
type CtxLoggerFactoryFn ¶
CtxLoggerFactoryFn is a function that returns a logger with context.
type DebugLogger ¶
type DebugLogger interface {
Debug(messages ...any)
Debugf(message string, params ...any)
Trace(messages ...any)
Tracef(message string, params ...any)
}
DebugLogger defines debug and trace level logging.
type ErrorLogger ¶
type ErrorLogger interface {
Error(messages ...any)
Errorf(message string, params ...any)
Fatal(messages ...any)
Fatalf(message string, params ...any)
}
ErrorLogger defines error and fatal level logging.
type ExtraData ¶
type ExtraData struct {
Time *time.Time `json:"time,omitempty"`
TimeStart *time.Time `json:"time_start,omitempty"`
TimeDelta string `json:"time_delta,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
}
ExtraData contains request metadata.
type GetExtraDataFunc ¶
GetExtraDataFunc is a function that returns extra data for logging.
type ILogger ¶
type ILogger interface {
DebugLogger
InfoLogger
ErrorLogger
}
ILogger represents a logger with different logging levels.
type InfoLogger ¶
type InfoLogger interface {
Info(messages ...any)
Infof(message string, params ...any)
Warn(messages ...any)
Warnf(message string, params ...any)
}
InfoLogger defines info and warning level logging.
type LogLevel ¶
type LogLevel int
LogLevel represents the level of a log message.
func LoggingLevelStrToInt ¶
LoggingLevelStrToInt converts a string to a logging level integer. The string is trimmed and converted to uppercase. If the string is empty, the default logging level is returned. If the string is a valid integer, it is returned as the logging level. If the string is one of the predefined strings, the corresponding logging level is returned.
Parameters:
- level The string to convert.
Returns:
- int: The logging level integer.
- error: An error if the conversion fails.
type LogLevelCfg ¶
type LogLevelCfg struct {
Level LogLevel
Severity LogSeverity
Color ANSICode
Writer io.Writer
Callback func(data []byte)
}
LogLevelCfg holds logging level configuration.
type LogLevelOpts ¶
type LogLevelOpts struct {
Debug *LogLevelCfg
Trace *LogLevelCfg
Info *LogLevelCfg
Warn *LogLevelCfg
Error *LogLevelCfg
Fatal *LogLevelCfg
}
LogLevelOpts holds logging level options.
func DefaultLogLevelOpts ¶
func DefaultLogLevelOpts() *LogLevelOpts
DefaultLogLevelOpts returns the package-wide fallback log level settings.
type LogMessage ¶
type LogMessage struct {
Severity LogSeverity `json:"severity"`
Message any `json:"message"`
Data any `json:"data,omitempty"`
Extra any `json:"extra,omitempty"`
}
LogMessage represents a log message.
func NewLogMessage ¶
func NewLogMessage( severity LogSeverity, message any, data any, extra any, ) LogMessage
NewLogMessage creates a new LogMessage.
Parameters:
- severity: The severity of the message.
- message: The message to log.
- data: The data to log.
- extra: The extra data to log.
Returns:
- LogMessage: The new LogMessage.
type LogOpts ¶
type LogOpts struct {
LoggingLevel LogLevel
Compact bool
AnsiCodes bool
GetExtraData GetExtraDataFunc
LogLevelOpts *LogLevelOpts
}
LogOpts holds shared logger configuration.
func DefaultLogOpts ¶
func DefaultLogOpts() *LogOpts
DefaultLogOpts returns the package-wide fallback settings.
type LoggerFactoryFn ¶
LoggerFactoryFn is a function that returns a logger.