Documentation ¶
Overview ¶
Example ¶
package main import ( "github.com/tencentmusic/evhub/pkg/log" ) func main() { log.Init(&log.Config{ Level: log.LevelInfo, Filename: "test.log", MaxSize: 10, MaxAge: 1, MaxBackups: 2, Compress: false, DevMode: false, }) people := "Alice" log.Debug("Hello", "people", people) log.Info("Hello", "people", people) log.Warn("Hello", "people", people) log.Error("Hello", "people", people) }
Output:
Index ¶
- Constants
- Variables
- func Close()
- func Debug(msg string, keyvals ...interface{})
- func Debugf(template string, args ...interface{})
- func Error(msg string, keyvals ...interface{})
- func Errorf(template string, args ...interface{})
- func Fatal(msg string, keyvals ...interface{})
- func Fatalf(template string, args ...interface{})
- func Info(msg string, keyvals ...interface{})
- func Infof(template string, args ...interface{})
- func Init(config *Config)
- func LevelHandler() http.Handler
- func Panic(msg string, keyvals ...interface{})
- func Panicf(template string, args ...interface{})
- func SetDye(ctx context.Context, appID string, topicID string, eventID string, ...) context.Context
- func SetEventAppID(ctx context.Context, appID string) context.Context
- func SetEventID(ctx context.Context, eventID string) context.Context
- func SetEventTopicID(ctx context.Context, topicID string) context.Context
- func SetLevel(level Level)
- func SetRepeatTimes(ctx context.Context, repeatTimes uint32) context.Context
- func SetRetryTimes(ctx context.Context, retryTimes uint32) context.Context
- func ShouldJSON(v interface{})
- func Warn(msg string, keyvals ...interface{})
- func Warnf(template string, args ...interface{})
- func With(ctx context.Context) *zap.SugaredLogger
- type Config
- type EventKey
- type Level
- type Logger
Examples ¶
Constants ¶
const ( OutputStdout = iota OutputFile OutputStdoutAndFile )
const ( IndexName = "index_name" AppIDName = "app_id" CallerSkipWith = -2 )
Variables ¶
var ( LogIndexName = "evhub" AppID = "evhub" )
Functions ¶
func Debug ¶
func Debug(msg string, keyvals ...interface{})
Debug logs a message with some additional context.
func Debugf ¶
func Debugf(template string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Error ¶
func Error(msg string, keyvals ...interface{})
Error logs a message with some additional context.
func Errorf ¶
func Errorf(template string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Fatal ¶
func Fatal(msg string, keyvals ...interface{})
Fatal logs a message with some additional context, then calls os.Exit.
func Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Info ¶
func Info(msg string, keyvals ...interface{})
Info logs a message with some additional context.
func Infof ¶
func Infof(template string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func LevelHandler ¶
LevelHandler returns an HTTP handler that can dynamically modifies the log level.
func Panic ¶
func Panic(msg string, keyvals ...interface{})
Panic logs a message with some additional context, then panics.
func Panicf ¶
func Panicf(template string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics.
func ShouldJSON ¶
func ShouldJSON(v interface{})
func Warn ¶
func Warn(msg string, keyvals ...interface{})
Warn logs a message with some additional context.
Types ¶
type Config ¶
type Config struct { Level Level // Level is the minimum enabled logging level. Output int // Output determines where the log should be written to. Filename string // Filename is the file to write logs to. MaxSize int // MaxSize is the maximum size in megabytes of the log file before it gets rotated. MaxAge int // MaxAge is the maximum number of days to // retain old log files based on the timestamp encoded in their filename. MaxBackups int // MaxBackups is the maximum number of old log files to retain. Compress bool // Compress determines if the rotated log files should be compressed using gzip. DevMode bool // DevMode if true -> print colorful log in console and files. LogIndexName string AppID string }
Config is the configuration of the log.
type Level ¶
type Level int
A Level is a logging priority. Higher levels are more important.
const ( // LevelDebug logs are typically voluminous, and are usually disabled in // production. LevelDebug Level = iota // LevelInfo is the default logging priority. LevelInfo // LevelWarn logs are more important than Info, but don't need individual // human review. LevelWarn // LevelError logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. LevelError // LevelPanic logs a message, then panics. LevelPanic // LevelFatal logs a message, then calls os.Exit(1). LevelFatal )
func ConvertLevel ¶
func (*Level) UnmarshalText ¶
UnmarshalText Unmarshal the text.
type Logger ¶
type Logger interface { Debug(msg string, keyvals ...interface{}) Info(msg string, keyvals ...interface{}) Warn(msg string, keyvals ...interface{}) Error(msg string, keyvals ...interface{}) Panic(msg string, keyvals ...interface{}) Fatal(msg string, keyvals ...interface{}) Debugf(template string, args ...interface{}) Infof(template string, args ...interface{}) Warnf(template string, args ...interface{}) Errorf(template string, args ...interface{}) Panicf(template string, args ...interface{}) Fatalf(template string, args ...interface{}) With(args ...interface{}) Logger WithOptions(opts ...zap.Option) *zap.SugaredLogger SetLevel(Level) LevelHandler() http.Handler Close() error GetLevel() Level }
Logger is the fundamental interface for all log operations.