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
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(format string, v ...interface{})
- func Flags() int
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Prefix() string
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetFlags(flag int)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- func Warnln(v ...interface{})
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(format string, v ...interface{})
- func (l *Logger) Flags() int
- func (l *Logger) Output(calldepth, noflag int, v ...interface{}) error
- func (l *Logger) Outputf(calldepth int, noflag int, format string, v ...interface{}) error
- func (l *Logger) Outputln(calldepth int, noflag int, v ...interface{}) error
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) Prefix() string
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) SetFlags(flag int)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(v ...interface{})
Constants ¶
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 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 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.
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 ¶
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 ¶
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 ¶
Fatalf prints the message like Printf and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.
func (*Logger) Fatalln ¶
Fatalln prints the message like Println and calls os.Exit(1). The printing might be suppressed by the flag Lnofatal.
func (*Logger) Output ¶
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) 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 ¶
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) 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 ¶
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) Warn ¶
func (l *Logger) Warn(v ...interface{})
Warn prints the message like Print. The printing might be suppressed by the flag Lnowarn.