logging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package logging provides a dead-simple, level-aware logging facility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(format string, v ...interface{})

Debug logs the given message with DEBUG level.

func Error

func Error(format string, v ...interface{})

Error logs the given message with ERROR level.

func Fatal

func Fatal(format string, v ...interface{})

Fatal logs the given message with ERROR level and exits (same as log.Fatal).

func Info

func Info(format string, v ...interface{})

Info logs the given message with INFO level.

func SetLevel

func SetLevel(level Level)

SetLevel sets the logging level of the default logger.

func Warn

func Warn(format string, v ...interface{})

Warn logs the given message with WARN level.

Types

type Level

type Level uint8

Level defines all available log levels.

const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
)

The various log levels.

func LevelFromString

func LevelFromString(s string) (*Level, error)

LevelFromString parses a string and returns the approriate Level with the same name. If no such Level exists, a non-nil error is returned.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Debug(format string, v ...interface{})
	Info(format string, v ...interface{})
	Warn(format string, v ...interface{})
	Error(format string, v ...interface{})
	Fatal(format string, v ...interface{})
}

A Logger is used to write a string to some output using a certain log level that is part of the written string.

func NewDefaultLevelLogger

func NewDefaultLevelLogger(prefix string) Logger

NewDefaultLevelLogger creates a new logging object. The log level is inherited from the default logger which is set via SetLevel. The optional prefix is prepended to each log output.

func NewLogger

func NewLogger(level Level, prefix string) Logger

NewLogger creates a new logging object that only logs messages above the given level and swallows all others. The optional prefix is prepended to each log output.

Jump to

Keyboard shortcuts

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