xlog

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package xlog provides a simple logging package that allows to disable certain message categories. It defines a type, Logger, with multiple methods for formatting output. The package has also a predefined 'standard' Logger accessible through helper function Print[f|ln], Fatal[f|ln], Panic[f|ln], Warn[f|ln], Print[f|ln] and Debug[f|ln] that are easier to use then creating a Logger manually. That logger writes to standard error and prints the date and time of each logged message, which can be configured using the function SetFlags.

The Fatal functions call os.Exit(1) after the message is output unless not suppressed by the flags. The Panic functions call panic after the writing the log message unless suppressed.

Index

Constants

View Source
const (
	Ldate         = 1 << iota // the date: 2009-01-23
	Ltime                     // the time: 01:23:23
	Lmicroseconds             // microsecond resolution: 01:23:23.123123
	Llongfile                 // full file name and line number: /a/b/c/d.go:23
	Lshortfile                // final file name element and line number: d.go:23
	Lnopanic                  // suppresses output from Panic[f|ln] but not the panic call
	Lnofatal                  // suppresses output from Fatal[f|ln] but not the exit
	Lnowarn                   // suppresses output from Warn[f|ln]
	Lnoprint                  // suppresses output from Print[f|ln]
	Lnodebug                  // suppresses output from Debug[f|ln]
	// initial values for the standard logger
	Lstdflags = Ldate | Ltime | Lnodebug
)

The flags define what information is prefixed to each log entry generated by the Logger. The Lno* versions allow the suppression of specific output. The bits are or'ed together to control what will be printed. There is no control over the order of the items printed and the format. The full format is:

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 prints the message like Print. The printing might be suppressed by the flag Lnodebug.

func Debugf

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

Debugf prints the message like Printf. The printing might be suppressed by the flag Lnodebug.

func Debugln

func Debugln(v ...interface{})

Debugln prints the message like Println. The printing might be suppressed by the flag Lnodebug.

func Fatal

func Fatal(v ...interface{})

Fatal prints the message like Print and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func Fatalf

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

Fatalf prints the message like Printf and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func Fatalln

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

Fatalln prints the message like Println and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func Flags

func Flags() int

Flags returns the current flags used by the standard logger.

func Panic

func Panic(v ...interface{})

Panic prints the message like Print and calls panic. The printing might be suppressed by the flag Lnopanic.

func Panicf

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

Panicf prints the message like Printf and calls panic. The printing might be suppressed by the flag Lnopanic.

func Panicln

func Panicln(v ...interface{})

Panicln prints the message like Println and calls panic. The printing might be suppressed by the flag Lnopanic.

func Prefix

func Prefix() string

Prefix returns the prefix used by the standard logger of the package.

func Print

func Print(v ...interface{})

Print prints the message like fmt.Print. The printing might be suppressed by the flag Lnoprint.

func Printf

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

Printf prints the message like fmt.Printf. The printing might be suppressed by the flag Lnoprint.

func Println

func Println(v ...interface{})

Println prints the message like fmt.Println. The printing might be suppressed by the flag Lnoprint.

func SetFlags

func SetFlags(flag int)

SetFlags sets the flags for the standard logger.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output for the standard logger of the package.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the prefix of the standard logger of the package.

func Warn

func Warn(v ...interface{})

Warn prints the message like Print. The printing might be suppressed by the flag Lnowarn.

func Warnf

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

Warnf prints the message like Printf. The printing might be suppressed by the flag Lnowarn.

func Warnln

func Warnln(v ...interface{})

Warnln prints the message like Println. The printing might be suppressed by the flag Lnowarn.

Types

type Logger

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

A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation if not suppressed makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func New

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

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

func (*Logger) Debug

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

Debug prints the message like Print. The printing might be suppressed by the flag Lnodebug.

func (*Logger) Debugf

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

Debugf prints the message like Printf. The printing might be suppressed by the flag Lnodebug.

func (*Logger) Debugln

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

Debugln prints the message like Println. The printing might be suppressed by the flag Lnodebug.

func (*Logger) Fatal

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

Fatal prints the message like Print and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func (*Logger) Fatalf

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

Fatalf prints the message like Printf and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func (*Logger) Fatalln

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

Fatalln prints the message like Println and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.

func (*Logger) Flags

func (l *Logger) Flags() int

Flags returns the current flags used by the logger.

func (*Logger) Output

func (l *Logger) Output(calldepth, noflag int, v ...interface{}) error

Output writes the string s with the header controlled by the flags to the l.out writer. A newline will be appended if s doesn't end in a newline. Calldepth is used to recover the PC, although all current calls of Output use the call depth 2. Access to the function is serialized.

func (*Logger) Outputf

func (l *Logger) Outputf(calldepth int, noflag int, format string, v ...interface{}) error

Outputf works like output but formats the output like Printf.

func (*Logger) Outputln

func (l *Logger) Outputln(calldepth int, noflag int, v ...interface{}) error

Outputln works like output but formats the output like Println.

func (*Logger) Panic

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

Panic prints the message like Print and calls panic. The printing might be suppressed by the flag Lnopanic.

func (*Logger) Panicf

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

Panicf prints the message like Printf and calls panic. The printing might be suppressed by the flag Lnopanic.

func (*Logger) Panicln

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

Panicln prints the message like Println and calls panic. The printing might be suppressed by the flag Lnopanic.

func (*Logger) Prefix

func (l *Logger) Prefix() string

Prefix returns the prefix used by the logger.

func (*Logger) Print

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

Print prints the message like fmt.Print. The printing might be suppressed by the flag Lnoprint.

func (*Logger) Printf

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

Printf prints the message like fmt.Printf. The printing might be suppressed by the flag Lnoprint.

func (*Logger) Println

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

Println prints the message like fmt.Println. The printing might be suppressed by the flag Lnoprint.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the flags of the logger.

func (*Logger) SetOutput

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

SetOutput sets the output of the logger.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the prefix for the logger.

func (*Logger) Warn

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

Warn prints the message like Print. The printing might be suppressed by the flag Lnowarn.

func (*Logger) Warnf

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

Warnf prints the message like Printf. The printing might be suppressed by the flag Lnowarn.

func (*Logger) Warnln

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

Warnln prints the message like Println. The printing might be suppressed by the flag Lnowarn.

Jump to

Keyboard shortcuts

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