log

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 6 Imported by: 17

Documentation

Overview

Package log provides an intentionally barebones logging system. It is designed to allow packages to expose additional information that may be valuable to developers, without having that information clutter the experience for end users.

As a package developer, create a Logger object by calling GetLogger with a name that identifies your package.

logger := log.NewLogger("mypackage")

Now you can emit Info and Debug events. Info should be used for details about the flow and behavior of your package, while Debug contains lower-level info about the actions being taken. As an example, "Parsing the config file" would be an Info message, while "Here's the result of parsing the config file: %+v" would be a Debug message.

The Info() and Debug() methods accept key-value entries for structured logging. InfoMsg() and DebugMsg() are wrappers around that, for simple logs whose only key is "msg".

Additionally, the Logger object supports setting Fields, which will be applied to any events logged via that Logger.

By default, no logs are ever displayed. To change the verbosity level, set the "LOG_LEVEL" environment variable to either "INFO" or "DEBUG". Setting it to INFO will show only Info level messages; setting it to DEBUG will show both Info and Debug level messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	Fields map[string]string
}

Logger carries template event fields and allows for logging events

func NewLogger

func NewLogger(name string) Logger

NewLogger returns a logger with a "name" field populated

func (Logger) Debug

func (l Logger) Debug(fields map[string]string)

Debug logs an event at the DEBUG level

func (Logger) DebugMsg

func (l Logger) DebugMsg(msg string)

DebugMsg logs an event at the DEBUG level with a string message

func (Logger) DebugMsgf

func (l Logger) DebugMsgf(msg string, args ...interface{})

DebugMsgf logs an event at the DEBUG level with a formatted string message

func (Logger) Info

func (l Logger) Info(fields map[string]string)

Info logs an event at the INFO level

func (Logger) InfoMsg

func (l Logger) InfoMsg(msg string)

InfoMsg logs an event at the INFO level with a string message

func (Logger) InfoMsgf

func (l Logger) InfoMsgf(msg string, args ...interface{})

InfoMsgf logs an event at the INFO level with a formatted string message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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