logger

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	HTTPModule    = "http_access"
	SlowSQLModule = "slow_sql"
)
View Source
const (
	AccessLogFileName  = "access.log"
	SlowSQLLogFileName = "show_sql.log"
)

Variables

View Source
var (
	AccessLog  = GetLogger(HTTPModule, "Access")
	SlowSQLLog = GetLogger(SlowSQLModule, "SQL")
)
View Source
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

func Any(key string, value interface{}) zap.Field

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 Error

func Error(err error) zap.Field

Error is shorthand for the common idiom NamedError("error", err).

func InitLogger

func InitLogger(cfg config.Logging, fileName string) error

InitLogger initializes a zap logger from user config

func Int

func Int(key string, val int) zap.Field

Int is a shortcut for int32

func Int32

func Int32(key string, val int32) zap.Field

Int32 constructs a field with the given key and value.

func Int64

func Int64(key string, val int64) zap.Field

Int64 constructs a field with the given key and value.

func IsDebug

func IsDebug() bool

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal checks if the stdOut is a terminal or not

func LevelString

func LevelString(l zapcore.Level) string

LevelString returns a upper-case ASCII representation of the log level.

func Reflect

func Reflect(key string, val interface{}) zap.Field

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

func Stack() zap.Field

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.

func String

func String(key, val string) zap.Field

String constructs a field with the given key and value.

func Uint16

func Uint16(key string, val uint16) zap.Field

Uint16 constructs a field with the given key and value.

func Uint32

func Uint32(key string, val uint32) zap.Field

Uint32 constructs a field with the given key and value.

Types

type Color

type Color uint8

Color represents a text color.

const (
	Black Color = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Foreground colors.

func (Color) Add

func (c Color) Add(s string) string

Add adds the coloring to the given string.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is wrapper for zap logger with module, it is singleton.

func GetLogger

func GetLogger(module, role string) *Logger

GetLogger return logger with module name

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

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

func (l *Logger) Error(msg string, fields ...zap.Field)

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.

func (*Logger) GetLogger

func (l *Logger) GetLogger() *zap.Logger

GetLogger returns under logger impl.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL