zaplogi

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

zaplogi provides a zaplogger interface replacement

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = Level(zapcore.DebugLevel)
	// InfoLevel is the default logging priority.
	InfoLevel = Level(zapcore.InfoLevel)
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = Level(zapcore.WarnLevel)
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = Level(zapcore.ErrorLevel)
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = Level(zapcore.DPanicLevel)
	// PanicLevel logs a message, then panics.
	PanicLevel = Level(zapcore.PanicLevel)
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = Level(zapcore.FatalLevel)

	MinLevel = DebugLevel
	MaxLevel = FatalLevel
)

Log Levels, this section is taken directly from zapcore

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level zapcore.Level

func (Level) MarshalText

func (l Level) MarshalText() ([]byte, error)

MarshalText marshals the Level to text. Note that the text representation drops the -Level suffix (see example).

func (Level) String

func (l Level) String() string

String returns a lower-case ASCII representation of the log level.

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText expects the text representation of a Level to drop the -Level suffix (see example).

In particular, this makes it easy to configure logging levels using YAML, TOML, or JSON files.

type LogConfig

type LogConfig struct {
	// ConsoleLog determines if you want to log to the console.
	ConsoleLog     bool `json:"console_log" yaml:"console-log"`
	RootCallerSkip int  `json:"root_caller_skip" yaml:"root-caller-skip"`
	// LogFileConfigs contain the various rotational file configurations
	LogFileConfigs []LogFileConfig `json:"log_file_configs" yaml:"log-file-configs"`
}

LogConfig encapsulates the initialisation of the zap logger

type LogFileConfig

type LogFileConfig struct {
	// LoggerName is the logger's name to log to. If specified, It will only
	// log to this file when the logger's name is equal to LoggerName.
	// This gives fine control over which files that you want to log to.
	LoggerName string
	// LogRange is the level range to log under. If not specified,
	// defaul to [InfoLevel, InfoLevel]
	LogRange [2]Level
	// Type determines what type of log file to use. If specified,
	// accepts "lumberjack" or "logfeller" as the 2 main log file handler configs
	// to marshal as attributes via the `file_handler` field.
	// Check the respective docs on usage via JSON/YAML marshalling
	// 	- `https://pkg.go.dev/github.com/lohvht/logfeller@v1.0.0`
	// 	- `https://pkg.go.dev/gopkg.in/natefinch/lumberjack.v2`
	// Otherwise, no io.Writer will be configured. Omit this field if you would
	// like to set the writer manually.
	Type LogFileType
	io.Writer
}

LogFileConfig is the configuration for the log file If unmarshalling directly from JSON/YAML, take note

func (*LogFileConfig) UnmarshalJSON

func (c *LogFileConfig) UnmarshalJSON(data []byte) error

func (*LogFileConfig) UnmarshalYAML

func (c *LogFileConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type LogFileType

type LogFileType int
const (
	NoWriter LogFileType = iota
	Lumberjack
	Logfeller
)

func (LogFileType) MarshalText

func (t LogFileType) MarshalText() ([]byte, error)

func (LogFileType) String

func (t LogFileType) String() string

String returns a lower-case ASCII representation of the log file type

func (*LogFileType) UnmarshalText

func (t *LogFileType) UnmarshalText(text []byte) error

UnmarshalText unmarshals text to a log file type. In particular, this makes it easy to configure log file types using YAML, TOML, or JSON files.

type Logger

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

func NewConsole

func NewConsole() *Logger

NewConsole returns a logger that will only log to console (stdout and stderr). NewConsole implement logger.Logger and this logger is the initial logger for the package.

func NewDefault

func NewDefault(logDir string, backups int, logConsole bool) *Logger

NewDefault creates 2 log files with max backups that rotates every day at 12am.

func NewWithConfig

func NewWithConfig(c LogConfig) (*Logger, error)

NewWithConfig returns a Logger with the given config. Logger implemen logger.Logger interface, so you may use SetDefault to replace the default logger. With this function, you can customise the log output and how you would want to initialise the logger. However, usually New will suffice.

func (*Logger) CallSkip

func (l *Logger) CallSkip(skips int) iface.Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, keysAndValues ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(template string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, keysAndValues ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(template string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, keysAndValues ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(template string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, keysAndValues ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(template string, args ...interface{})

func (*Logger) Named

func (l *Logger) Named(loggerName string) iface.Logger

func (*Logger) Panic

func (l *Logger) Panic(msg string, keysAndValues ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(template string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(msg string, keysAndValues ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(template string, args ...interface{})

func (*Logger) With

func (l *Logger) With(args ...interface{}) iface.Logger

Jump to

Keyboard shortcuts

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