Documentation ¶
Overview ¶
Package log implements modules for logging.
Index ¶
- type AuditLogWriter
- type ChanneledLogMux
- type Config
- type DefaultLogMux
- type Log
- type Logger
- func (l *Logger) AddLogWriter(ctx context.Context, w logwriter.LogWriter)
- func (l *Logger) Audit(ctx context.Context, msg interface{}) error
- func (l *Logger) Debug(ctx context.Context, message string, logObject ...interface{})
- func (l *Logger) Emergency(ctx context.Context, message string, err error, logObject ...interface{})
- func (l *Logger) Error(ctx context.Context, message string, logObject ...interface{})
- func (l *Logger) Fatal(ctx context.Context, message string, exitCode int, logObject ...interface{})
- func (l *Logger) GetLogLevel() m.LogLevel
- func (l *Logger) Info(ctx context.Context, message string, logObject ...interface{})
- func (l *Logger) NewResourceLogger(resourceName string) Log
- func (l *Logger) Notice(ctx context.Context, message string, logObject ...interface{})
- func (l *Logger) SetModuleName(moduleName string)
- func (l *Logger) Trace(ctx context.Context, message string, logObject ...interface{})
- func (l *Logger) Warning(ctx context.Context, message string, logObject ...interface{})
- type Mux
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditLogWriter ¶
type ChanneledLogMux ¶
type ChanneledLogMux struct {
// contains filtered or unexported fields
}
func NewChanneledLogMux ¶
func NewChanneledLogMux(bufferSize uint8, logWriterList ...logwriter.ChanneledLogWriter) *ChanneledLogMux
func (*ChanneledLogMux) Print ¶
func (ls *ChanneledLogMux) Print(ctx context.Context, msg *m.LogMessage)
type Config ¶
type Config struct { ServiceName string // ServiceName represents the name of the service. ModuleName string // ModuleName represents the name of the module. LogLevel message.LogLevel // LogLevel represents the log level. Mux Mux // Mux represents the multiplexer for handling log messages. FileTrace bool // FileTrace indicates whether file tracing is enabled. Audit AuditLogWriter // Audit represents the audit log writer. }
Config represents the configuration options for the logger.
func GetDefaultConfig ¶
func GetDefaultConfig() Config
GetDefaultConfig returns the new Config with values from environment variables or default values.
Environment Variables - SERVICE_NAME: Sets [ServiceName] - LOG__LEVEL: Sets [LogLevel], following are the valid options - TRACE - DEBUG - INFO - NOTICE - WARNING - ERROR - CRITICAL - EMERGENCY - LOG__FILE_TRACE: Sets [FileTrace] - LOG__WRITER: Sets the log writer for [Mux], supports following values by default, can be extended - CONSOLE - JSONL
For custom [LOG__WRITER] use logwriter.AddLogWriter before the package initialization
type DefaultLogMux ¶
type DefaultLogMux struct {
// contains filtered or unexported fields
}
DefaultLogMux is a implementation of LogMux and calls the associated log handlers sequentially over a for loop
func NewDefaultLogMux ¶
func NewDefaultLogMux(logWriterList ...logwriter.LogWriter) *DefaultLogMux
func (*DefaultLogMux) AddLogWriter ¶
func (ls *DefaultLogMux) AddLogWriter(ctx context.Context, writer logwriter.LogWriter)
func (*DefaultLogMux) Print ¶
func (ls *DefaultLogMux) Print(ctx context.Context, msg *m.LogMessage)
type Log ¶
type Log interface { // NewResourceLogger creates a new logger instance with the specified resource name. NewResourceLogger(resourceName string) Log // Audit logs an audit message. Audit(ctx context.Context, msg interface{}) error // Trace logs a trace-level message. Trace(ctx context.Context, message string, logObject ...interface{}) // Debug logs a debug-level message. Debug(ctx context.Context, message string, logObject ...interface{}) // Info logs an info-level message. Info(ctx context.Context, message string, logObject ...interface{}) // Notice logs a notice-level message. Notice(ctx context.Context, message string, logObject ...interface{}) // Warning logs a warning-level message. Warning(ctx context.Context, message string, logObject ...interface{}) // Error logs an error-level message. Error(ctx context.Context, message string, logObject ...interface{}) // Emergency logs an emergency-level message and includes an error. Emergency(ctx context.Context, message string, err error, logObject ...interface{}) // Fatal logs a fatal-level message and exits the program with the specified exit code. Fatal(ctx context.Context, message string, exitCode int, logObject ...interface{}) // GetLogLevel returns the current log level of the logger. GetLogLevel() message.LogLevel // AddLogWriter adds a new log writer to the logger. AddLogWriter(context.Context, logwriter.LogWriter) }
Log defines the interface for logging used throughout the package.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) AddLogWriter ¶
AddLogWriter adds a log writer to the logger.
func (*Logger) Emergency ¶
func (l *Logger) Emergency(ctx context.Context, message string, err error, logObject ...interface{})
Emergency logs a message with EMERGENCY level.
func (*Logger) Fatal ¶
Fatal logs a message with FATAL level and exits the program with the specified exit code.
func (*Logger) GetLogLevel ¶
GetLogLevel returns the current log level.
func (*Logger) NewResourceLogger ¶
NewResourceLogger creates a new Logger instance with the specified resource name.
func (*Logger) SetModuleName ¶
SetModuleName sets the module name for the logger.
type Mux ¶
type Mux interface { Print(context.Context, *m.LogMessage) AddLogWriter(context.Context, logwriter.LogWriter) }
Mux interface abstracts how the logger interacts with the the log handlers
type Option ¶
type Option func(*Config)
Option represents an option function for configuring the logger.
func WithAudit ¶
func WithAudit(audit AuditLogWriter) Option
WithAudit sets the audit log writer for the logger.
func WithFileTrace ¶
WithFileTrace sets the file trace flag for the logger.
func WithLogLevelName ¶
WithLogLevelName sets the log level name for the logger.
func WithModuleName ¶
WithModuleName sets the module name for the logger.
func WithServiceName ¶
WithServiceName sets the service name for the logger.