logger

package module
v0.0.0-...-581e055 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2014 License: BSD-2-Clause Imports: 8 Imported by: 5

README

logger - Logging framework for go

Simple logging framework for go. It supports different logging levels and has inheritance of that level to child loggers.

Installation

Using go get
$ go get github.com/AlexanderThaller/logger

This will clone the source of logger to $GOROOT/src/pkg/github.com/op/go-logging

After that you can use logger by importing github.com/AlexanderThaller/logger into your go application.

Example

package main

import (
  "github.com/AlexanderThaller/logger"
)

func init() {
  // Set application logger to Info (default is Notice)
  logger.SetLevel("application", logger.Info)
}

func main() {
  l := logger.New("application", "main")

  l.Notice("Starting")

  // This message will be shown because in the init function we set the
  // level of the "application" logger to Info
  l.Info("Some infos")

  // This message will be hidden because it is below the logger level
  // Info
  l.Debug("Debug Values")

  // Change the Level for the application.main logger to Debug
  l.SetLevel(logger.Debug)

  // This message will be shown because we set the level of the
  // "application.main" logger to Debug
  l.Debug("More debug values")
}

Documentation

The documentation can be found here: http://godoc.org/github.com/AlexanderThaller/logger

Documentation

Overview

Package logger provides a logging framework similar to those of python and haskell.

Index

Constants

This section is empty.

Variables

View Source
var (

	// SaveLoggerLevels will make the package save loggers which are only defined
	// by their parents if it is set to true.
	SaveLoggerLevels = true
)

Functions

func ImportLoggers

func ImportLoggers(lo map[Logger]string) (err error)

ImportLoggers sets the LogLevel for the given Loggers.

func NamePriority

func NamePriority(pr Priority) (pri string, err error)

NamePriority returns the string value of the given priority.

func SetFormat

func SetFormat(lo Logger, fo Format) error

SetFormat changes the message format for the given logger. Avaivable fields are:

Time: The time when the message is printed.

Logger: The name of the logger.

Priority: The priority of the logger.

Message: The output message.

The default Format is:

"[{{.Time}} {{.Logger}} {{.Priority}}] - {{.Message}}.\n"

func SetLevel

func SetLevel(lo Logger, pr Priority) (err error)

SetLevel sets the priority level for the given logger.

func SetNoColor

func SetNoColor(lo Logger, nc bool)

SetNoColor sets the nocolor flag for the given logger. If true no colors will be printed for the logger.

func SetOutput

func SetOutput(lo Logger, ou io.Writer) error

SetOutput sets the output parameter of the logger to the given io.Writer. The default is os.Stderr.

func SetTimeFormat

func SetTimeFormat(lo Logger, fo string) error

SetTimeFormat sets the TimeFormat which will be used in the message format for the specified logger

The default format is: RFC3339

Types

type Format

type Format string

Format represents the format which will be used to print the message for an logger.

type Logger

type Logger string

Logger represent different lognames and priorities. They can have parents and child loggers which will inherit the priority of the parent if it has none. The hirachy of loggers is represented through sepperation with dots ('.'). The root logger has the name '.'.

func New

func New(na ...string) (log Logger)

New will return a logger with the given name.

func (Logger) Alert

func (lo Logger) Alert(me ...interface{})

Alert logs a message with the Debug priority.

func (Logger) Critical

func (lo Logger) Critical(me ...interface{})

Critical logs a message with the Debug priority.

func (Logger) Debug

func (lo Logger) Debug(me ...interface{})

Debug logs a message with the Debug priority.

func (Logger) Emergency

func (lo Logger) Emergency(me ...interface{})

Emergency logs a message with the Debug priority.

func (Logger) Error

func (lo Logger) Error(me ...interface{})

Error logs a message with the Debug priority.

func (Logger) GetLevel

func (lo Logger) GetLevel() Priority

GetLevel returns the priority level of the logger.

func (Logger) Info

func (lo Logger) Info(me ...interface{})

Info logs a message with the Debug priority.

func (Logger) Log

func (lo Logger) Log(pr Priority, me ...interface{})

Log logs a message with the given priority.

func (Logger) Notice

func (lo Logger) Notice(me ...interface{})

Notice logs a message with the Debug priority.

func (Logger) SetFormat

func (lo Logger) SetFormat(fo Format)

SetFormat changes the message format for the Logger. Avaivable fields are:

Time: The time when the message is printed.

Logger: The name of the logger.

Priority: The priority of the logger.

Message: The output message.

The default Format is:

"[{{.Time}} {{.Logger}} {{.Priority}}] - {{.Message}}.\n"

func (Logger) SetLevel

func (lo Logger) SetLevel(pr Priority) (err error)

SetLevel sets the priority level for the Logger.

func (Logger) SetNoColor

func (lo Logger) SetNoColor(nc bool)

SetNoColor sets the nocolor flag for the given logger. If true no colors will be printed for the logger.

func (Logger) SetOutput

func (lo Logger) SetOutput(ou io.Writer)

SetOutput sets the output parameter of the logger to the given io.Writer. The default is os.Stderr.

func (Logger) SetTimeFormat

func (lo Logger) SetTimeFormat(fo string) error

SetTimeFormat sets the TimeFormat which will be used in the message format for the Logger

The default format is: RFC3339

func (Logger) Trace

func (lo Logger) Trace(me ...interface{})

Trace logs a message with the Trace priority.

func (Logger) Warning

func (lo Logger) Warning(me ...interface{})

Warning logs a message with the Debug priority.

type Priority

type Priority int

Priority defines how important a log message is. Loggers will output messages which are above their priority level.

const (
	Trace Priority = iota
	Debug
	Info
	Notice
	Warning
	Error
	Critical
	Alert
	Emergency
	Disable
)

Different priority levels ordered by their severity.

const (
	DefaultPriority   Priority = Notice
	DefaultSepperator          = "."
)

DefaultPriority of the root logger.

func GetLevel

func GetLevel(lo Logger) (pri Priority)

GetLevel returns the priority level of the given logger.

func ParsePriority

func ParsePriority(pr string) (Priority, error)

ParsePriority tries to parse the priority by the given string.

Jump to

Keyboard shortcuts

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