seelog

package module
v1.0.0-...-637f6c2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2012 License: BSD-3-Clause Imports: 21 Imported by: 0

README

Seelog

Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log messages. It is natively written in the Go programming language.

Features

  • Xml configuring to be able to change logger parameters without recompilation
  • Changing configurations on the fly without app restart
  • Possibility to set different log configurations for different project files and functions
  • Adjustable message formatting
  • Simultaneous log output to multiple streams
  • Choosing logger priority strategy to minimize performance hit
  • Different output writers
    • Console writer
    • File writer
    • Buffered writer (Chunk writer)
    • Rolling log writer (Logging with rotation)
    • SMTP writer
    • Others... (See Wiki)
  • (In progress) Log message wrappers (JSON, XML, etc.)
  • Global variables and functions for easy usage in standalone apps
  • Functions for flexible usage in libraries

Quick-start

package main

import log "github.com/cihub/seelog"

func main() {
    defer log.Flush()
    log.Info("Hello from Seelog!")
}

Installation

If you don't have the Go development environment installed, visit the Getting Started document and follow the instructions. Once you're ready, execute the following command:

go get -u github.com/cihub/seelog

Documentation

Seelog has github wiki pages which contain a detailed Seelog reference: https://github.com/cihub/seelog/wiki

Examples

Seelog examples can be found here: seelog-examples

Issues

Feel free to push issues that could make Seelog better: https://github.com/cihub/seelog/issues

Documentation

Overview

Package seelog implements logging functionality with flexible dispatching, filtering, and formatting.

Index

Constants

View Source
const (
	SeelogConfigId             = "seelog"
	OutputsId                  = "outputs"
	FormatsId                  = "formats"
	MinLevelId                 = "minlevel"
	MaxLevelId                 = "maxlevel"
	LevelsId                   = "levels"
	ExceptionsId               = "exceptions"
	ExceptionId                = "exception"
	FuncPatternId              = "funcpattern"
	FilePatternId              = "filepattern"
	FormatId                   = "format"
	FormatAttrId               = "format"
	FormatKeyAttrId            = "id"
	OutputFormatId             = "formatid"
	FilePathId                 = "path"
	FileWriterId               = "file"
	SmtpWriterId               = "smtp"
	SenderAddressId            = "senderaddress"
	SenderNameId               = "sendername"
	RecipientId                = "recipient"
	AddressId                  = "address"
	HostNameId                 = "hostname"
	HostPortId                 = "hostport"
	UserNameId                 = "username"
	UserPassId                 = "password"
	SpliterDispatcherId        = "splitter"
	ConsoleWriterId            = "console"
	FilterDispatcherId         = "filter"
	FilterLevelsAttrId         = "levels"
	RollingFileWriterId        = "rollingfile"
	RollingFileTypeAttr        = "type"
	RollingFilePathAttr        = "filename"
	RollingFileMaxSizeAttr     = "maxsize"
	RollingFileMaxRollsAttr    = "maxrolls"
	RollingFileDataPatternAttr = "datepattern"

	BufferedSizeAttr         = "size"
	BufferedFlushPeriodAttr  = "flushperiod"
	LoggerTypeFromStringAttr = "type"
	AsyncLoggerIntervalAttr  = "asyncinterval"
)
View Source
const (
	TraceLvl = iota
	DebugLvl
	InfoLvl
	WarnLvl
	ErrorLvl
	CriticalLvl
	Off
)

Log levels

View Source
const (
	TraceStr    = "trace"
	DebugStr    = "debug"
	InfoStr     = "info"
	WarnStr     = "warn"
	ErrorStr    = "error"
	CriticalStr = "critical"
	OffStr      = "off"
)

Log level string representations (used in configuration files)

View Source
const (
	VerbSymbol         = '%'
	VerbSymbolString   = "%"
	VerbParameterStart = '('
	VerbParameterEnd   = ')'
	DateDefaultFormat  = "2006-01-02"
	TimeFormat         = "15:04:05"
)
View Source
const (
	Size = iota
	Date
)
View Source
const (
	AsyncloggerTypeFromStringStr = "asyncloop"
)
View Source
const (
	DefaultloggerTypeFromString = asyncLooploggerTypeFromString
)
View Source
const (
	MaxQueueSize = 10000
)

Variables

View Source
var Defaultformatter *formatter

Functions

func Critical

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

Critical formats message according to format specifier and writes to default logger with log level = Critical

func Debug

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

Debug formats message according to format specifier and writes to default logger with log level = Debug

func Error

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

Error formats message according to format specifier and writes to default logger with log level = Error

func Flush

func Flush()

Flush performs all cleanup, flushes all queued messages, etc. Call this method when your app is going to shut down not to lose any log messages.

func Info

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

Info formats message according to format specifier and writes to default logger with log level = Info

func ReplaceLogger

func ReplaceLogger(logger LoggerInterface) error

Acts as UseLogger but the logger that was previously used would be disposed (except Default and Disabled loggers).

func Trace

func Trace(format string, params ...interface{})

Trace formats message according to format specifier and writes to default logger with log level = Trace

func UseLogger

func UseLogger(logger LoggerInterface) error

UseConfig uses the given logger for all Trace/Debug/... funcs.

func Warn

func Warn(format string, params ...interface{})

Warn formats message according to format specifier and writes to default logger with log level = Warn

Types

type LogLevel

type LogLevel uint8

Log level type

func LogLevelFromString

func LogLevelFromString(levelStr string) (level LogLevel, found bool)

LogLevelFromString parses a string and returns a corresponding log level, if sucessfull.

func (LogLevel) String

func (level LogLevel) String() string

LogLevelToString returns seelog string representation for a specified level. Returns "" for invalid log levels.

type LoggerInterface

type LoggerInterface interface {
	Trace(format string, params ...interface{})
	Debug(format string, params ...interface{})
	Info(format string, params ...interface{})
	Warn(format string, params ...interface{})
	Error(format string, params ...interface{})
	Critical(format string, params ...interface{})

	Close()
	Flush()
	Closed() bool
	// contains filtered or unexported methods
}

LoggerInterface represents structs capable of logging Seelog messages

var Current LoggerInterface
var Default LoggerInterface
var Disabled LoggerInterface

func LoggerFromConfigAsBytes

func LoggerFromConfigAsBytes(data []byte) (LoggerInterface, error)

LoggerFromConfigAsBytes creates a logger with config from bytes stream. Bytes should contain valid seelog xml.

func LoggerFromConfigAsFile

func LoggerFromConfigAsFile(fileName string) (LoggerInterface, error)

LoggerFromConfigAsFile creates logger with config from file. File should contain valid seelog xml.

func LoggerFromConfigAsString

func LoggerFromConfigAsString(data string) (LoggerInterface, error)

LoggerFromConfigAsString creates a logger with config from a string. String should contain valid seelog xml.

func LoggerFromWriterWithMinLevel

func LoggerFromWriterWithMinLevel(output io.Writer, minLevel LogLevel) (LoggerInterface, error)

LoggerFromWriterWithMinLevel creates a simple logger for usage with non-Seelog systems. Creates logger that writes to output with minimal level = minLevel.

Jump to

Keyboard shortcuts

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