log

package
v6.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package log implements modules for logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditLogWriter

type AuditLogWriter interface {
	WriteMessage(context.Context, interface{}) error
}

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 New

func New(options ...Option) *Logger

New creates a new Logger instance with the specified options.

func (*Logger) AddLogWriter

func (l *Logger) AddLogWriter(ctx context.Context, w logwriter.LogWriter)

AddLogWriter adds a log writer to the logger.

func (*Logger) Audit

func (l *Logger) Audit(ctx context.Context, msg interface{}) error

Audit writes an audit log message.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, message string, logObject ...interface{})

Debug logs a message with DEBUG level.

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) Error

func (l *Logger) Error(ctx context.Context, message string, logObject ...interface{})

Error logs a message with ERROR level.

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, message string, exitCode int, logObject ...interface{})

Fatal logs a message with FATAL level and exits the program with the specified exit code.

func (*Logger) GetLogLevel

func (l *Logger) GetLogLevel() m.LogLevel

GetLogLevel returns the current log level.

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, message string, logObject ...interface{})

Info logs a message with INFO level.

func (*Logger) NewResourceLogger

func (l *Logger) NewResourceLogger(resourceName string) Log

NewResourceLogger creates a new Logger instance with the specified resource name.

func (*Logger) Notice

func (l *Logger) Notice(ctx context.Context, message string, logObject ...interface{})

Notice logs a message with NOTICE level.

func (*Logger) SetModuleName

func (l *Logger) SetModuleName(moduleName string)

SetModuleName sets the module name for the logger.

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, message string, logObject ...interface{})

Trace logs a message with TRACE level.

func (*Logger) Warning

func (l *Logger) Warning(ctx context.Context, message string, logObject ...interface{})

Warning logs a message with WARNING level.

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

func WithFileTrace(fileTrace bool) Option

WithFileTrace sets the file trace flag for the logger.

func WithLogLevelName

func WithLogLevelName(logLevelName string) Option

WithLogLevelName sets the log level name for the logger.

func WithModuleName

func WithModuleName(moduleName string) Option

WithModuleName sets the module name for the logger.

func WithMux

func WithMux(mux Mux) Option

WithMux sets the Mux for the logger.

func WithServiceName

func WithServiceName(serviceName string) Option

WithServiceName sets the service name for the logger.

Directories

Path Synopsis
Package logwriter provides interfaces for writing log messages.
Package logwriter provides interfaces for writing log messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL