Documentation
¶
Index ¶
- Constants
- func GetAuthor() string
- func GetVersion() string
- func IntToLevel(level int) string
- func LevelToInt(level string) int
- func MakeTimeRFC3339() string
- func MicTime() string
- type Appender
- func (a *Appender) HandleFile(logger *LoggerEntry, level, message string, tf *TemplateFormatter, ...) (filePath, logInfo string)
- func (a *Appender) HandleTCPUDP(logger *LoggerEntry, level string, levelInt int, message string, ...) (dest, logInfo string)
- func (a *Appender) SetDistingType(enabled bool)
- func (a *Appender) SetFilePrefix(prefix string)
- func (a *Appender) SetSlashOrUnderline(sep string)
- type BufferManager
- func (bm *BufferManager) Clear()
- func (bm *BufferManager) Configure(enabled bool, size int)
- func (bm *BufferManager) Flush() error
- func (bm *BufferManager) GetBuffer() map[string][]string
- func (bm *BufferManager) GetBufferCount() int
- func (bm *BufferManager) IsEnabled() bool
- func (bm *BufferManager) Set(logInfo, path string) bool
- type CallerInfo
- type Config
- type DatetimeCache
- type LoggerEntry
- type LoggerManager
- func (lm *LoggerManager) GetBasePath() string
- func (lm *LoggerManager) GetLastLogger() *LoggerEntry
- func (lm *LoggerManager) GetSlashOrUnderline() string
- func (lm *LoggerManager) ProcessLogger(logger string, lastOrTmp bool) *LoggerEntry
- func (lm *LoggerManager) SetBasePath(path string)
- func (lm *LoggerManager) SetDistingFolder(enabled bool)
- type Option
- func WithAppender(appender int) Option
- func WithBasePath(path string) Option
- func WithBuffer(size int) Option
- func WithDistingByHour() Option
- func WithDistingFolder(enabled bool) Option
- func WithDistingType() Option
- func WithLevel(level int) Option
- func WithLogger(name string) Option
- func WithLoggerAuto() Option
- func WithLoggerAutoByFunc() Option
- func WithRecallDepth(depth int) Option
- func WithRemoteHost(host string, port int) Option
- func WithTemplate(template string) Option
- func WithTrimWrap() Option
- type RequestVariable
- type SeasLog
- func (sl *SeasLog) Alert(message string, context ...map[string]string) error
- func (sl *SeasLog) Close() error
- func (sl *SeasLog) CloseLoggerStream(mod int, logger string) bool
- func (sl *SeasLog) Critical(message string, context ...map[string]string) error
- func (sl *SeasLog) Debug(message string, context ...map[string]string) error
- func (sl *SeasLog) Emergency(message string, context ...map[string]string) error
- func (sl *SeasLog) Error(message string, context ...map[string]string) error
- func (sl *SeasLog) FlushBuffer() error
- func (sl *SeasLog) GetBasePath() string
- func (sl *SeasLog) GetBuffer() map[string][]string
- func (sl *SeasLog) GetBufferCount() int
- func (sl *SeasLog) GetBufferEnabled() bool
- func (sl *SeasLog) GetDatetimeFormat() string
- func (sl *SeasLog) GetFilePrefix() string
- func (sl *SeasLog) GetLastLogger() string
- func (sl *SeasLog) GetLevel() int
- func (sl *SeasLog) GetLoggerAuto() bool
- func (sl *SeasLog) GetRecallDepth() int
- func (sl *SeasLog) GetRequestID() string
- func (sl *SeasLog) GetRequestVariable() *RequestVariable
- func (sl *SeasLog) GetTemplate() string
- func (sl *SeasLog) Info(message string, context ...map[string]string) error
- func (sl *SeasLog) Log(level int, message string, context map[string]string, module string) error
- func (sl *SeasLog) Notice(message string, context ...map[string]string) error
- func (sl *SeasLog) SetAppender(appender int)
- func (sl *SeasLog) SetBasePath(path string)
- func (sl *SeasLog) SetBuffer(enabled bool, size int)
- func (sl *SeasLog) SetDatetimeFormat(format string)
- func (sl *SeasLog) SetDistingByHour(enabled bool)
- func (sl *SeasLog) SetDistingFolder(enabled bool)
- func (sl *SeasLog) SetDistingType(enabled bool)
- func (sl *SeasLog) SetFilePrefix(prefix string)
- func (sl *SeasLog) SetLevel(level int)
- func (sl *SeasLog) SetLogger(logger string) error
- func (sl *SeasLog) SetLoggerAuto(enabled bool, by int)
- func (sl *SeasLog) SetRecallDepth(depth int)
- func (sl *SeasLog) SetRemoteHost(host string, port int)
- func (sl *SeasLog) SetRequestID(id string)
- func (sl *SeasLog) SetRequestVariable(rv *RequestVariable)
- func (sl *SeasLog) SetTemplate(template string)
- func (sl *SeasLog) SetTrimWrap(enabled bool)
- func (sl *SeasLog) String() string
- func (sl *SeasLog) Warning(message string, context ...map[string]string) error
- type SeasLogError
- type StreamEntry
- type StreamManager
- type TemplateFormatter
- func (tf *TemplateFormatter) GenerateLevelTemplate(level string) string
- func (tf *TemplateFormatter) GenerateLogInfo(level, message string, dc *DatetimeCache, rv *RequestVariable, ci CallerInfo) string
- func (tf *TemplateFormatter) GenerateSyslogInfo(level, message string, dc *DatetimeCache, rv *RequestVariable, ci CallerInfo) string
- func (tf *TemplateFormatter) GetCurrentTemplate() string
- func (tf *TemplateFormatter) GetLevelTemplate() string
- func (tf *TemplateFormatter) ReInit()
- func (tf *TemplateFormatter) SetBasePath(basePath string)
- func (tf *TemplateFormatter) SetRequestID(id string)
- func (tf *TemplateFormatter) SetTemplate(template string)
Constants ¶
const ( ErrLoggerError = 4403 ErrContentError = 4406 ErrWindowsError = 4407 )
Error codes matching the C implementation.
const ( LevelEmergency = 0 LevelAlert = 1 LevelCritical = 2 LevelError = 3 LevelWarning = 4 LevelNotice = 5 LevelInfo = 6 LevelDebug = 7 LevelAll = 8 )
const ( StrAll = "ALL" StrDebug = "DEBUG" StrInfo = "INFO" StrNotice = "NOTICE" StrWarning = "WARNING" StrError = "ERROR" StrCritical = "CRITICAL" StrAlert = "ALERT" StrEmergency = "EMERGENCY" )
Level string constants
const ( AppenderFile = 1 AppenderTCP = 2 AppenderUDP = 3 )
Appender types
const ( CloseStreamModAll = 1 CloseStreamModAssign = 2 CloseStreamCanDelete = 3 )
Stream close modes
const ( LoggerAutoByFile = 0 // Use the caller's filename (without .go extension) as logger LoggerAutoByFunc = 1 // Use the caller's function name as logger )
Auto-logger modes — controls how the logger name is derived from the caller.
const SyslogFacility = 8
Syslog facility (LOG_USER)
Variables ¶
This section is empty.
Functions ¶
func IntToLevel ¶
IntToLevel converts an integer level to its string representation. Returns StrDebug for unknown values.
func LevelToInt ¶
LevelToInt converts a level string to its integer value. Returns LevelDebug if the string is not recognised.
func MakeTimeRFC3339 ¶
func MakeTimeRFC3339() string
MakeTimeRFC3339 returns the current time in RFC 3339 format.
Types ¶
type Appender ¶
type Appender struct {
// contains filtered or unexported fields
}
Appender dispatches log entries to the configured output (file, TCP, or UDP). Mirrors the appender_handle_file and appender_handle_tcp_udp functions in Appender.c.
func NewAppender ¶
func NewAppender(appender int, filePrefix string, distingType bool, slashOrUnderline string) *Appender
NewAppender creates a new Appender.
func (*Appender) HandleFile ¶
func (a *Appender) HandleFile(logger *LoggerEntry, level, message string, tf *TemplateFormatter, dc *DatetimeCache, rv *RequestVariable, ci CallerInfo) (filePath, logInfo string)
HandleFile constructs the file path and formats the log entry for file output. Returns the log file path and the formatted log message (with newline).
func (*Appender) HandleTCPUDP ¶
func (a *Appender) HandleTCPUDP(logger *LoggerEntry, level string, levelInt int, message string, tf *TemplateFormatter, dc *DatetimeCache, rv *RequestVariable, hostName, processID string, ci CallerInfo) (dest, logInfo string)
HandleTCPUDP constructs the syslog-formatted message for network output. Returns the destination identifier (logger name) and the syslog message.
func (*Appender) SetDistingType ¶
SetDistingType updates the disting_type setting.
func (*Appender) SetFilePrefix ¶
SetFilePrefix updates the file prefix.
func (*Appender) SetSlashOrUnderline ¶
SetSlashOrUnderline updates the path separator.
type BufferManager ¶
type BufferManager struct {
// contains filtered or unexported fields
}
BufferManager accumulates log entries in memory, grouped by destination path. When buffer_count reaches buffer_size, the buffer is flushed. Mirrors the buffer management in the C implementation's Buffer.c.
func NewBufferManager ¶
func NewBufferManager(enabled bool, bufferSize int, sm *StreamManager) *BufferManager
NewBufferManager creates a new BufferManager.
func (*BufferManager) Clear ¶
func (bm *BufferManager) Clear()
Clear empties the buffer without flushing.
func (*BufferManager) Configure ¶
func (bm *BufferManager) Configure(enabled bool, size int)
Configure updates the buffer enabled state and size.
func (*BufferManager) Flush ¶
func (bm *BufferManager) Flush() error
Flush writes all buffered entries to their respective streams.
func (*BufferManager) GetBuffer ¶
func (bm *BufferManager) GetBuffer() map[string][]string
GetBuffer returns a copy of the current buffer contents.
func (*BufferManager) GetBufferCount ¶
func (bm *BufferManager) GetBufferCount() int
GetBufferCount returns the total number of buffered entries.
func (*BufferManager) IsEnabled ¶
func (bm *BufferManager) IsEnabled() bool
IsEnabled returns whether buffering is active.
func (*BufferManager) Set ¶
func (bm *BufferManager) Set(logInfo, path string) bool
Set adds a log entry to the buffer. If the buffer is full, it flushes. Returns true if the entry was buffered, false if buffering is disabled.
type CallerInfo ¶
type CallerInfo struct {
File string // Basename of the source file (e.g. "main.go")
Line int // Line number
Func string // Full function name (e.g. "myapp.(*UserService).Login")
}
CallerInfo holds the caller's file, line, and function name. It is captured at the public API entry points and passed through the logging pipeline to avoid redundant runtime.Caller calls.
func (CallerInfo) FormatClassAction ¶
func (ci CallerInfo) FormatClassAction() string
FormatClassAction formats the function name as Class::Action (matching C behavior). In Go, this returns the full function name (e.g. "myapp.UserService.Login").
func (CallerInfo) FormatFileLine ¶
func (ci CallerInfo) FormatFileLine() string
getCallerInfo returns the file basename and line number from CallerInfo.
type Config ¶
type Config struct {
DefaultBasePath string
DefaultLogger string
DefaultFilePrefix string
DefaultFileDatetimeSep string
DefaultDatetimeFormat string
DefaultTemplate string
DistingFolder bool
DistingType bool
DistingByHour bool
UseBuffer bool
BufferSize int
BufferDisabledInCLI bool
Level int
RecallDepth int
// LoggerAuto enables automatic logger name derivation from the caller.
// When true and no explicit module is passed to a log method,
// the logger name is derived from the caller's filename or function name.
LoggerAuto bool
LoggerAutoBy int // LoggerAutoByFile=0 (default), LoggerAutoByFunc=1
Appender int
AppenderRetry int
RemoteHost string
RemotePort int
RemoteTimeout time.Duration
TrimWrap bool
ThrowException bool
IgnoreWarning bool
}
Config holds all configuration options, mirroring the SeasLog C INI entries.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with the same defaults as the SeasLog C extension.
type DatetimeCache ¶
type DatetimeCache struct {
// contains filtered or unexported fields
}
DatetimeCache caches formatted time strings to avoid redundant formatting. Mirrors last_sec_entry_t (per-second) and last_min_entry_t (per-minute) from the C implementation.
func NewDatetimeCache ¶
func NewDatetimeCache(format string, distingByHour bool, separator string) *DatetimeCache
NewDatetimeCache creates a new DatetimeCache.
func (*DatetimeCache) GetFormat ¶
func (dc *DatetimeCache) GetFormat() string
GetFormat returns the current datetime format.
func (*DatetimeCache) RealDate ¶
func (dc *DatetimeCache) RealDate() string
RealDate returns the date string for file naming, computing at most once per minute.
func (*DatetimeCache) RealTime ¶
func (dc *DatetimeCache) RealTime() string
RealTime returns the formatted timestamp, computing at most once per second.
func (*DatetimeCache) SetDistingByHour ¶
func (dc *DatetimeCache) SetDistingByHour(enabled bool)
SetDistingByHour updates the hour-based file naming and forces a refresh.
func (*DatetimeCache) SetFormat ¶
func (dc *DatetimeCache) SetFormat(format string)
SetFormat updates the datetime format and forces a refresh.
func (*DatetimeCache) SetSeparator ¶
func (dc *DatetimeCache) SetSeparator(sep string)
SetSeparator updates the date separator and forces a refresh.
type LoggerEntry ¶
type LoggerEntry struct {
Hash uint64
Logger string
LoggerPath string
Access bool // true if directory creation succeeded
}
LoggerEntry represents a resolved logger with its path and access status.
type LoggerManager ¶
type LoggerManager struct {
// contains filtered or unexported fields
}
LoggerManager manages logger resolution with hash-based caching. Mirrors the logger_list hash table in the C implementation.
func NewLoggerManager ¶
func NewLoggerManager(basePath, defaultLogger string, distingFolder bool) *LoggerManager
NewLoggerManager creates a new LoggerManager.
func (*LoggerManager) GetBasePath ¶
func (lm *LoggerManager) GetBasePath() string
GetBasePath returns the current base path.
func (*LoggerManager) GetLastLogger ¶
func (lm *LoggerManager) GetLastLogger() *LoggerEntry
GetLastLogger returns the current active logger.
func (*LoggerManager) GetSlashOrUnderline ¶
func (lm *LoggerManager) GetSlashOrUnderline() string
GetSlashOrUnderline returns the separator for log file paths.
func (*LoggerManager) ProcessLogger ¶
func (lm *LoggerManager) ProcessLogger(logger string, lastOrTmp bool) *LoggerEntry
ProcessLogger resolves a logger by name, using the cache when possible. If lastOrTmp is true, the logger becomes the active (last) logger. If false, it's a temporary logger for one-off logging.
func (*LoggerManager) SetBasePath ¶
func (lm *LoggerManager) SetBasePath(path string)
SetBasePath updates the base path and clears the cache.
func (*LoggerManager) SetDistingFolder ¶
func (lm *LoggerManager) SetDistingFolder(enabled bool)
SetDistingFolder updates the folder mode and clears the cache.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring SeasLog.
func WithBuffer ¶
WithBuffer enables buffering with the given size.
func WithDistingByHour ¶
func WithDistingByHour() Option
WithDistingByHour enables hourly log rotation.
func WithDistingFolder ¶
WithDistingFolder enables or disables folder-based logger separation.
func WithLoggerAuto ¶
func WithLoggerAuto() Option
WithLoggerAuto enables automatic logger name derivation from the caller's filename.
func WithLoggerAutoByFunc ¶
func WithLoggerAutoByFunc() Option
WithLoggerAutoByFunc enables automatic logger name derivation from the caller's function name.
func WithRecallDepth ¶
WithRecallDepth sets the recall depth for caller info (%F and %C).
func WithRemoteHost ¶
WithRemoteHost sets the remote host for TCP/UDP appenders.
func WithTrimWrap ¶
func WithTrimWrap() Option
WithTrimWrap enables stripping newlines from log messages.
type RequestVariable ¶
type RequestVariable struct {
DomainPort string
ClientIP string
RequestURI string
RequestMethod string
}
RequestVariable holds request-related information used by template placeholders.
func NewRequestVariable ¶
func NewRequestVariable() *RequestVariable
NewRequestVariable creates a RequestVariable with sensible defaults.
type SeasLog ¶
type SeasLog struct {
// contains filtered or unexported fields
}
SeasLog is the main logging structure.
func NewSeasLog ¶
NewSeasLog creates a new SeasLog instance with the given options.
func NewSeasLogWithConfig ¶
NewSeasLogWithConfig creates a new SeasLog instance with an explicit config.
func (*SeasLog) CloseLoggerStream ¶
CloseLoggerStream closes stream connections. mod: CloseStreamModAll=close all, CloseStreamModAssign=close matching logger.
func (*SeasLog) FlushBuffer ¶
FlushBuffer writes all buffered entries to their streams.
func (*SeasLog) GetBasePath ¶
GetBasePath returns the current base path.
func (*SeasLog) GetBufferCount ¶
GetBufferCount returns the number of buffered entries.
func (*SeasLog) GetBufferEnabled ¶
GetBufferEnabled returns whether buffering is active.
func (*SeasLog) GetDatetimeFormat ¶
GetDatetimeFormat returns the current datetime format.
func (*SeasLog) GetFilePrefix ¶
GetFilePrefix returns the current file prefix.
func (*SeasLog) GetLastLogger ¶
GetLastLogger returns the name of the current active logger.
func (*SeasLog) GetLoggerAuto ¶
GetLoggerAuto returns whether auto-logger is enabled.
func (*SeasLog) GetRecallDepth ¶
GetRecallDepth returns the current recall depth.
func (*SeasLog) GetRequestID ¶
GetRequestID returns the current request ID.
func (*SeasLog) GetRequestVariable ¶
func (sl *SeasLog) GetRequestVariable() *RequestVariable
GetRequestVariable returns the current request variables.
func (*SeasLog) GetTemplate ¶
GetTemplate returns the current log template.
func (*SeasLog) SetAppender ¶
SetAppender sets the appender type (file, TCP, or UDP).
func (*SeasLog) SetBasePath ¶
SetBasePath sets the base log directory.
func (*SeasLog) SetDatetimeFormat ¶
SetDatetimeFormat sets the datetime format (Go time layout).
func (*SeasLog) SetDistingByHour ¶
SetDistingByHour enables or disables hourly log file rotation.
func (*SeasLog) SetDistingFolder ¶
SetDistingFolder enables or disables folder-based logger separation.
func (*SeasLog) SetDistingType ¶
SetDistingType enables or disables per-level log file separation.
func (*SeasLog) SetFilePrefix ¶
SetFilePrefix sets the file name prefix.
func (*SeasLog) SetLoggerAuto ¶
SetLoggerAuto enables or disables automatic logger name derivation from the caller. When enabled, the logger name is derived from the caller's filename or function name. by: LoggerAutoByFile (0) or LoggerAutoByFunc (1).
func (*SeasLog) SetRecallDepth ¶
SetRecallDepth sets the recall depth for caller info (%F and %C).
func (*SeasLog) SetRemoteHost ¶
SetRemoteHost sets the remote host and port for TCP/UDP.
func (*SeasLog) SetRequestID ¶
SetRequestID sets the request unique ID.
func (*SeasLog) SetRequestVariable ¶
func (sl *SeasLog) SetRequestVariable(rv *RequestVariable)
SetRequestVariable sets request variables for template placeholders.
func (*SeasLog) SetTemplate ¶
SetTemplate sets the log template and re-compiles it.
func (*SeasLog) SetTrimWrap ¶
SetTrimWrap enables or disables stripping newlines from log messages.
type SeasLogError ¶
SeasLogError represents a SeasLog error.
func (*SeasLogError) Error ¶
func (e *SeasLogError) Error() string
type StreamEntry ¶
type StreamEntry struct {
Opt string
Hash uint64
Writer io.WriteCloser
// contains filtered or unexported fields
}
StreamEntry represents a cached stream (file handle or network connection).
type StreamManager ¶
type StreamManager struct {
// contains filtered or unexported fields
}
StreamManager manages a pool of reusable streams (file handles and network connections). Mirrors the stream_list hash table in the C implementation.
func NewStreamManager ¶
func NewStreamManager(appender int, remoteHost string, remotePort int, remoteTimeout time.Duration) *StreamManager
NewStreamManager creates a new StreamManager.
func (*StreamManager) CloseAll ¶
func (sm *StreamManager) CloseAll()
CloseAll closes all streams and clears the pool.
func (*StreamManager) CloseStream ¶
func (sm *StreamManager) CloseStream(mod int, opt string) bool
CloseStream closes streams matching the given criteria. mod=CloseStreamModAll closes all streams. mod=CloseStreamModAssign closes streams matching the opt substring.
func (*StreamManager) ProcessStream ¶
func (sm *StreamManager) ProcessStream(opt string) io.Writer
ProcessStream returns a writer for the given path/target, reusing cached connections when possible. For file appenders, opt is the file path. For TCP/UDP, opt is the logger name (the actual connection is shared per appender type).
func (*StreamManager) SetAppender ¶
func (sm *StreamManager) SetAppender(appender int)
SetAppender updates the appender type and clears the pool.
func (*StreamManager) SetRemote ¶
func (sm *StreamManager) SetRemote(host string, port int)
SetRemote updates the remote host/port and clears the pool.
type TemplateFormatter ¶
type TemplateFormatter struct {
// contains filtered or unexported fields
}
TemplateFormatter implements the SeasLog template engine. It pre-compiles the template, resolving static placeholders (hostname, PID) and keeping dynamic placeholders for per-log-call substitution.
func NewTemplateFormatter ¶
func NewTemplateFormatter(template, hostName, processID, basePath, requestID string) *TemplateFormatter
NewTemplateFormatter creates a formatter and pre-compiles the template.
func (*TemplateFormatter) GenerateLevelTemplate ¶
func (tf *TemplateFormatter) GenerateLevelTemplate(level string) string
GenerateLevelTemplate formats the level template for analyzer use.
func (*TemplateFormatter) GenerateLogInfo ¶
func (tf *TemplateFormatter) GenerateLogInfo(level, message string, dc *DatetimeCache, rv *RequestVariable, ci CallerInfo) string
GenerateLogInfo formats a log entry using the pre-compiled template. It substitutes dynamic placeholders (%T, %t, %Q, %L, %M, %F, %U, %u, %C, %D, %R, %m, %I).
func (*TemplateFormatter) GenerateSyslogInfo ¶
func (tf *TemplateFormatter) GenerateSyslogInfo(level, message string, dc *DatetimeCache, rv *RequestVariable, ci CallerInfo) string
GenerateSyslogInfo formats a log entry for syslog (without newline, without %T prefix).
func (*TemplateFormatter) GetCurrentTemplate ¶
func (tf *TemplateFormatter) GetCurrentTemplate() string
GetCurrentTemplate returns the pre-compiled template.
func (*TemplateFormatter) GetLevelTemplate ¶
func (tf *TemplateFormatter) GetLevelTemplate() string
GetLevelTemplate returns the extracted level template.
func (*TemplateFormatter) ReInit ¶
func (tf *TemplateFormatter) ReInit()
ReInit re-compiles the template (e.g. after config changes).
func (*TemplateFormatter) SetBasePath ¶
func (tf *TemplateFormatter) SetBasePath(basePath string)
SetBasePath updates the base path and re-compiles the template.
func (*TemplateFormatter) SetRequestID ¶
func (tf *TemplateFormatter) SetRequestID(id string)
SetRequestID updates the request ID.
func (*TemplateFormatter) SetTemplate ¶
func (tf *TemplateFormatter) SetTemplate(template string)
SetTemplate updates the template string and re-compiles.