seezlog

package module
v0.0.0-...-881a8ac Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: MIT Imports: 3 Imported by: 0

README

seezlog

seezlog is a convenience wrapper for seelog so you can setup formatted logging in one line and it will "just work".

Godoc

Why?

Because I found myself wanting to use seelog as a logger for command line tools but found it tedious to set up the xml formatting in every project. This will wrap all that logic and provide you a one line function that initializes a seelog logger capable of printing both to stdout and a log file.

Usage

For simplicity, there are only three public functions:

SetupLogger
SetupLogger(logTo Level, outTo Level, path string) (logger log.LoggerInterface, err error)

Creates and initializes up a seelog logger that will print to stdout up to outTo log level and will print to a log file up to logTo log level. Just plug this into seelog's ReplaceLogger function to use it. See the example below or take a look in the examples directory


SetupConsoleLogger
SetupConsoleLogger(outTo Level) (logger log.LoggerInterface, err error)

Creates and initializes up a seelog logger that will only print to stdout up to outTo log level. Just plug this into seelog's ReplaceLogger function to use it. See the example below or take a look in the examples directory


GenerateConfig
GenerateConfig(logTo Level, outTo Level, path string) (config string, err error)

Generates the configuration to create a seelog logger that will print to stdout up to outTo log level and will print to a log file up to logTo log level. This can be useful if you are trying to generate a constant config file for seelog and just want this library to generate a no hastle config for you.

Log Levels

The accepted log levels of type Level are Critical, Error, Warn, Info, Debug, Trace, and NoLog

The level ordering is as follows: Critical > Error > Warn > Info > Debug > Trace


Example

import(
    seezlog "github.com/grindlemire/seezlog"
    log "github.com/cihub/seelog"
)

logger, err := seezlog.SetupLogger(seezlog.Info, seezlog.Warn, "./example.log")
if err != nil {
    fmt.Printf("Error setting up logger: %v", err)
    os.Exit(1)
}
log.ReplaceLogger(logger)
defer log.Flush()

log.Critical("This critical will to stdout and the log file")
log.Warn("This warn will print to stdout and the log file")
log.Error("This error will print only to the log file")
log.Info("This info will print only to the log file")
log.Debug("This debug will not print to the log or stdout")
log.Trace("This trace will not print to the log or stdout")

Example Log Messages

[Info] [2006-01-02 15:04:05] [file.go] Info message

[WARN] [2006-01-02 15:04:05] [func @ file.go.Line] Warn message

[ERROR] [2006-01-02 15:04:05] [func @ file.go.Line] Error message

[CRITICAL] [2006-01-02 15:04:05] [func @ file.go.Line] Critical message

[DEBUG] [2006-01-02 15:04:05] [func @ file.go:Line] Debug message

[TRACE] [2006-01-02 15:04:05] [func @ file.go:Line] Trace message

Documentation

Index

Constants

View Source
const (
	NoLog = iota
	Critical
	Error
	Warn
	Info
	Debug
	Trace
)

Log levels accepted by GenerateConfig and SetupLogger.

Variables

This section is empty.

Functions

func GenerateConfig

func GenerateConfig(logTo Level, outTo Level, path string) (config string, err error)

GenerateConfig will generate the seelog xml file and spit it out to stdout.

func SetupConsoleLogger

func SetupConsoleLogger(outTo Level) (logger log.LoggerInterface, err error)

SetupLogger will setup a seelog logger that only outputs to stdout to a specific log level. Call ReplaceLogger with this logger from seelog to use this logger.

func SetupLogger

func SetupLogger(logTo Level, outTo Level, path string) (logger log.LoggerInterface, err error)

SetupLogger will setup a seelog logger to a specific log level and will output to stdout to a specific log level. Call ReplaceLogger with this logger from seelog to use this logger.

Types

type Level

type Level int

Level is the enum type representing the log level

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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