logging

package
v0.0.0-...-c32710b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logging provides an application logging solution by wrapping an existing logging library. The functionality is provided as an interface so that applications only need to depend on this logic. The underlying logging implementation can be easily switched if this is a requirement

Index

Constants

View Source
const (
	// LogFieldNameFunction identifies the function in structured logging
	LogFieldNameFunction = "function"

	// RequestIDKey identifies a reqest in structured logging
	RequestIDKey = "requestID"

	// ApplicationNameKey identifies the application in structured logging
	ApplicationNameKey = "appName"

	// HostIDKey identifies the host in structured logging
	HostIDKey = "hostID"

	// ErrorKey identifies errors
	ErrorKey = "err"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValue

type KeyValue interface {
	Read() []string
}

KeyValue defines a combination of Key and Value

func ErrV

func ErrV(err error) KeyValue

ErrV is a specific error value

func LogV

func LogV(key, value string) KeyValue

LogV creates a KeyValue pair

type LogConfig

type LogConfig struct {
	FilePath string
	LogLevel string
	Trace    TraceConfig
	// GrayLogServer defines the address of a log-aggregator using Graylog
	GrayLogServer string
}

LogConfig specifies logging settings for

type Logger

type Logger interface {
	// implement the io.Closer interface
	io.Closer
	// Info logs a message and values with logging-level INFO
	Info(msg string, keyvals ...KeyValue)
	// Info logs a message and values with logging-level DEBUG
	Debug(msg string, keyvals ...KeyValue)
	// Warn logs a message and values with logging-level WARNING
	Warn(msg string, keyvals ...KeyValue)
	// Error logs a message and values with logging-level ERROR
	Error(msg string, keyvals ...KeyValue)
	// InfoRequest is used to log a *http.Request (with a Trace-ID, if available)
	InfoRequest(msg string, req *http.Request, keyvals ...KeyValue)
	// ErrorRequest is used to log a *http.Request (with a Trace-ID, if available)
	ErrorRequest(msg string, req *http.Request, keyvals ...KeyValue)
}

Logger interface defines common logging functions for applications

func New

func New(conf LogConfig, env config.Environment) Logger

New returns a Logger instance which is used to perform the logging

func NewNop

func NewNop() Logger

NewNop is useful for testing, it creates a zero / noop instance

type TraceConfig

type TraceConfig struct {
	AppName string
	HostID  string
}

TraceConfig is used to correlate logging-entries

Jump to

Keyboard shortcuts

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