log

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 8 Imported by: 0

README

Log

Coming Soon™

Documentation

Overview

Package log is a wrapper around the zap logger, providing easier integration of logging into applications and packages.

Index

Constants

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

Variables

View Source
var Levels = map[string]Level{
	"debug": DebugLevel,
	"info":  InfoLevel,
	"warn":  WarnLevel,
	"error": ErrorLevel,
	"panic": PanicLevel,
	"fatal": FatalLevel,
}

Levels contains a map of level names with their associated Level type.

Functions

func Check

func Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry

Check returns a CheckedEntry if logging a message at the specified level is enabled. It's a completely optional optimization; in high-performance applications, Check can help avoid allocating a slice to hold fields.

func Core

func Core() zapcore.Core

Core returns the Logger's underlying zapcore.Core.

func Debug

func 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 Error

func 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 Fatal

func Fatal(msg string, fields ...zap.Field)

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

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Info

func 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 Log

func Log() *zap.Logger

Log returns the globally configured logger instance.

func Named

func Named(s string) *zap.Logger

Named adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.

func Panic

func Panic(msg string, fields ...zap.Field)

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

The logger then panics, even if logging at PanicLevel is disabled.

func Register

func Register(l *Logger) error

Register registers a Logger globally. Register can be called multiple times, but only the first call will register a logger, all subsequent calls are a no-op.

func RegisterFromFlags

func RegisterFromFlags(f Flags) (func(), error)

RegisterFromFlags creates and registers a new logger using CLI flags.

func Sync

func Sync()

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Warn

func 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.

func With

func With(fields ...zap.Field) *zap.Logger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

func WithOptions

func WithOptions(opts ...zap.Option) *zap.Logger

WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.

Types

type Config

type Config struct {
	// Encoder is the encoder that should be used to encode log output.
	Encoder zapcore.Encoder `json:"encoder"`
	// Level is the level at which logs will be output.
	Level Level `json:"level"`
	// Output is the writer that encoded logs will be output to.
	Output io.Writer `json:"output"`
}

Config represents the configuration for a Logger.

type Flags

type Flags struct {
	Encoder string `enum:"console,json,logfmt" default:"logfmt"`
	Level   string `enum:"debug,info,warn,error,panic,fatal" default:"info"`
}

Flags are CLI flags for use with [kong](https://github.com/alecthomas/kong)

type Level

type Level = zapcore.Level

Level is a logging priority, higher levels are more important.

type Logger

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

Logger likes logs.

func New

func New(c *Config) (*Logger, error)

New returns a new configured Logger.

func (*Logger) Logger

func (l *Logger) Logger() (*zap.Logger, error)

Logger returns a zap Logger that can be used to actually log things.

Directories

Path Synopsis
Package encoder implements log encoders used to output logs in varying ways.
Package encoder implements log encoders used to output logs in varying ways.

Jump to

Keyboard shortcuts

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