logger

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LongBodyThreshold = 100

LongBodyThreshold is the body length threshold beyond which the body will be written to a file. Otherwise, if the content is textual, it is written inline in the log.

This is ignored unless level == WithHeadersAndBodies.

View Source
var TimeFormat = "15:04:05"

TimeFormat sets the appearance of the timestamp that prefixes each logged message. The default is "15:04:05". See time.Format.

Functions

func SyncWriter

func SyncWriter(w io.Writer) io.Writer

SyncWriter wraps a io.Writer so that each call to Write is protected by a mutex. Use this to wrap the call to writer's Write method if it is not thread safe.

Note that you do not need this wrapper for os.File Write operations on POSIX and Windows systems as they are already thread-safe.

Types

type Logger

type Logger func(item *logging.LogItem)

Logger is a function that processes log items, e.g. by writing them to a log file.

func FileLogger

func FileLogger(name string, fs afero.Fs) (Logger, error)

FileLogger returns a new Logger writing to a file in dir. The name of the file is provided. The same directory specifies where request and response bodies will be written as files. The current directory is used if this is "." or blank.

func LogWriter

func LogWriter(out io.Writer, fs afero.Fs) Logger

LogWriter returns a new Logger. Log items are written without overlapping to ensure the log is easily readable. The filesystem fs specifies where request and response bodies will be written as files, if enabled by the item's level. If fs is nil, the OS filesystem is used.

Jump to

Keyboard shortcuts

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