logging

package module
v0.0.0-...-207764b Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: MIT Imports: 9 Imported by: 0

README

logging

Logging package for Go with logging levels

Documentation

Index

Constants

View Source
const (
	INVALID = -1   // not a valid logging level, returned by LevelFromString
	DEBUG   = iota // messages printed with this level have a "DEBUG:" prefix
	INFO           // messages printed with this level have a "INFO:" prefix
	WARNING        // messages printed with this level have a "WARNING:" prefix
	ERROR          // messages printed with this level have a "ERROR:" prefix
	FATAL          // messages printed with this level have a "FATAL:" prefix, calls os.Exit(1)
	NOTSET         // prints nothing from the logger
)

These constants define the level of logging

View Source
const (
	Ldate         = 1 << iota     // the date in the local time zone: 2009/01/23
	Ltime                         // the time in the local time zone: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                          // if Ldate or Ltime is set, use UTC rather than the local time zone
	Ltruncate                     // truncate up to logger.maxmsglength
	Llevel                        // write logging level
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,

2009/01/23 01:23:23 message

while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug calls Debug on the default logger

func Debugf

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

Debugf calls Debug on the default logger

func Error

func Error(v ...interface{})

Error calls Debug on the default logger

func Errorf

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

Errorf calls Debug on the default logger

func Fatal

func Fatal(v ...interface{})

Fatal calls Debug on the default logger

func Fatalf

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

Fatalf calls Debug on the default logger

func Info

func Info(v ...interface{})

Info calls Debug on the default logger

func Infof

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

Infof calls Debug on the default logger

func LevelFromString

func LevelFromString(name string) int

LevelFromString returns the level value for the given level name

func SetFlags

func SetFlags(flags int)

SetFlags set the default logger flags

func SetLevel

func SetLevel(level int)

SetLevel set the level of the default logger

func SetOutput

func SetOutput(w io.Writer)

SetOutput set the output of the default logger

func SetPrefix

func SetPrefix(prefix string)

SetPrefix set the prefix of the default logger

func Warning

func Warning(v ...interface{})

Warning calls Debug on the default logger

func Warningf

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

Warningf calls Debug on the default logger

Types

type Logger

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

Logger redefine log.Logger and adds leveling

func New

func New(out io.Writer, prefix string, flags, level int) *Logger

New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties. The level argument defines the logger level of logging

func (*Logger) Debug

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

Debug calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Print with DEBUG: as message prefix

func (*Logger) Debugf

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

Debugf calls logger.Output to print to the logger if logging level is inferior or equal to DEBUG. Arguments are handled in the manner of fmt.Printf with DEBUG: as message prefix

func (*Logger) Error

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

Error calls logger.Output to print to the logger if logging level is inferior or equal to ERROR. Arguments are handled in the manner of fmt.Print with ERROR: as message prefix

func (*Logger) Errorf

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

Errorf calls logger.Output to print to the logger if logging level is inferior or equal to ERROR. Arguments are handled in the manner of fmt.Printf with ERROR: as message prefix

func (*Logger) Fatal

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

Fatal calls logger.Output to print to the logger if logging level is inferior or equal to FATAL. Arguments are handled in the manner of fmt.Print with FATAL: as message prefix

func (*Logger) Fatalf

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

Fatalf calls logger.Output to print to the logger if logging level is inferior or equal to FATAL. Arguments are handled in the manner of fmt.Printf with FATAL: as message prefix and followed by a call to os.Exit(1)

func (*Logger) Info

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

Info calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Print with INFO: as message prefix

func (*Logger) Infof

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

Infof calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Printf with INFO: as message prefix

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string, level int) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flags int)

SetFlags sets the logger properties

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel checks for level value and sets the logging level

func (*Logger) SetOutput

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

SetOutput sets the output destination for the logger.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the output destination for the logger.

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

Warning calls logger.Output to print to the logger if logging level is inferior or equal to WARNING. Arguments are handled in the manner of fmt.Print with WARNING: as message prefix

func (*Logger) Warningf

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

Warningf calls logger.Output to print to the logger if logging level is inferior or equal to WARNING. Arguments are handled in the manner of fmt.Printf with WARNING: as message prefix

Jump to

Keyboard shortcuts

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