Documentation ¶
Index ¶
- Constants
- func FormatParamsAsJSON(params map[string]interface{}) string
- func FormatParamsAsKeyValue(params map[string]interface{}) string
- type LogLevel
- type LogMessage
- type LogOption
- type Logger
- func (l *Logger) Close()
- func (l *Logger) Debug(message string, opts ...LogOption)
- func (l *Logger) Error(message string, opts ...LogOption)
- func (l *Logger) Fatal(message string, opts ...LogOption)
- func (l *Logger) Info(message string, opts ...LogOption)
- func (l *Logger) Trace(message string, opts ...LogOption)
- func (l *Logger) Warning(message string, opts ...LogOption)
- type LoggerOption
- func EnableConsoleOutput(enable bool) LoggerOption
- func EnableFileOutput(enable bool) LoggerOption
- func EnableSourceInfo(enable bool) LoggerOption
- func SetBufferSize(size int) LoggerOption
- func SetConsoleLevel(level LogLevel) LoggerOption
- func SetDefaultFileName(fileName string) LoggerOption
- func SetFileLevel(level LogLevel) LoggerOption
- func SetMaxFileHandles(maxHandles int) LoggerOption
- func SetParamFormatter(formatter ParamFormatter) LoggerOption
- type ParamFormatter
Constants ¶
const ( LogLevelTrace LogLevel = iota LogLevelDebug LogLevelInfo LogLevelWarning LogLevelError LogLevelFatal // DefaultBufferSize is the default size of the log message channel. DefaultBufferSize = 100 // DefaultFileName is the default name for log files. DefaultFileName = "default.log" // DefaultMaxFileHandles is the default maximum number of file handles. DefaultMaxFileHandles = 10 // DefaultUnusedFileHandleThreshold is the threshold for cleaning up unused file handles. DefaultUnusedFileHandleThreshold = 30 * time.Minute // DefaultCleanupTicker is the interval for the cleanup routine. DefaultCleanupTicker = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func FormatParamsAsJSON ¶
FormatParamsAsJSON formats parameters as a JSON string.
func FormatParamsAsKeyValue ¶
FormatParamsAsKeyValue formats parameters as key-value pairs.
Types ¶
type LogMessage ¶
type LogMessage struct { Level LogLevel // Log level of the message (e.g., DEBUG, INFO, etc.) Message string // The actual log message FileMessage string // Formatted message for file output ConsoleMessage string // Formatted message for console output File string // The target log file Params map[string]interface{} // Additional parameters for the log message }
LogMessage represents a log message with its level, content, and additional parameters.
type LogOption ¶
type LogOption func(*LogMessage)
LogOption defines a function type for log message configuration.
func SetLogFile ¶
SetLogFile specifies the log file for a log message. This function is used to set a custom log file for individual log messages.
func SetLogParams ¶
SetLogParams specifies additional parameters for a log message. This function allows adding key-value pairs that provide additional information for the log message.
type Logger ¶
type Logger struct { LogChannel chan LogMessage // Channel for log messages. FileLevel LogLevel // Minimum level of messages to log to file. ConsoleLevel LogLevel // Minimum level of messages to log to console. DefaultFileName string // Default log file name. OutputToFile bool // Flag to enable or disable file output. OutputToConsole bool // Flag to enable or disable console output. AddSource bool // Flag to add source file info in logs. // contains filtered or unexported fields }
Logger represents an asynchronous logger.
func NewLogger ¶
func NewLogger(opts ...LoggerOption) (*Logger, error)
NewLogger creates a new Logger with specified options. opts are functional options to configure the Logger.
type LoggerOption ¶
LoggerOption defines a function type for logger configuration options.
func EnableConsoleOutput ¶
func EnableConsoleOutput(enable bool) LoggerOption
EnableConsoleOutput enables or disables console output.
func EnableFileOutput ¶
func EnableFileOutput(enable bool) LoggerOption
EnableFileOutput enables or disables file output.
func EnableSourceInfo ¶
func EnableSourceInfo(enable bool) LoggerOption
EnableSourceInfo enables or disables the logging of source file information.
func SetBufferSize ¶ added in v1.0.2
func SetBufferSize(size int) LoggerOption
SetBufferSize sets the size of the log message channel.
func SetConsoleLevel ¶
func SetConsoleLevel(level LogLevel) LoggerOption
SetConsoleLevel sets the console log level.
func SetDefaultFileName ¶
func SetDefaultFileName(fileName string) LoggerOption
SetDefaultFileName sets the default log file name.
func SetFileLevel ¶
func SetFileLevel(level LogLevel) LoggerOption
SetFileLevel sets the file log level.
func SetMaxFileHandles ¶
func SetMaxFileHandles(maxHandles int) LoggerOption
SetMaxFileHandles sets the maximum number of file handles.
func SetParamFormatter ¶
func SetParamFormatter(formatter ParamFormatter) LoggerOption
SetParamFormatter sets the parameter formatting strategy for the logger.
type ParamFormatter ¶
ParamFormatter is a function type for formatting log parameters.