logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: LGPL-3.0 Imports: 5 Imported by: 3

README

logger is a threadsafe logging library for go that does conditional logging controlled via UNIX-style loglevels.
Read its documentation via "go doc -all".
The library is free software licensed under the LGPL-3 license.

©2020 Jörg Walter

Documentation

Overview

The package logger provides a Logger type that can receive log records. Logger will only display a record if it is as severe as or more severe than the loglevel set for the Logger. Users of Logger therefore can control how much logging output they will see while running their program. A Logger can be used by multiple goroutines.

For usable loglevels see CONSTANTS.

Index

Constants

View Source
const (
	Level_Panic = iota
	Level_Alert
	Level_Critical
	Level_Error
	Level_Warning
	Level_Notice
	Level_Info
	Level_Debug
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LevelFlag

type LevelFlag int

func (*LevelFlag) Set

func (f *LevelFlag) Set(arg string) error

func (*LevelFlag) String

func (f *LevelFlag) String() string

type Logger

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

Logger is the data type used for sending log records to.

func New

func New(w io.Writer, level int, delimiter string) *Logger

New constructs a new Logger. It will print a log record to its given writer if it fulfills the Logger's designated loglevel or a more severe one. If you set the level to Level_Critical, the Logger will print all messages of Level_Panic or Level_Alert or Level_Critical.

func (*Logger) Alert

func (l *Logger) Alert(v ...interface{}) (n int, err error)

Alert sends a message of loglevel Level_Alert to the Logger.

func (*Logger) Critical

func (l *Logger) Critical(v ...interface{}) (n int, err error)

Critical sends a message of loglevel Level_Critical to the Logger.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{}) (n int, err error)

Debug sends a message of loglevel Level_Debug to the Logger.

func (*Logger) Error

func (l *Logger) Error(v ...interface{}) (n int, err error)

Error sends a message of loglevel Level_Error to the Logger.

func (*Logger) Info

func (l *Logger) Info(v ...interface{}) (n int, err error)

Info sends a message of loglevel Level_Info to the Logger.

func (*Logger) Level

func (l *Logger) Level() int

Level returns the Logger's current loglevel as an integer.

func (*Logger) LevelStr

func (l *Logger) LevelStr() string

LevelStr returns the string representation of the Logger's current loglevel.

func (*Logger) Notice

func (l *Logger) Notice(v ...interface{}) (n int, err error)

Notice sends a message of loglevel Level_Notice to the Logger.

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{}) (n int, err error)

Panic sends a message of loglevel Level_Panic to the Logger. Please note that it does NOT call panic()!

func (*Logger) Println

func (l *Logger) Println(level int, v ...interface{}) (n int, err error)

Println writes the log message if its log level is equally severe or more severe than that set for the Logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel sets a new loglevel for the Logger. Setting an invalid loglevel will cause a panic.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput changes the writer the Logger will write its messages to.

func (*Logger) SetTimeFormat

func (l *Logger) SetTimeFormat(format string)

SetTimeFormat takes a format string as defined in the "(t Time) Format" function of go's "time" module. If such a string is set, log records will display a timestamp formatted like specified by the format string. To remove timestamps from future log records, set the format string to "".

func (*Logger) TimeFormat

func (l *Logger) TimeFormat() string

TimeFormat returns the current format string for the timestamp. If it returns "", log records will have no timestamp.

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{}) (n int, err error)

Warning sends a message of loglevel Level_Warning to the Logger.

Jump to

Keyboard shortcuts

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