Documentation ¶
Overview ¶
Package logwriter provides interfaces for writing log messages.
Package logwriter contains the log handler implementations
Index ¶
- Constants
- func AddLogWriter(name string, l LogWriter) error
- func DefaultLogMapper(ctx context.Context, msg *message.LogMessage) map[string]interface{}
- func GetLogObjectType(logObj []any) string
- func GetObjectType(obj any) string
- func ParseLogObject(logObj []any, indent bool) string
- func ParseObject(fullMessage any, indent bool) string
- type ChanneledLogWriter
- type ConsoleLogWriter
- type JSONLLogWriter
- type LogMapper
- type LogWriter
Constants ¶
const ParseErrorMsg = "******************ERROR DURING MARSHAL OF FULL MESSAGE*******************"
Variables ¶
This section is empty.
Functions ¶
func AddLogWriter ¶
AddLogWriter adds a log writer to the registry with the specified name.
If a log writer with the same name already exists in the registry, an error is returned. Otherwise, the log writer is added to the registry.
func DefaultLogMapper ¶
func DefaultLogMapper(ctx context.Context, msg *message.LogMessage) map[string]interface{}
DefaultLogMapper is the default log mapper function.
func GetLogObjectType ¶
GetLogObjectType returns the TypeOf objects in logObj as a string delimited by commas.
func GetObjectType ¶
GetObjectType returns the TypeOf the object as a string.
func ParseLogObject ¶
ParseLogObject encodes the value of logObj into a string.
func ParseObject ¶
ParseObject encodes the value of fullMessage into a string.
Types ¶
type ChanneledLogWriter ¶
type ChanneledLogWriter interface { // Start starts the log writer, consuming log messages from the given channel. Start(chan message.MuxLogMessage) // WriteMessage writes a log message to the log writer. WriteMessage(context.Context, *message.LogMessage) error // GetBufferSize returns the buffer size of the channel used by the log writer. GetBufferSize() int }
ChanneledLogWriter represents an interface for a log writer that consumes log messages from a channel.
This interface defines methods for starting the log writer and writing log messages. It also provides a method to retrieve the buffer size of the channel.
type ConsoleLogWriter ¶
type ConsoleLogWriter struct { }
ConsoleLogWriter writes logs to the console.
func NewConsoleWriter ¶
func NewConsoleWriter() *ConsoleLogWriter
NewConsoleWriter creates a new instance of ConsoleLogWriter.
func (*ConsoleLogWriter) GetBufferSize ¶
func (c *ConsoleLogWriter) GetBufferSize() int
GetBufferSize returns the buffer size for the ConsoleLogWriter.
func (*ConsoleLogWriter) Start ¶
func (c *ConsoleLogWriter) Start(logChannel chan message.MuxLogMessage)
Start starts the ConsoleLogWriter to listen on the provided log channel and write logs to the console.
func (*ConsoleLogWriter) WriteMessage ¶
func (c *ConsoleLogWriter) WriteMessage(ctx context.Context, l *message.LogMessage) error
WriteMessage writes a log message to the console.
type JSONLLogWriter ¶
type JSONLLogWriter struct {
// contains filtered or unexported fields
}
JSONLLogWriter writes logs to console in JSONL format.
func NewJSONLConsoleWriter ¶
func NewJSONLConsoleWriter(mapper LogMapper) *JSONLLogWriter
NewJSONLConsoleWriter creates a new JSONLLogWriter instance.
func (*JSONLLogWriter) WriteMessage ¶
func (c *JSONLLogWriter) WriteMessage(ctx context.Context, l *message.LogMessage) error
WriteMessage writes a log message in JSONL format.
type LogMapper ¶
type LogMapper func(context.Context, *message.LogMessage) map[string]interface{}
LogMapper defines the function signature for log mapping.
type LogWriter ¶
type LogWriter interface { // WriteMessage writes a log message to the log writer. WriteMessage(context.Context, *message.LogMessage) error }
LogWriter represents a generic interface for writing log messages.
This interface defines a single method for writing log messages.
func GetLogWriter ¶
GetLogWriter retrieves a log writer by its name from the registry.
If a log writer with the specified name exists in the registry, it is returned. If no log writer with the specified name is found, nil is returned.