Documentation
¶
Index ¶
- Constants
- Variables
- func Colorize(msg string, colors ...string) string
- func CutFrontPath(s string, length int) string
- func CutStart(s string, length int, delim string, prefixIfCut bool) string
- func DeColorize(str string) string
- func NewLogFile(filename string) (*os.File, error)
- type BatchLogger
- func (l *BatchLogger) Critical(e error)
- func (l *BatchLogger) Criticalf(format string, args ...any)
- func (l *BatchLogger) Debug(args ...any)
- func (l *BatchLogger) Debugf(format string, args ...any)
- func (l *BatchLogger) Error(args ...any)
- func (l *BatchLogger) Errorf(format string, args ...any)
- func (l *BatchLogger) Info(args ...any)
- func (l *BatchLogger) Infof(format string, args ...any)
- func (l *BatchLogger) LogLevel() request.LogLevel
- func (l *BatchLogger) Now(loglevel Loglevel, format string, args ...any)
- func (l *BatchLogger) Test(args ...any)
- func (l *BatchLogger) Testf(format string, args ...any)
- func (l *BatchLogger) Warning(args ...any)
- func (l *BatchLogger) Warningf(format string, args ...any)
- type LogEntry
- type Logger
- func (l *Logger) Critical(err error)
- func (l *Logger) Criticalf(format string, args ...any)
- func (l *Logger) Debug(args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Error(args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Info(args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) LogLevel() request.LogLevel
- func (l *Logger) Test(args ...any)
- func (l *Logger) Testf(format string, args ...any)
- func (l *Logger) Warning(args ...any)
- func (l *Logger) Warningf(format string, args ...any)
- type Loglevel
Constants ¶
const ( Italics string = "\x1b[3m" Underline string = "\x1b[4m" Blink string = "\x1b[5m" Bold string = "\x1b[1m" Reset string = "\033[0m" Red string = "\033[31m" Green string = "\033[32m" Yellow string = "\033[33m" Blue string = "\033[34m" Purple string = "\033[35m" Cyan string = "\033[36m" White string = "\033[37m" Grey string = "\033[90m" BrightRed string = "\033[31;1m" BrightGreen string = "\033[32;1m" BrightYellow string = "\033[33;1m" BrightBlue string = "\033[34;1m" BrightPurple string = "\033[35;1m" BrightCyan string = "\033[36;1m" BrightGrey string = "\033[37;1m" DimRed string = "\033[31;2m" DimGreen string = "\033[32;2m" DimYellow string = "\033[33;2m" DimBlue string = "\033[34;2m" DimPurple string = "\033[35;2m" DimCyan string = "\033[36;2m" DimGrey string = "\033[37;2m" )
ANSI color codes
Variables ¶
var ( // LogTest ColorLevelTest = Purple // LogDebug ColorLevelDebug = Green // LogInfo ColorLevelInfo = Blue // LogWarn ColorLevelWarning = Yellow // LogErr ColorLevelError = Red // No level, default switch case opt. ColorNoLevel = Green )
Preset colors for use in the logger's Colorize function
Functions ¶
func CutFrontPath ¶
Cut the front of a path, and add "..." if it was cut.
Types ¶
type BatchLogger ¶
type BatchLogger struct { // The prefix of the logger. Prefix string // The log level of the logger. Loglevel Loglevel // Colorize is a flag which determines whether the log entry is written colorized. Colorize bool // Handler is a function which determines how the log entry is handled. Handler func(entries []*LogEntry, stdout io.Writer) // File is the file to write to. File io.Writer // contains filtered or unexported fields }
BatchLogger is a logger which logs messages in batches.
This logger is useful when you want to log a large number of messages or need to pool log messages.
This does not guarantee order of messages!
func NewBatchLogger ¶
func NewBatchLogger(loglevel Loglevel, flushSize int, flushInterval time.Duration, file io.Writer, prefix ...string) *BatchLogger
NewBatchLogger creates a new Logger.
func (*BatchLogger) Critical ¶
func (l *BatchLogger) Critical(e error)
Critical logs a critical message.
func (*BatchLogger) Criticalf ¶
func (l *BatchLogger) Criticalf(format string, args ...any)
Criticalf logs a critical message with a format.
func (*BatchLogger) Debug ¶
func (l *BatchLogger) Debug(args ...any)
Write a debug message, loglevel debug
func (*BatchLogger) Debugf ¶
func (l *BatchLogger) Debugf(format string, args ...any)
Write a debug message, loglevel debug
Format the message in the fmt package format.
func (*BatchLogger) Error ¶
func (l *BatchLogger) Error(args ...any)
Write an error message, loglevel error
func (*BatchLogger) Errorf ¶
func (l *BatchLogger) Errorf(format string, args ...any)
Write an error message, loglevel error
Format the message in the fmt package format.
func (*BatchLogger) Info ¶
func (l *BatchLogger) Info(args ...any)
Write an info message, loglevel info
func (*BatchLogger) Infof ¶
func (l *BatchLogger) Infof(format string, args ...any)
Write an info message, loglevel info
Format the message in the fmt package format.
func (*BatchLogger) LogLevel ¶
func (l *BatchLogger) LogLevel() request.LogLevel
Loglevel returns the loglevel of the logger.
func (*BatchLogger) Now ¶
func (l *BatchLogger) Now(loglevel Loglevel, format string, args ...any)
Write a message instantly with the given loglevel.
func (*BatchLogger) Test ¶
func (l *BatchLogger) Test(args ...any)
Write a test message, loglevel test
func (*BatchLogger) Testf ¶
func (l *BatchLogger) Testf(format string, args ...any)
Write a test message, loglevel test
Format the message in the fmt package format.
func (*BatchLogger) Warning ¶
func (l *BatchLogger) Warning(args ...any)
Write a warning message, loglevel warning
func (*BatchLogger) Warningf ¶
func (l *BatchLogger) Warningf(format string, args ...any)
Write a warning message, loglevel warning
Format the message in the fmt package format.
type LogEntry ¶
type LogEntry struct { Time time.Time `json:"time"` // The time the log entry was created. Level Loglevel `json:"level"` // The level of the log entry. Message string `json:"message"` // The message of the log entry. Stacktrace tracer.StackTrace `json:"stacktrace"` // The tracer of the log entry. }
A entry to be logged.
This may include a list of callers (Stacktrace)
func NewLogEntry ¶
Intialize a new log entry.
level: The level of the log entry.
message: The message of the log entry.
stackTraceLen: The length of the stacktrace.
skip: The number of frames to skip in the stacktrace.