log

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

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

Go to latest
Published: Oct 24, 2017 License: MIT Imports: 6 Imported by: 41

README

log - Flexible Logging for Go

Travis CI

Setup logging with SetupLogging():

  • Type: logging mode to use - file, syslog, console
  • Level: debug, info, error, etc. (See all levels below.)
  • Facility: syslog facility to log to - daemon, misc, etc.
  • File: path to log to file if in file mode.

e.g.:

log.SetupLogging(log.LogConfig{
    Type:  "console",
    Level: "warning"
})

If logging is not setup, then the messages will simply go to stdout. If logging cannot be setup for file or syslog, then the default stdout will be used. An error message will print to stderr to notify you if this occurs.

The following log levels are defined, in decreasing verbosity / increasing criticality:

  • Debug
  • Info
  • Notice
  • Warn
  • Error
  • Crit
  • Alert
  • Emerg

Usage

Usage is the same as Sprintf/Printf statements - simply append an f to the desired level. e.g.:

dbug_mesg := "This isn't a bug."
log.Debugf("I really need to know this in debug mode: %s", msg)

Contributing

  1. Fork the repo
  2. Write your code in a feature branch
  3. Create a new Pull Request

Documentation

Overview

Daemons need to log. This package makes that easy, allowing you to configure logging to syslog, a file, or console (stdout), with syslog style log levels.

Since this logging mechanism supports non-syslog output, filtering based on log levels is done in-application, so you'll want to accept debug messages and above in syslog configs.

Simply call SetupLogging(), passing it a reference to a LogConfig struct and start logging! If you happen to log something prior to setting up logging, messages will print to stderr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alertf

func Alertf(msg string, args ...interface{})

Logs a formatted Alert message. Supports fmt.Sprintf style arguments.

func Critf

func Critf(msg string, args ...interface{})

Logs a formatted Crit message. Supports fmt.Sprintf style arguments.

func Debugf

func Debugf(msg string, args ...interface{})

Logs a formatted Debug message. Supports fmt.Sprintf style arguments.

func Emergf

func Emergf(msg string, args ...interface{})

Logs a formatted Emerg message. Supports fmt.Sprintf style arguments.

func Errorf

func Errorf(msg string, args ...interface{})

Logs a formatted Error message. Supports fmt.Sprintf style arguments.

func Infof

func Infof(msg string, args ...interface{})

Logs a formatted Info message. Supports fmt.Sprintf style arguments.

func IsAlert

func IsAlert() bool

Returns true if the looger will log ALERT messages

func IsCritical

func IsCritical() bool

Returns true if the looger will log CRIT messages

func IsDebug

func IsDebug() bool

Returns true if the looger will log DEBUG messages

func IsEmergency

func IsEmergency() bool

Returns true if the looger will log EMERG messages

func IsError

func IsError() bool

Returns true if the looger will log ERR messages

func IsInfo

func IsInfo() bool

Returns true if the looger will log INFO messages

func IsNotice

func IsNotice() bool

Returns true if the looger will log NOTICE messages

func IsTrace

func IsTrace() bool

Returns true if the looger will log TRACE messages

func IsWarning

func IsWarning() bool

Returns true if the looger will log WARNING messages

func LogLevel

func LogLevel() syslog.Priority

Retreives the currently configured log level

func Noticef

func Noticef(msg string, args ...interface{})

Logs a formatted Notice message. Supports fmt.Sprintf style arguments.

func SetupLogging

func SetupLogging(cfg LogConfig)

func Tracef

func Tracef(msg string, args ...interface{})

Logs a formatted Trace message. Supports fmt.Sprintf style arguments.

func Warnf

func Warnf(msg string, args ...interface{})

Logs a formatted Warning message. Supports fmt.Sprintf style arguments.

Types

type LogConfig

type LogConfig struct {
	Type     string // logging mode to use - file, syslog, console
	Level    string // Syslog level to log at (debug, info, notice, error, etc)
	Facility string // Syslog facility to log to (daemon, misc, etc)
	File     string // Path that will be logged to if in file mode
}

Jump to

Keyboard shortcuts

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