log

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

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

Go to latest
Published: Oct 24, 2016 License: MIT Imports: 5 Imported by: 5

README

go-simple-logger

Go Report Card

  import "github.com/necrophonic/log"

Very simple logger for golang. Similar to Go's core log but with granular log levels (trace, debug, warn, error, info, fatal) and always outputs unbuffered to STDOUT and STDERR as appropriate - it's up to client to redirect this to somewhere more appropriate if desired.

import "github.com/necrophonic/log"

// LevelTrace > LevelDebug > LevelWarn > LevelInfo > LevelError > LevelNone
log.Init(log.LevelInfo)

// Log at TRACE level - would be suppressed in example
// due to level being set at INFO.
log.Trace("Trace this out")

// Log at INFO level - equivalent operation to fmt.Print
log.Info("This is more informational")

// Log at INFO level with formatting - equivalent operation to fmt.Printf
log.Infof("This %s is nice", "thing")

Functions

Provides functions for each level of granularity. Each has both "regular" (equivalent to fmt.Print) and "formatted" (equivalent to fmt.Printf) versions.

See go doc for details

  • Fatal(v ...interface{})
  • Fatalf(format string, v ...interface{})
  • Trace(v ...interface{})
  • Tracef(format string, v ...interface{})
  • Debug(v ...interface{})
  • Debugf(format string, v ...interface{})
  • Info(v ...interface{})
  • Infof(format string, v ...interface{})
  • Warn(v ...interface{})
  • Warnf(format string, v ...interface{})
  • Error(v ...interface{})
  • Errorf(format string, v ...interface{})

Log levels

If you've ever used something like log4j then you should be familiar with levels.

Essentially you set a level for output and only logging statements that match or exceed that level will be output.

The hierarchy of levels is thus (high to low):

  • None (no log output apart from Fatal)
  • Error
  • Info
  • Warn
  • Debug
  • Trace (everything)

Licence

This code is licenced under the permissive MIT licence. Basically, you can do whatever you want as long as you include the original copyright and license notice in any copy of the software/source. Read this for a summary.

Documentation

Overview

Package log defines a generic log implemetation with differing granularity levels.

The logger is built on top of the standard golang log package.

Index

Constants

View Source
const (
	LevelNone  = 0
	LevelError = 1
	LevelInfo  = 2
	LevelWarn  = 3
	LevelDebug = 4
	LevelTrace = 5
)

Level setting constants

LevelTrace > LevelDebug > LevelWarn > LevelInfo > LevelError > LevelNone

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug provides debug level logging in the manner of fmt.Print

func Debugf

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

Debugf provides debug level logging in the manner of fmt.Printf

func Error

func Error(v ...interface{})

Error provides error level logging in the manner of fmt.Print

func Errorf

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

Errorf provides error level logging in the manner of fmt.Printf

func Fatal

func Fatal(v ...interface{})

Fatal provides fatal level logging in the manner of fmt.Print. Being fatal it will log, and then it will exit the current process.

func Fatalf

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

Fatalf provides fatal level logging in the manner of fmt.Printf. Being fatal it will log, and then it will exit the current process.

func Info

func Info(v ...interface{})

Info provides info level logging the manner of fmt.Print

func Infof

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

Infof provides info level logging in the manner of fmt.Printf

func Init

func Init(l int) error

Init initialises the logger. This must be called at least once before and of the functions can be called.

func InitFromString

func InitFromString(l string) error

InitFromString initialises the logger with Init(). Takes a string rather than a numerical levvel

func Trace

func Trace(v ...interface{})

Trace provides trace level logging in the manner of fmt.Print

func Tracef

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

Tracef provides trace level logging in the manner of fmt.Printf

func Warn

func Warn(v ...interface{})

Warn provides warning level logging in the manner of fmt.Print

func Warnf

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

Warnf provides warning level logging in the manner of fmt.Printf

Types

type DefaultLogger

type DefaultLogger struct {
	Level int
}

DefaultLogger defines a simple logging package

type Logger

type Logger interface {
	Fatal(v ...interface{})
	Trace(v ...interface{})
	Debug(v ...interface{})
	Info(fv ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})

	Fatalf(format string, v ...interface{})
	Tracef(format string, v ...interface{})
	Debugf(format string, v ...interface{})
	Infof(fformat string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
}

Logger is the default interface all logs must implement in this library

Jump to

Keyboard shortcuts

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