Documentation
¶
Index ¶
- Constants
- func Close()
- func EndSpan(ctx context.Context)
- func InitTracer(name string)
- func NewSpan(ctx context.Context, name string) (context.Context, traceing.Span)
- func ShutdownTracer() error
- func SpanID(ctx context.Context) string
- func TraceID(ctx context.Context) string
- type Config
- type EncodeType
- type Interface
- type Logger
Constants ¶
const CallerKey = "caller"
CallerKey is the key for the caller field in logs.
const LevelKey = "level"
LevelKey is the key for the log level field in logs.
const MaxAge = 30 * 24 * time.Hour
MaxAge defines the maximum duration to retain log files (30 days).
const MessageKey = "message"
MessageKey is the key for the message field in logs.
const NameKey = "name"
NameKey is the key for the logger name field in logs.
const RotationSize = 500 * 1024 * 1024
RotationSize defines the maximum file size before rotation (500 MB).
const RotationTime = 24 * time.Hour
RotationTime defines the duration after which log files are rotated (24 hours).
const StacktraceKey = "stacktrace"
StacktraceKey is the key for the stacktrace field in logs.
const TimeKey = "time"
TimeKey is the key for the timestamp field in logs.
Variables ¶
This section is empty.
Functions ¶
func InitTracer ¶
func InitTracer(name string)
func ShutdownTracer ¶
func ShutdownTracer() error
Types ¶
type Config ¶
type Config struct {
Dir string // Dir is the directory for log files.
TracerName string // TracerName is the name of the tracer (optional).
Level zapcore.Level // Level is the minimum log level to record.
Encode EncodeType // Encode specifies the log encoding format (JSON or console).
TimeFormat string // TimeFormat is the format for timestamp fields.
}
Config defines the configuration for initializing a Logger.
type EncodeType ¶
type EncodeType string
EncodeType defines the encoding format for logs.
const ( ConsoleEncode EncodeType = "console" // ConsoleEncode formats logs in a human-readable console format. JSONEncode EncodeType = "json" // JSONEncode formats logs in JSON format. )
Constants for log encoding types.
type Logger ¶
type Logger struct {
*zap.Logger // Embedded zap logger for logging operations.
// contains filtered or unexported fields
}
Logger wraps a zap logger with file rotation writers.
func Init ¶
Init initializes the singleton Logger with the specified configuration. It creates log files with rotation (by time and size) and supports JSON or console encoding. It returns the initialized Logger and an error if initialization fails (e.g., directory creation or writer setup fails). Subsequent calls return the same instance without reinitializing.
func NameWithOptions ¶ added in v0.9.2
func Named ¶
Named returns a new Logger with the specified name. It returns nil if the Logger instance is not initialized.
func (*Logger) Close ¶
Close shuts down the Logger and closes all associated log writers. It returns an error if any writer fails to close.