logger

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IsCli represents if command-line.
	IsCli = false

	// RunningAtomicLevel supports changing level on the fly
	RunningAtomicLevel = zap.NewAtomicLevelAt(zapcore.InfoLevel)

	AccessLogModule = "AccessLog"
	DefaultLogger   atomic.Value
)

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(fileName string, setting Setting, cfg *zapcore.EncoderConfig, options ...zap.Option) (*zap.Logger, error)

InitLogger initializes a zap logger from user config

func Int

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

Int is a shortcut for int.

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 RegisterLogger

func RegisterLogger(module string, logger *zap.Logger, ignoreModuleAndRole bool)

func SimpleAccessLevelEncoder added in v0.0.4

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 interface {
	// 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.
	Debug(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.
	Info(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.
	Warn(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.
	Error(msg string, fields ...zap.Field)
}

logger is wrapper for zap logger with module.

func GetLogger

func GetLogger(module, role string) Logger

GetLogger return logger with module name

type Setting

type Setting struct {
	Dir        string     `env:"DIR" toml:"dir"`
	Level      string     `env:"LEVEL" toml:"level"`
	MaxSize    ltoml.Size `env:"MAX_SIZE" toml:"maxsize"`
	MaxBackups uint16     `env:"MAX_BACKUPS" toml:"maxbackups"`
	MaxAge     uint16     `env:"MAX_AGE" toml:"maxage"`
}

Setting represents a logging configuration.

func NewDefaultSetting

func NewDefaultSetting() *Setting

NewDefaultSetting returns a new default logging setting.

func (*Setting) TOML

func (l *Setting) TOML(prefix string) string

TOML returns logger setting's toml config string.

Jump to

Keyboard shortcuts

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