Documentation ¶
Index ¶
- Constants
- Variables
- type CachedLogger
- func (c *CachedLogger) Clear(ctx context.Context)
- func (c *CachedLogger) Configure(ctx context.Context, cfg *config.ConfigParams)
- func (c *CachedLogger) Dump(ctx context.Context) error
- func (c *CachedLogger) Update(ctx context.Context)
- func (c *CachedLogger) Write(ctx context.Context, level LevelType, err error, message string)
- type CompositeLogger
- type ConsoleLogger
- type ICachedLogSaver
- type ICachedLoggerOverrides
- type ILogger
- type ILoggerOverrides
- type LevelType
- type LogMessage
- type Logger
- func (c *Logger) ComposeError(err error) string
- func (c *Logger) Configure(ctx context.Context, cfg *config.ConfigParams)
- func (c *Logger) Debug(ctx context.Context, message string, args ...any)
- func (c *Logger) Error(ctx context.Context, err error, message string, args ...any)
- func (c *Logger) Fatal(ctx context.Context, err error, message string, args ...any)
- func (c *Logger) FormatAndWrite(ctx context.Context, level LevelType, err error, message string, args []any)
- func (c *Logger) Info(ctx context.Context, message string, args ...any)
- func (c *Logger) Level() LevelType
- func (c *Logger) Log(ctx context.Context, level LevelType, err error, message string, args ...any)
- func (c *Logger) SetLevel(value LevelType)
- func (c *Logger) SetReferences(ctx context.Context, references refer.IReferences)
- func (c *Logger) SetSource(value string)
- func (c *Logger) Source() string
- func (c *Logger) Trace(ctx context.Context, message string, args ...any)
- func (c *Logger) Warn(ctx context.Context, message string, args ...any)
- type NullLogger
- func (c *NullLogger) Debug(ctx context.Context, message string, args ...any)
- func (c *NullLogger) Error(ctx context.Context, err error, message string, args ...any)
- func (c *NullLogger) Fatal(ctx context.Context, err error, message string, args ...any)
- func (c *NullLogger) Info(ctx context.Context, message string, args ...any)
- func (c *NullLogger) Level() LevelType
- func (c *NullLogger) Log(ctx context.Context, level LevelType, err error, message string, args ...any)
- func (c *NullLogger) SetLevel(value LevelType)
- func (c *NullLogger) Trace(ctx context.Context, message string, args ...any)
- func (c *NullLogger) Warn(ctx context.Context, message string, args ...any)
Constants ¶
const ( DefaultMaxCacheSize = 100 DefaultInterval = 10000 ConfigParameterOptionsInterval = "options.interval" ConfigParameterOptionsMaxCacheSize = "options.max_cache_size" )
Variables ¶
var LevelConverter = &_TLogLevelConverter{}
LevelConverter Helper class to convert log level values.
Functions ¶
This section is empty.
Types ¶
type CachedLogger ¶
type CachedLogger struct { Logger Cache []LogMessage Updated bool LastDumpTime time.Time MaxCacheSize int Interval int Overrides ICachedLoggerOverrides // contains filtered or unexported fields }
func InheritCachedLogger ¶
func InheritCachedLogger(overrides ICachedLoggerOverrides) *CachedLogger
InheritCachedLogger creates a new instance of the logger from ICachedLogSaver
Parameters: - overrides ICachedLoggerOverrides Returns: CachedLogger
func (*CachedLogger) Clear ¶
func (c *CachedLogger) Clear(ctx context.Context)
Clear (removes) all cached log messages.
Parameters: - ctx context.Context
func (*CachedLogger) Configure ¶
func (c *CachedLogger) Configure(ctx context.Context, cfg *config.ConfigParams)
Configure configures component by passing configuration parameters.
Parameters: - ctx context.Context - config *config.ConfigParams configuration parameters to be set.
func (*CachedLogger) Dump ¶
func (c *CachedLogger) Dump(ctx context.Context) error
Dump (writes) the currently cached log messages.
Parameters: - ctx context.Context
func (*CachedLogger) Update ¶
func (c *CachedLogger) Update(ctx context.Context)
Update makes message cache as updated and dumps it when timeout expires.
Parameters: - ctx context.Context
func (*CachedLogger) Write ¶
Writes a log message to the logger destination. Parameters:
- ctx context.Context
- level LogLevel a log level.
- ctx context.Context execution context to trace execution through call chain.
- err error an error object associated with this message.
- message string a human-readable message to log.
type CompositeLogger ¶
type CompositeLogger struct { *Logger // contains filtered or unexported fields }
CompositeLogger aggregates all loggers from component references under a single component. It allows logging messages and conveniently send them to multiple destinations.
References: - *:logger:*:*:1.0 (optional) ILogger components to pass log messages see ILogger Example: type MyComponent { _logger CompositeLogger } func (mc* MyComponent) Configure(ctx context.Context, config ConfigParams) { mc._logger.Configure(ctx, config) ... } func (mc* MyComponent) SetReferences(ctx context.Context, references IReferences) { mc._logger.SetReferences(ctx, references) ... } func (mc* MyComponent) myMethod(ctx context.Context) { mc._logger.Debug(ctx context.Context, "Called method mycomponent.mymethod") ... } var mc MyComponent = MyComponent{} mc._logger = NewCompositeLogger()
func NewCompositeLogger ¶
func NewCompositeLogger() *CompositeLogger
NewCompositeLogger creates a new instance of the logger.
Returns: *CompositeLogger
func NewCompositeLoggerFromReferences ¶
func NewCompositeLoggerFromReferences(ctx context.Context, references refer.IReferences) *CompositeLogger
NewCompositeLoggerFromReferences creates a new instance of the logger.
Parameters: - ctx context.Context - refer.IReferences references to locate the component dependencies. Returns: CompositeLogger
func (*CompositeLogger) SetReferences ¶
func (c *CompositeLogger) SetReferences(ctx context.Context, references refer.IReferences)
SetReferences sets references to dependent components.
Parameters: - ctx context.Context - refer.IReferences references to locate the component dependencies.
func (*CompositeLogger) Write ¶
Writes a log message to the logger destination(s). Parameters:
- ctx context.Context
- level LogLevel a log level.
- ctx context.Context execution context to trace execution through call chain.
- err error an error object associated with this message.
- message string a human-readable message to log.
type ConsoleLogger ¶
type ConsoleLogger struct {
*Logger
}
ConsoleLogger is a logger that writes log messages to console. Errors are written to standard err stream and all other messages to standard out stream.
Configuration parameters: - level: maximum log level to capture - source: source (context) name References: - *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source see Logger Example: logger = NewConsoleLogger() logger.SetLevel(LogLevel.Debug) logger.Error(context.Background(), "123", ex, "Error occured: %s", ex.message) logger.Debug(context.Background(), "123", "Everything is OK.")
func NewConsoleLogger ¶
func NewConsoleLogger() *ConsoleLogger
NewConsoleLogger creates a new instance of the logger.
Returns: ConsoleLogger
func (*ConsoleLogger) Write ¶
Write a log message to the logger destination.
Parameters: - ctx context.Context - level LevelType a log level. - ctx context.Context execution context to trace execution through call chain. - err error an error object associated with this message. - message string a human-readable message to log.
type ICachedLogSaver ¶
type ICachedLogSaver interface {
Save(ctx context.Context, messages []LogMessage) error
}
ICachedLogSaver abstract logger that caches captured log messages in memory and periodically dumps them. Child classes implement saving cached messages to their specified destinations.
Configuration parameters - level: maximum log level to capture - source: source (context) name - options: - interval: interval in milliseconds to save log messages (default: 10 seconds) - max_cache_size: maximum number of messages stored in this cache (default: 100) References: - *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
type ICachedLoggerOverrides ¶
type ICachedLoggerOverrides interface { ILoggerOverrides Save(ctx context.Context, messages []LogMessage) error }
type ILogger ¶
type ILogger interface { // Level gets the maximum log level. Messages with higher log level are filtered out. Level() LevelType // SetLevel set the maximum log level. SetLevel(value LevelType) // Log logs a message at specified log level. Log(ctx context.Context, level LevelType, err error, message string, args ...any) // Fatal logs fatal (unrecoverable) message that caused the process to crash. Fatal(ctx context.Context, err error, message string, args ...any) // Error logs recoverable application error. Error(ctx context.Context, err error, message string, args ...any) // Warn logs a warning that may or may not have a negative impact. Warn(ctx context.Context, message string, args ...any) // Info logs an important information message Info(ctx context.Context, message string, args ...any) // Debug logs a high-level debug information for troubleshooting. Debug(ctx context.Context, message string, args ...any) // Trace logs a low-level debug information for troubleshooting. Trace(ctx context.Context, message string, args ...any) }
ILogger for logger components that capture execution log messages.
type ILoggerOverrides ¶
type ILoggerOverrides interface {
Write(ctx context.Context, level LevelType, err error, message string)
}
ILoggerOverrides abstract logger that captures and formats log messages. Child classes take the captured messages and write them to their specific destinations.
Configuration parameters to pass to the configure method for component configuration: - level: maximum log level to capture - source: source (context) name References: - *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
type LevelType ¶
type LevelType uint8
LevelType is a type to represent log level names
const ( LevelNone LevelType = 0 LevelFatal LevelType = 1 LevelError LevelType = 2 LevelWarn LevelType = 3 LevelInfo LevelType = 4 LevelDebug LevelType = 5 LevelTrace LevelType = 6 )
Standard log levels. Logs at debug and trace levels are usually captured only locally for troubleshooting and never sent to consolidated log services.
Log levels: - None = 0 Nothing to log - Fatal = 1 Log only fatal errors that cause processes to crash - Error = 2 Log all errors. - Warn = 3 Log errors and warnings - Info = 4 Log errors and important information messages - Debug = 5 Log everything except traces - Trace = 6 Log everything.
func (LevelType) MarshalJSON ¶
func (*LevelType) UnmarshalJSON ¶
type LogMessage ¶
type LogMessage struct { Time time.Time `json:"time"` Source string `json:"source"` Level LevelType `json:"level"` TraceId string `json:"trace_id"` Error errors.ErrorDescription `json:"error"` Message string `json:"message"` }
LogMessage Data object to store captured log messages. This object is used by CachedLogger.
func NewLogMessage ¶
func NewLogMessage(traceId string, level LevelType, source string, err errors.ErrorDescription, message string) LogMessage
NewLogMessage create new log message object
Parameters: - level LevelType a log level - source string a source - traceId string transaction id to trace execution through call chain. - err errors.ErrorDescription an error object associated with this message. - message string a human-readable message to log. Returns: LogMessage
type Logger ¶
type Logger struct { Overrides ILoggerOverrides // contains filtered or unexported fields }
func InheritLogger ¶
func InheritLogger(overrides ILoggerOverrides) *Logger
InheritLogger creates a new instance of the logger and inherit from ILogWriter.
Parameters: - overrides ILoggerOverrides Returns: *Logger
func (*Logger) ComposeError ¶
ComposeError composes an human-readable error description
Parameters: - err error an error to format. Returns string a human-readable error description.
func (*Logger) Configure ¶
func (c *Logger) Configure(ctx context.Context, cfg *config.ConfigParams)
Configure configures component by passing configuration parameters.
Parameters: - ctx context.Context execution context to trace execution through call chain. - config ConfigParams configuration parameters to be set.
func (*Logger) Debug ¶
Debug logs a high-level debug information for troubleshooting.
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*Logger) Error ¶
Logs recoverable application error.
Parameters: - ctx context.Context execution context to trace execution through call chain. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*Logger) Fatal ¶
Fatal logs fatal (unrecoverable) message that caused the process to crash.
Parameters: - ctx context.Context execution context to trace execution through call chain. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*Logger) FormatAndWrite ¶
func (c *Logger) FormatAndWrite(ctx context.Context, level LevelType, err error, message string, args []any)
FormatAndWrite formats the log message and writes it to the logger destination. Parameters:
- ctx context.Context execution context to trace execution through call chain.
- level LevelType a log level
- err error an error object associated with this message
- message string a human-readable message to log
- args []any arguments to parameterize the message
func (*Logger) Info ¶
Info logs an important information message
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*Logger) Level ¶
Level gets the maximum log level. Messages with higher log level are filtered out.
Returns int the maximum log level.
func (*Logger) Log ¶
Log a message at specified log level.
Parameters: - ctx context.Context execution context to trace execution through call chain. - level LevelType a log level. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*Logger) SetLevel ¶
SetLevel set the maximum log level.
Parameters: value int a new maximum log level.
func (*Logger) SetReferences ¶
func (c *Logger) SetReferences(ctx context.Context, references refer.IReferences)
SetReferences to dependent components.
Parameters: - ctx context.Context execution context to trace execution through call chain. - references IReferences references to locate the component dependencies.
func (*Logger) SetSource ¶
SetSource sets the source (context) name.
Parameters: value string a new source (context) name.
func (*Logger) Source ¶
Source gets the source (context) name.
Returns: string the source (context) name.
func (*Logger) Trace ¶
Trace logs a low-level debug information for troubleshooting.
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
type NullLogger ¶
type NullLogger struct{}
NullLogger dummy implementation of logger that doesn't do anything. It can be used in testing or in situations when logger is required but shall be disabled.
func NewNullLogger ¶
func NewNullLogger() *NullLogger
NewNullLogger creates a new instance of the logger.
Returns *NullLogger
func (*NullLogger) Debug ¶
func (c *NullLogger) Debug(ctx context.Context, message string, args ...any)
Debug logs a high-level debug information for troubleshooting.
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) Error ¶
Logs recoverable application error.
Parameters: - ctx context.Context execution context to trace execution through call chain. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) Fatal ¶
Fatal logs fatal (unrecoverable) message that caused the process to crash.
Parameters: - ctx context.Context execution context to trace execution through call chain. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) Info ¶
func (c *NullLogger) Info(ctx context.Context, message string, args ...any)
Info logs an important information message
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) Level ¶
func (c *NullLogger) Level() LevelType
Level gets the maximum log level. Messages with higher log level are filtered out.
Returns: LevelType the maximum log level.
func (*NullLogger) Log ¶
func (c *NullLogger) Log(ctx context.Context, level LevelType, err error, message string, args ...any)
Log a message at specified log level.
Parameters: - ctx context.Context execution context to trace execution through call chain. - level LevelType a log level. - err error an error object associated with this message. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) SetLevel ¶
func (c *NullLogger) SetLevel(value LevelType)
SetLevel set the maximum log level.
Parameters: - value int a new maximum log level.
func (*NullLogger) Trace ¶
func (c *NullLogger) Trace(ctx context.Context, message string, args ...any)
Trace logs a low-level debug information for troubleshooting.
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.
func (*NullLogger) Warn ¶
func (c *NullLogger) Warn(ctx context.Context, message string, args ...any)
Warn logs a warning that may or may not have a negative impact.
Parameters: - ctx context.Context execution context to trace execution through call chain. - message string a human-readable message to log. - args ...any arguments to parameterize the message.