Documentation
¶
Index ¶
- Constants
- Variables
- func SanitizeForPostgreSQL(s string) string
- func SetConsoleLogLevel(level slog.Level)
- func SetConsoleLogLevelFromString(levelStr string)
- func SetFileLogger(directory string) error
- func SetFormatJSON()
- func SetFormatSimple()
- func SetFormatText()
- func SetJSONLFileLogger(directory string) error
- func SetTelegramBot(token string, chatIDs []string)
- type DXLog
- func (l *DXLog) Debug(text string)
- func (l *DXLog) Debugf(text string, v ...any)
- func (l *DXLog) Error(text string, err error)
- func (l *DXLog) ErrorAndCreateErrorf(text string, v ...any) (err error)
- func (l *DXLog) Errorf(err error, text string, v ...any)
- func (l *DXLog) Fatal(text string)
- func (l *DXLog) FatalAndCreateErrorf(text string, v ...any) (err error)
- func (l *DXLog) Fatalf(text string, v ...any)
- func (l *DXLog) Info(text string)
- func (l *DXLog) Infof(text string, v ...any)
- func (l *DXLog) LogText(err error, severity DXLogLevel, location string, text string, v ...any)
- func (l *DXLog) Panic(location string, err error)
- func (l *DXLog) PanicAndCreateErrorf(location, text string, v ...any) (err error)
- func (l *DXLog) Trace(text string)
- func (l *DXLog) Tracef(text string, v ...any)
- func (l *DXLog) Warn(text string)
- func (l *DXLog) WarnAndCreateError(text string) (err error)
- func (l *DXLog) WarnAndCreateErrorf(text string, v ...any) (err error)
- func (l *DXLog) Warnf(text string, v ...any)
- type DXLogFormat
- type DXLogLevel
Constants ¶
const ( DXLogFormatText DXLogFormat = iota DXLogFormatJSON = 1 DXLogFormatSimple = 2 )
const ( LevelTrace slog.Level = slog.LevelDebug - 4 LevelFatal slog.Level = slog.LevelError + 4 LevelPanic slog.Level = slog.LevelError + 8 )
Custom slog levels for TRACE, FATAL, and PANIC
Variables ¶
var ConsoleLogLevel = LevelTrace // Default: show all logs (backward compatible)
var DXLogLevelAsString = map[DXLogLevel]string{ DXLogLevelTrace: "TRACE", DXLogLevelDebug: "DEBUG", DXLogLevelInfo: "INFO", DXLogLevelWarn: "WARN", DXLogLevelError: "ERROR", DXLogLevelFatal: "FATAL", DXLogLevelPanic: "PANIC", }
var OnError func(l *DXLog, errPrev error, severity DXLogLevel, location string, text string, stack string) (err error)
Functions ¶
func SanitizeForPostgreSQL ¶
SanitizeForPostgreSQL replaces null bytes and other invalid UTF-8 sequences with their hex representation (e.g., \x00 becomes "0x00") so they can be safely stored in PostgreSQL TEXT fields while remaining visible to log viewers.
func SetConsoleLogLevel ¶
SetConsoleLogLevel sets the minimum log level that will be written to console (stdout). This does NOT affect the error_log database audit trail, which always captures errors. Valid levels: LevelTrace, LevelDebug, LevelInfo, LevelWarn, LevelError
Example: SetConsoleLogLevel(LevelInfo) will only show INFO, WARN, ERROR, FATAL, PANIC on console
func SetConsoleLogLevelFromString ¶
func SetConsoleLogLevelFromString(levelStr string)
SetConsoleLogLevelFromString sets console log level from string value. Valid values: "TRACE", "DEBUG", "INFO", "WARN", "ERROR" Invalid/empty values default to INFO
func SetFileLogger ¶
SetFileLogger enables daily rotating file logging to the given directory. Call BEFORE SetTelegramBot so the Telegram handler wraps the file handler. All log levels are written to file; existing OnError handler is chained.
func SetFormatJSON ¶
func SetFormatJSON()
func SetFormatSimple ¶
func SetFormatSimple()
SetFormatSimple sets a clean, human-readable format without field labels Output: "2026-02-15 18:16:58 Message here" Best for CLI tools and human-readable console output
func SetFormatText ¶
func SetFormatText()
func SetJSONLFileLogger ¶
SetJSONLFileLogger enables a second, machine-readable log stream: one JSON object per line in app-<date>.jsonl, rotated daily like SetFileLogger.
It is independent of SetFileLogger -- either, both or neither may be set -- and chains onto whatever handler is already registered, so the order of the Set*Logger calls only decides the order the streams are written in. Call the pair of them before SetTelegramBot so Telegram wraps both.
func SetTelegramBot ¶
SetTelegramBot configures Telegram alerting for dxlib/log. Messages are sent on WARN/ERROR/FATAL/PANIC severity via raw HTTP POST (zero new dependencies). token: Telegram bot token, chatIDs: list of chat IDs to send to.
Types ¶
type DXLog ¶
type DXLog struct {
Context context.Context
Prefix string
RequestURL string
LastErrorLogId int64
LastErrorLogUid string
}
var Log DXLog
func (*DXLog) ErrorAndCreateErrorf ¶
func (*DXLog) FatalAndCreateErrorf ¶
func (*DXLog) PanicAndCreateErrorf ¶
func (*DXLog) WarnAndCreateError ¶
func (*DXLog) WarnAndCreateErrorf ¶
type DXLogLevel ¶
type DXLogLevel int
const ( DXLogLevelPanic DXLogLevel = iota // Should be impossible to be wrong... mainly cause by programming error/bug and application must be stopped to prevent giving wrong output DXLogLevelFatal // Error because wrong configuration or input that prevent the application to continue running or must be exited DXLogLevelError // Should be impossible to be wrong... mainly cause by programming error/bug, but the application must be to continue running and process other inputs DXLogLevelWarn // Error because the input, the application must continue running and receive another input DXLogLevelInfo DXLogLevelDebug DXLogLevelTrace )