logging

package
v0.0.0-...-06ecd44 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logging implements a Zap-based logger, configured to be GCE/Stackdriver-compatible.

Index

Constants

View Source
const DomainKey = "_domain"

DomainKey is the map key used for logging domains. Domains divide a source into sub-sources (see Logger.NewDomainLogger).

View Source
const HostKey = "_host"

HostKey is the map key used for logging the machine hostname (via os.Hostname; see NewLog).

View Source
const SourceKey = "_source"

SourceKey is the map key used for logging sources (typically the name of the application; see NewLog).

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldSet

type FieldSet []zapcore.Field

FieldSet is an alias for a slice of zapcore Fields. Functions that aggregate fields can return a FieldSet to allow further aggregation.

func (FieldSet) Append

func (f FieldSet) Append(fields ...zapcore.Field) FieldSet

Append appends fields to the current FieldSet.

func (FieldSet) AppendFieldSet

func (f FieldSet) AppendFieldSet(fields FieldSet) FieldSet

AppendFieldSet appends a FieldSet to the current FieldSet.

type Logger

type Logger zap.Logger

Logger is a Zap-based logger configured to be GCE/Stackdriver-compatible.

func NewLog

func NewLog(productionLogging bool, source string, fields ...zapcore.Field) (*Logger, error)

NewLog returns a new Logger instance. If 'productionLogging' is true, JSON logger is constructed which logs at the Info level (by default); if 'productionLogging' is false, a developent-oriented console logger is constructed which logs at the Debug level. 'source' is the optional source (e.g. application or service name) of the events; all logs under this logger and its domains will be tagged with the source, if one is provided. 'fields' is an optional set of fields to install in the logger instance.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zapcore.Field)

Debug logs development-related information that is not typically necessary for production. When choosing a logging level, you should assume that debug logging will be disabled in production environments.

func (*Logger) ErrorWithTrace

func (l *Logger) ErrorWithTrace(err error, msg string, fields ...zapcore.Field)

ErrorWithTrace logs an error and captures the current stack trace (at the cost of a small performance hit). ErrorWithTrace is appropriate for unexpected errors, where the stack trace will be useful in diagnosing the root cause. For expected / non-critical errors, you may wish to prefer Info with a zap.Error() field.

func (*Logger) Flush

func (l *Logger) Flush()

Flush tries to commit any buffered log messages.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zapcore.Field)

Info logs at a level suitable for production; the log should be *actionable information* that will be read by a human, or by a machine.

func (*Logger) NewDomainLogger

func (l *Logger) NewDomainLogger(domain string) *Logger

NewDomainLogger returns a new Logger instance, based on the current instance, with the provided domain. The domain is set via With() using a well-defined key.

Jump to

Keyboard shortcuts

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