gol

package module
v0.0.0-...-6108c1c Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2015 License: Apache-2.0 Imports: 8 Imported by: 1

README

gol

gol is an extended logger for go, that can log to a console, file and syslog backend via a single interface. It supports multiple logging channels and the output can be filtered using a mask. On top of this, multiple of backends can be used at the same time.

See godoc for more details.

Usage

package main

import (
	"fmt"

	"github.com/simia-tech/gol"
)

func main() {
	gol.Initialize(
		&gol.Configuration{Backend: "console", Mask: "all", Color: true},
		&gol.Configuration{Backend: "syslog", Prefix: "gol-test"})

	gol.Info("number %d", 1)

	error := fmt.Errorf("nasty!")
	gol.Handle(error)
}

Documentation

Overview

gol is an extended logger for go, that can log to a console, file and syslog backend via a single interface. It supports multiple logging channels and the output can be filtered using a mask. On top of this, multiple of backends can be used at the same time.

Index

Constants

View Source
const (
	BACKEND_CONSOLE backend = "console"
	BACKEND_FILE    backend = "file"
	BACKEND_SYSLOG  backend = "syslog"
)
View Source
const (
	LEVEL_CRITICAL level = 1 << iota
	LEVEL_ERROR
	LEVEL_WARNING
	LEVEL_INFO
	LEVEL_DEBUG
	LEVEL_PROTOCOL
)
View Source
const (
	MASK_ALL     mask = mask(LEVEL_CRITICAL) | mask(LEVEL_ERROR) | mask(LEVEL_WARNING) | mask(LEVEL_INFO) | mask(LEVEL_DEBUG) | mask(LEVEL_PROTOCOL)
	MASK_DEBUG   mask = mask(LEVEL_CRITICAL) | mask(LEVEL_ERROR) | mask(LEVEL_WARNING) | mask(LEVEL_INFO) | mask(LEVEL_DEBUG)
	MASK_DEFAULT mask = mask(LEVEL_CRITICAL) | mask(LEVEL_ERROR) | mask(LEVEL_WARNING) | mask(LEVEL_INFO)
	MASK_WARNING mask = mask(LEVEL_CRITICAL) | mask(LEVEL_ERROR) | mask(LEVEL_WARNING)
)

Variables

This section is empty.

Functions

func Critical

func Critical(format string, values ...interface{})

Critical uses format and values to generate a log message on the critical channel.

func Debug

func Debug(format string, values ...interface{})

Debug uses format and values to generate a log message on the debug channel.

func Error

func Error(format string, values ...interface{})

Error uses format and values to generate a log message on the error channel.

func Handle

func Handle(err error, levels ...level)

Handle takes the given error and writes it to all channels that correspond to the given levels. If no level is given, the error will be published on the error channel.

func Info

func Info(format string, values ...interface{})

Info uses format and values to generate a log message on the info channel.

func Initialize

func Initialize(configurations ...*Configuration) error

Initialize sets up gol with a number of given configurations. Each configuration specified a single backend. By default, no backend is specified. In order to see any log message, Initialize has to be called.

For example

gol.Initialize(&gol.Configuration{Backend: "console", Mask: "all"})

will log all messages to the console.

func Panic

func Panic(v interface{})

func Protocol

func Protocol(format string, values ...interface{})

Debug uses format and values to generate a log message on the debug channel.

func Warning

func Warning(format string, values ...interface{})

Warning uses format and values to generate a log message on the warning channel.

Types

type Configuration

type Configuration struct {
	// common
	Backend string `json:"backend"`
	Mask    string `json:"mask"`

	// console
	Color bool `json:"color"`

	// file
	Path string `json:"path"`
	Mode string `json:"mode"`

	// syslog
	Prefix string `json:"prefix"`
}

Configuration holds all information that specify a single gol backend. While the common properties are needed for each backend, it holds also backend-specific properties.

Jump to

Keyboard shortcuts

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