logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: BSD-2-Clause Imports: 6 Imported by: 430

Documentation

Overview

Package logger implements an hierarchical logger used by other packages.

Index

Constants

View Source
const (
	DEBUG = iota
	INFO
	WARN
	ERROR
	FATAL
)

Levels to filter log output

View Source
const (
	// Show date
	FDATE = 1 << iota
	// Show hour, minutes and seconds
	FTIME
	// Show milliseconds after FTIME
	FMILIS
	// Show microseconds after FTIME
	FMICROS
	// Show nanoseconfs after TIME
	FNANOS
)

Flags used to format the log date/time

Variables

This section is empty.

Functions

func AddWriter

func AddWriter(writer LoggerWriter)

AddWriter adds a writer to the current outputs of the default logger.

func Debug

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

Debug emits a DEBUG level log message

func Error

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

Error emits an ERROR level log message

func Fatal

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

Fatal emits a FATAL level log message

func Info

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

Info emits an INFO level log message

func Log

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

Log emits a log message with the specified level

func SetFormat

func SetFormat(format int)

SetFormat sets the date/time message format of the default logger.

func SetLevel

func SetLevel(level int)

SetLevel sets the current level of the default logger. Only log messages with levels with the same or higher priorities than the current level will be emitted.

func SetLevelByName

func SetLevelByName(lname string)

SetLevelByName sets the current level of the default logger by level name: debug|info|warn|error|fatal (case ignored.) Only log messages with levels with the same or higher priorities than the current level will be emitted.

func Warn

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

Warn emits a WARN level log message

Types

type Console

type Console struct {
	// contains filtered or unexported fields
}

Console is a console writer used for logging.

func NewConsole

func NewConsole(color bool) *Console

NewConsole creates and returns a new logger Console writer If color is true, this writer uses Ansi codes to write log messages in color accordingly to its level.

func (*Console) Close

func (w *Console) Close()

func (*Console) Sync

func (w *Console) Sync()

func (*Console) Write

func (w *Console) Write(event *Event)

Write writes the provided logger event to the console.

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event is a logger event passed from the logger to its writers.

type File

type File struct {
	// contains filtered or unexported fields
}

File is a file writer used for logging.

func NewFile

func NewFile(filename string) (*File, error)

NewFile creates and returns a pointer to a new File object along with any error that occurred.

func (*File) Close

func (f *File) Close()

Close closes the file.

func (*File) Sync

func (f *File) Sync()

Sync commits the current contents of the file to stable storage.

func (*File) Write

func (f *File) Write(event *Event)

Write writes the provided logger event to the file.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger Object state structure

var Default *Logger

Default logger and global mutex

func Find

func Find(path string) *Logger

Find finds a logger with the specified path.

func New

func New(name string, parent *Logger) *Logger

New creates and returns a new logger with the specified name. If a parent logger is specified, the created logger inherits the parent's configuration.

func (*Logger) AddWriter

func (l *Logger) AddWriter(writer LoggerWriter)

AddWriter adds a writer to the current outputs of this logger.

func (*Logger) Debug

func (l *Logger) Debug(format string, v ...interface{})

Debug emits a DEBUG level log message

func (*Logger) EnableChild

func (l *Logger) EnableChild(name string, state bool)

EnableChild enables or disables this logger child logger with the specified name.

func (*Logger) Error

func (l *Logger) Error(format string, v ...interface{})

Error emits an ERROR level log message

func (*Logger) Fatal

func (l *Logger) Fatal(format string, v ...interface{})

Fatal emits a FATAL level log message

func (*Logger) Info

func (l *Logger) Info(format string, v ...interface{})

Info emits an INFO level log message

func (*Logger) Log

func (l *Logger) Log(level int, format string, v ...interface{})

Log emits a log message with the specified level

func (*Logger) RemoveWriter

func (l *Logger) RemoveWriter(writer LoggerWriter)

RemoveWriter removes the specified writer from the current outputs of this logger.

func (*Logger) SetFormat

func (l *Logger) SetFormat(format int)

SetFormat sets the logger date/time message format

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel sets the current level of this logger. Only log messages with levels with the same or higher priorities than the current level will be emitted.

func (*Logger) SetLevelByName

func (l *Logger) SetLevelByName(lname string) error

SetLevelByName sets the current level of this logger by level name: debug|info|warn|error|fatal (case ignored.) Only log messages with levels with the same or higher priorities than the current level will be emitted.

func (*Logger) Warn

func (l *Logger) Warn(format string, v ...interface{})

Warn emits a WARN level log message

type LoggerWriter

type LoggerWriter interface {
	Write(*Event)
	Close()
	Sync()
}

LoggerWriter is the interface for all logger writers

type Net

type Net struct {
	// contains filtered or unexported fields
}

Net is a network writer used for logging.

func NewNet

func NewNet(network string, address string) (*Net, error)

NewNet creates and returns a pointer to a new Net object along with any error that occurred.

func (*Net) Close

func (n *Net) Close()

Clone closes the network connection.

func (*Net) Sync

func (n *Net) Sync()

func (*Net) Write

func (n *Net) Write(event *Event)

Write writes the provided logger event to the network.

Jump to

Keyboard shortcuts

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