log

package module
v0.0.0-...-ff6b9b9 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 4 Imported by: 4

README

log

Wraps the standard log package, adding levels, microsecond timestamp resolution, and other features.

Description

Levels

Supports the following levels

  • None
  • Trace
  • Debug
  • Info
  • Warn
  • Error

Default level is Info.

LOG_LEVEL environment variable sets the log level.

Outputs

Output defaults to os.Stderr, but can be directed to any supplied io.Writer, such as a file, buffer, 3rd party log ingest, etc.

Syslog (on Linux) can be supported by setting output to a syslog io.Writer

Usage

import "github.com/335is/log"

func main() {
    log.Tracef("%s", "Low level verbose log statment")
    log.Debugf("%s", "Default configuration loaded")
    log.Infof("%s", "Starting service version 1.2.3")
    log.Warnf("%s", "Something bad may happen")
    log.Errorf("%s", "Something bad just happened!")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

func Debugf(format string, vars ...interface{})

Debugf logs Debug level and above

func Errorf

func Errorf(format string, vars ...interface{})

Errorf logs Error level and above

func Infof

func Infof(format string, vars ...interface{})

Infof logs Info level and above

func SetLevel

func SetLevel(l Level)

SetLevel sets the current logging level

func SetWriter

func SetWriter(w io.Writer)

SetWriter sets the writer that our logger uses, such as os.Stderr, os.Stdout, a file writer, etc.

func Tracef

func Tracef(format string, vars ...interface{})

Tracef logs Trace level and above

func Warnf

func Warnf(format string, vars ...interface{})

Warnf logs Warn level and above

Types

type Level

type Level int

Level defines the logging level type

const (
	// None is no logging
	None Level = iota

	// Trace logs verbose details and, really should be metricss
	Trace

	// Debug logs Debug and above
	Debug

	// Info logs Info and above
	Info

	// Warn logs Warn and above
	Warn

	// Error logs Error and above
	Error
)

Log level controls the logging threshold, which log statements will be output. For example, Debug level will not output Trace statements, but will output Debug, Info, and the rest.

func Default

func Default() Level

Default returns the default log level LOG_LEVEL env var overrides the default of Info

func FromString

func FromString(s string) Level

FromString converts the string representation of level into its const It does a case-insensitive comparison Invalid level string returns -1

func GetLevel

func GetLevel() Level

GetLevel returns the current logging level

func (Level) String

func (l Level) String() string

String returns the level as a string

Jump to

Keyboard shortcuts

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