logger

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: ISC Imports: 8 Imported by: 67

README

logger - A simple logging layer on top of seelog

Implements multiple log channels to a single rotated log file. Log levels are considered a simple hierarchy with each channel having a single limit, below which logs to that channel are skipped.

The makeloggerinterface is a program to generate the interface.go file to simplify its maintenance.

Documentation

Overview

A simple logging layer on top of seelog

Implements multiple log channels to a single rotated log file. Log levels are considered a simple hierarchy with each channel having a single limit, below which logs to that channel are skipped.

Index

Constants

View Source
const (
	Major   = "0"
	Minor   = "3"
	Patch   = "4"
	Version = Major + "." + Minor + "." + Patch
)
View Source
const DefaultLevel = "error"

the initial level for unknown tags

View Source
const DefaultTag = "DEFAULT"

the tagname reserved to set the default level for unknown tags

Variables

This section is empty.

Functions

func Critical

func Critical(message string)

global logging message

func Criticalf

func Criticalf(format string, arguments ...interface{})

global logging formatted message

func Finalise

func Finalise()

flush all channels and shutdown the logger

func Flush

func Flush()

flush all channels

func Initialise

func Initialise(configuration Configuration) error

Set up the logging system

func Panic

func Panic(message string)

global logging message + panic

func PanicIfError

func PanicIfError(message string, err error)

conditional panic

func Panicf

func Panicf(format string, arguments ...interface{})

global logging formatted message + panic

Types

type Configuration

type Configuration struct {
	Directory string            `libucl:"directory" hcl:"directory" json:"directory"`
	File      string            `libucl:"file" hcl:"file" json:"file"`
	Size      int               `libucl:"size" hcl:"size" json:"size"`
	Count     int               `libucl:"count" hcl:"count" json:"count"`
	Levels    map[string]string `libucl:"levels" hcl:"levels" json:"levels"`
	Console   bool              `libucl:"console" hcl:"console" json:"console"`
}

initial configuration for the logger

example of use (with structure tags for config file parsing)

type AppConfiguration struct {
  …
  Logging logger.Configuration `libucl:"logging" hcl:"logging" json:"logging"`
  …
}

err := logger.Initialise(conf.Logging)
if nil != err {  // if failed then display message and exit
  exitwithstatus.Message("logger error: %s", err)
}
defer logger.Finalise()

example of ucl/hcl configuration section

logging {
  directory = "/var/lib/app/log"
  file = "app.log"
  size = 1048576
  count = 50
  #console = true # to duplicate messages to console (default false)
  levels {
    DEFAULT = "info"
    system = "error"
    main = "warn"
  }
}

type L

type L struct {
	sync.Mutex
	// contains filtered or unexported fields
}

The logging channel structure example of use

var log *logger.L
log := logger.New("sometag")

log.Debugf("value: %d", value)

func New

func New(tag string) *L

Open a new logging channel with a specified tag

func (*L) Critical

func (l *L) Critical(message string)

Log a simple string e.g.

log.Critical("a log message")

func (*L) Criticalc

func (l *L) Criticalc(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Criticalc(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Criticalf

func (l *L) Criticalf(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Criticalf("the value = %d", xValue)

func (*L) Debug

func (l *L) Debug(message string)

Log a simple string e.g.

log.Debug("a log message")

func (*L) Debugc

func (l *L) Debugc(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Debugc(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Debugf

func (l *L) Debugf(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Debugf("the value = %d", xValue)

func (*L) Error

func (l *L) Error(message string)

Log a simple string e.g.

log.Error("a log message")

func (*L) Errorc

func (l *L) Errorc(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Errorc(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Errorf

func (l *L) Errorf(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Errorf("the value = %d", xValue)

func (*L) Flush

func (l *L) Flush()

flush messages

func (*L) Info

func (l *L) Info(message string)

Log a simple string e.g.

log.Info("a log message")

func (*L) Infoc

func (l *L) Infoc(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Infoc(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Infof

func (l *L) Infof(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Infof("the value = %d", xValue)

func (*L) Trace

func (l *L) Trace(message string)

Log a simple string e.g.

log.Trace("a log message")

func (*L) Tracec

func (l *L) Tracec(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Tracec(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Tracef

func (l *L) Tracef(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Tracef("the value = %d", xValue)

func (*L) Warn

func (l *L) Warn(message string)

Log a simple string e.g.

log.Warn("a log message")

func (*L) Warnc

func (l *L) Warnc(closure func() string)

Log from a closure, any function returning a string is suitable and the closure will only be executed if the log level is low enough. This allows complex e.g.

log.Warnc(func() string {
    return fmt.Sprintf("the sin(%f) = %f", x, math.sin(x))
})

func (*L) Warnf

func (l *L) Warnf(format string, arguments ...interface{})

Log a formatted string with arguments lige fmt.Sprintf() e.g.

log.Warnf("the value = %d", xValue)

Directories

Path Synopsis
generate the various logging calls
generate the various logging calls

Jump to

Keyboard shortcuts

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