logging

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

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

Go to latest
Published: Jun 2, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

README

go-logging

Go Report Card Build Status GoDoc

A logging library for golang

Example

coding...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPackageHost

func AddPackageHost(host string)

AddPackageHost add a customized golang package host to known package hosts. While create static local context for logging message formatting, known package hosts is used to cut off GOPATH directory from the path of file. It ensures output compiled in different GOPATH will log with same path of file.

func Debug

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

Debug log message with "debug" level and default session.

func Error

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

Error log message with "error" level and default session.

func Fatal

func Fatal(format string, args ...interface{})

Fatal log message with "fatal" level and default session.

func Info

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

Info log message with "info" level and default session.

func LoadConfig

func LoadConfig(config Config)

LoadConfig load configuration and setting up the go-logging.

func Log

func Log(level, format string, args ...interface{})

Log log message with default session.

func LogWithSkip

func LogWithSkip(skip int, level string, format string, args ...interface{})

LogWithSkip log message with specified skip

func SetTimeFormat

func SetTimeFormat(format string)

SetTimeFormat set the time format.

func Warn

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

Warn log message with "warn" level and default session.

Types

type Config

type Config struct {
	TimeFormat string
	Handlers   []*Handler
}

Config defines the configuration of go-logging.

type EmailWriter

type EmailWriter struct {
	// Email server
	Server string

	// Email sender and account name
	Sender string

	// Email account password
	Password string

	// Email Receivers
	Receivers []string

	// Email subject
	Subject string

	// the logs arrived after first log in "Delay" duration will be grouped with the first log
	Delay time.Duration
	// contains filtered or unexported fields
}

EmailWriter group logs and send as email

func (*EmailWriter) Initialize

func (writer *EmailWriter) Initialize()

Initialize setup the writer

func (*EmailWriter) Write

func (writer *EmailWriter) Write(bytes []byte) (int, error)

Write receives logs

type Handler

type Handler struct {
	// responsible levels
	Levels []string

	// format of log message
	Format string

	// writers
	Writers []Writer
}

Handler handles format the log message and dispatch it to writers

type Session

type Session map[string]interface{}

Session hold special field of user defined session.

func NewSession

func NewSession() Session

NewSession create a new session.

func (Session) Debug

func (s Session) Debug(format string, args ...interface{})

Debug log message with "debug" level

func (Session) Error

func (s Session) Error(format string, args ...interface{})

Error log message with "error" level

func (Session) Fatal

func (s Session) Fatal(format string, args ...interface{})

Fatal log message with "fatal" level

func (Session) Info

func (s Session) Info(format string, args ...interface{})

Info log message with "info" level

func (Session) Log

func (s Session) Log(level string, format string, args ...interface{})

Log log message with any level

func (Session) LogWithSkip

func (s Session) LogWithSkip(skip int, level string, format string, args ...interface{})

LogWithSkip log message with specified skip.

func (Session) Set

func (s Session) Set(key string, value interface{})

Set set a key-value pair to session

func (Session) Warn

func (s Session) Warn(format string, args ...interface{})

Warn log message with "warn" level

type TimeRotateWriter

type TimeRotateWriter struct {
	sync.Mutex
	// file path
	Path string

	// split file path
	Split string

	// rotate interval
	Interval time.Duration

	// keep split file duration, the expired split file will be removed
	Keep time.Duration
	// contains filtered or unexported fields
}

TimeRotateWriter write logs to file and rotate the file Periodically.

func (*TimeRotateWriter) Initialize

func (writer *TimeRotateWriter) Initialize() error

Initialize setup the writer

func (*TimeRotateWriter) Write

func (writer *TimeRotateWriter) Write(bytes []byte) (int, error)

Write receives log and write to file

type Writer

type Writer io.Writer

Writer wrap the io.Writer interface. It is useful for WriterFactory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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