Documentation
¶
Overview ¶
Package logger provides a leveled, concurrent-safe logging utility built on top of the standard library's log package. Logs are written to disk using rlog and can be filtered by level: debug, info, warn, error, or none.
The logger prefixes messages with the process ID and supports dynamic log level changes, log formatting customization, and safe shutdown via Close().
Usage:
package main import "github.com/Data-Corruption/rlog/logger" // Create a logger logDir := "./logs" l, err := logger.New(logDir, "debug") if err != nil { log.Fatalf("Failed to create logger: %v", err) } defer l.Close() // Ensure logs are flushed // Log using methods l.Info("Application started") l.Debugf("Configuration value: %s", "some_value") // Log using context ctx := context.Background() ctx = logger.IntoContext(ctx, l) // Place logger into context logger.Info(ctx, "Hello") // Uses logger placed into context logger.Warn(ctx, "Warning message")
Index ¶
- Variables
- func Debug(ctx context.Context, v ...interface{})
- func Debugf(ctx context.Context, format string, v ...interface{})
- func Error(ctx context.Context, v ...interface{})
- func Errorf(ctx context.Context, format string, v ...interface{})
- func Info(ctx context.Context, v ...interface{})
- func Infof(ctx context.Context, format string, v ...interface{})
- func IntoContext(ctx context.Context, logger *Logger) context.Context
- func Warn(ctx context.Context, v ...interface{})
- func Warnf(ctx context.Context, format string, v ...interface{})
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Flush() error
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) IsClosed() bool
- func (l *Logger) SetFlags(debugFlag, stdFlag int)
- func (l *Logger) SetLevel(level string) error
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidLogLevel = fmt.Errorf("invalid log level") ErrClosed = fmt.Errorf("logger closed") )
Functions ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func FromContext ¶
func New ¶
New creates a new logger instance with the given directory path and log level. Levels are: debug, info, warn, error, none (case-insensitive).
func (*Logger) SetFlags ¶
SetFlags sets the flags for all loggers. debugFlag and stdFlag are the flags from std lib log package.
Click to show internal directories.
Click to hide internal directories.