blob: c1ffa78742886e9e7a07edcc66f3dd2473f535de [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package log
import (
"io"
)
// Level is the log level.
type Level int
// Enums log level constants.
const (
LevelNil Level = iota
LevelTrace
LevelDebug
LevelInfo
LevelWarn
LevelError
LevelFatal
)
// String turns the LogLevel to string.
func (lv *Level) String() string {
return LevelStrings[*lv]
}
// LevelStrings is the map from log level to its string representation.
var LevelStrings = map[Level]string{
LevelTrace: "trace",
LevelDebug: "debug",
LevelInfo: "info",
LevelWarn: "warn",
LevelError: "error",
LevelFatal: "fatal",
}
// LevelNames is the map from string to log level.
var LevelNames = map[string]Level{
"trace": LevelTrace,
"debug": LevelDebug,
"info": LevelInfo,
"warn": LevelWarn,
"error": LevelError,
"fatal": LevelFatal,
}
// LoggerOptions is the log options.
type LoggerOptions struct {
LogLevel Level
Pattern string
Writer io.Writer
}
// LoggerOption modifies the LoggerOptions.
type LoggerOption func(*LoggerOptions)
// Field is the user defined log field.
type Field struct {
Key string
Value interface{}
}
// Logger is the underlying logging work for server.
type Logger interface {
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print.
Trace(args ...interface{})
// Tracef logs to TRACE log. Arguments are handled in the manner of fmt.Printf.
Tracef(format string, args ...interface{})
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
Debug(args ...interface{})
// Debugf logs to DEBUG log. Arguments are handled in the manner of fmt.Printf.
Debugf(format string, args ...interface{})
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
Info(args ...interface{})
// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
Infof(format string, args ...interface{})
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print.
Warn(args ...interface{})
// Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
Warnf(format string, args ...interface{})
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
Error(args ...interface{})
// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
Errorf(format string, args ...interface{})
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
// All Fatal logs will exit by calling os.Exit(1).
// Implementations may also call os.Exit() with a non-zero exit code.
Fatal(args ...interface{})
// Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
Fatalf(format string, args ...interface{})
// Sync calls the underlying Core's Sync method, flushing any buffered log entries.
// Applications should take care to call Sync before exiting.
Sync() error
// SetLevel set the output log level.
SetLevel(output string, level Level)
// GetLevel get the output log level.
GetLevel(output string) Level
// WithFields set some user defined data to logs, such as uid, imei, etc.
// Fields must be paired.
// Deprecated: use With instead.
WithFields(fields ...string) Logger
// With add user defined fields to Logger. Fields support multiple values.
With(fields ...Field) Logger
}