Documentation ¶
Index ¶
- Constants
- Variables
- func Any(key string, value interface{}) zap.Field
- func Error(err error) zap.Field
- func InitLogger(cfg config.Logging, fileName string) error
- func Int(key string, val int) zap.Field
- func Int32(key string, val int32) zap.Field
- func Int64(key string, val int64) zap.Field
- func IsDebug() bool
- func IsTerminal(f *os.File) bool
- func LevelString(l zapcore.Level) string
- func Reflect(key string, val interface{}) zap.Field
- func SimpleAccessLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func SimpleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func SimpleTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Stack() zap.Field
- func String(key, val string) zap.Field
- func Uint16(key string, val uint16) zap.Field
- func Uint32(key string, val uint32) zap.Field
- type Color
- type Logger
Constants ¶
const ( HTTPModule = "http_access" SlowSQLModule = "slow_sql" )
const ( AccessLogFileName = "access.log" SlowSQLLogFileName = "show_sql.log" )
Variables ¶
var ( AccessLog = GetLogger(HTTPModule, "Access") SlowSQLLog = GetLogger(SlowSQLModule, "SQL") )
var ( // IsCli represents if lin-cli command-line. IsCli = false // RunningAtomicLevel supports changing level on the fly RunningAtomicLevel = zap.NewAtomicLevelAt(zapcore.InfoLevel) )
Functions ¶
func Any ¶
Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
func InitLogger ¶
InitLogger initializes a zap logger from user config
func IsTerminal ¶
IsTerminal checks if the stdOut is a terminal or not
func LevelString ¶
LevelString returns a upper-case ASCII representation of the log level.
func Reflect ¶
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func SimpleAccessLevelEncoder ¶
func SimpleAccessLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
SimpleAccessLevelEncoder serializes access log level
func SimpleLevelEncoder ¶
func SimpleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
SimpleLevelEncoder serializes a Level to a upper case string. For example, InfoLevel is serialized to "INFO".
func SimpleTimeEncoder ¶
func SimpleTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
SimpleTimeEncoder serializes a time.Time to a simplified format without timezone
func Stack ¶
Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is wrapper for zap logger with module, it is singleton.
func (*Logger) Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.