Documentation
¶
Overview ¶
Package llog implements support for logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides a low-level class (llog.T) that encapsulates all state and and methods of multi-leveled logging (i.e. Info, Warning, Error and Fatal) and formatting variants such as Infof. Each instance of T may be named and hence multiple sets of logs can be produced by a single process. It also provides V-style logging controlled by the -v and -vmodule=file=2 style flags. Although command line flags are not directly implemented, implementations of the Go 1.2 flags.Value interface are provided to make it easy for users to parse their command line flags correctly. The NewLogger factory function accepts positional parameters that correspond google command line flags.
l := NewLogger("system") l.Print(infoLog, Info("Prepare to repel boarders") l.Printf(fatalLog, "Initialization failed: %s", err)
See the documentation for the V function for an explanation of these examples:
if l.V(2) { l.Print(infoLog,"Starting transaction...") }
Log output is buffered and written periodically using Flush. Programs should call Flush before exiting to guarantee all log output is written.
By default, all log statements write to files in a temporary directory. This package provides several methods that modify this behavior. These methods must be called before any logging is done.
NewLogger(name) SetLogDir(logDir) log files will be written to this directory instead of the default temporary directory. SetLogToStderr(bool) If true, logs are written to standard error instead of to files. SetAlsoLogToStderr(bool) If true, logs are written to standard error as well as to files. SetStderrThreshold(level) Log events at or above this severity are logged to standard error as well as to files. SetMaxStackBufSize(size) Set the max size (bytes) of the byte buffer to use for stack traces. The default max is 4096K; use powers of 2 since the stack size will be grown exponentially until it exceeds the max. A min of 128K is enforced and any attempts to reduce this will be silently ignored. Other controls provide aids to debugging. SetLogBacktraceAt(location) When set to a file and line number holding a logging statement, such as gopherflakes.go:234 a stack trace will be written to the Info log whenever execution hits that statement. (Unlike with -vmodule, the ".go" must be present.) SetV(level) Enable V-leveled logging at the specified level. SetVModule(module) The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the ".go" suffix) or "glob" pattern and N is a V level. For instance, -gopher*=3 sets the V level to 3 in all Go files whose names begin "gopher".
SetVFilepath(regexp)
The syntax of the argument is as per VModule, expect that regular expressions on the entire file path path are used instead of glob patterns on the file name component as SetVModule.
Index ¶
- Variables
- type FilepathSpec
- type Level
- type Log
- func (l *Log) Flush()
- func (l *Log) Print(s Severity, args ...interface{})
- func (l *Log) PrintDepth(s Severity, depth int, args ...interface{})
- func (l *Log) Printf(s Severity, format string, args ...interface{})
- func (l *Log) PrintfDepth(s Severity, depth int, format string, args ...interface{})
- func (l *Log) Println(s Severity, args ...interface{})
- func (l *Log) PrintlnDepth(s Severity, depth int, args ...interface{})
- func (l *Log) SetAlsoLogToStderr(f bool)
- func (l *Log) SetLogDir(logDir string)
- func (l *Log) SetLogToStderr(f bool)
- func (l *Log) SetMaxStackBufSize(max int)
- func (l *Log) SetStderrThreshold(s Severity)
- func (l *Log) SetTraceLocation(location TraceLocation)
- func (l *Log) SetV(v Level)
- func (l *Log) SetVFilepath(spec FilepathSpec)
- func (l *Log) SetVModule(spec ModuleSpec)
- func (l *Log) Stats() Stats
- func (l *Log) String() string
- func (l *Log) V(level Level) bool
- func (l *Log) VDepth(depth int, level Level) bool
- type ModuleSpec
- type OutputStats
- type Severity
- type Stats
- type TraceLocation
Constants ¶
This section is empty.
Variables ¶
var MaxSize uint64 = 1024 * 1024 * 1800
MaxSize is the maximum size of a log file in bytes.
Functions ¶
This section is empty.
Types ¶
type FilepathSpec ¶
type FilepathSpec struct {
// contains filtered or unexported fields
}
FilepathSpec represents the setting of the -vfilepath flag.
func (*FilepathSpec) Get ¶
func (p *FilepathSpec) Get() interface{}
Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the struct is not exported.
func (*FilepathSpec) Set ¶
func (p *FilepathSpec) Set(value string) error
Syntax: foo/bar=2,foo/bar/.*=1,f*=3
func (*FilepathSpec) String ¶
func (fp *FilepathSpec) String() string
type Level ¶
type Level int32
Level specifies a level of verbosity for V logs. *Level implements flag.Value; the -v flag is of type Level and should be modified only through the flag.Value interface.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log collects all the global state of the logging setup.
func NewLogger ¶
NewLogger creates a new logger. name is a non-empty string that appears in the names of log files to distinguish between separate instances of the logger writing to the same directory. skip is the number of stack frames to skip in order to reach the call point to be logged. 0 will log the caller of the logging methods, 1 their caller etc.
func (*Log) PrintDepth ¶
func (*Log) PrintfDepth ¶
func (*Log) PrintlnDepth ¶
func (*Log) SetAlsoLogToStderr ¶
SetAlsoLogToStderr sets the flag that, if true, logs to standard error as well as files
func (*Log) SetLogToStderr ¶
SetLogToStderr sets the flag that, if true, logs to standard error instead of files
func (*Log) SetMaxStackBufSize ¶
func (*Log) SetStderrThreshold ¶
SetStderrThreshold sets the threshold for which logs at or above which go to stderr
func (*Log) SetTraceLocation ¶
func (l *Log) SetTraceLocation(location TraceLocation)
SetTaceLocation sets the location, file:N, which when encountered will cause logging to emit a stack trace
func (*Log) SetVFilepath ¶
func (l *Log) SetVFilepath(spec FilepathSpec)
SetModuleSpec sets the comma-separated list of pattern=N settings for file-filtered logging
func (*Log) SetVModule ¶
func (l *Log) SetVModule(spec ModuleSpec)
SetModuleSpec sets the comma-separated list of pattern=N settings for file-filtered logging
func (*Log) VDepth ¶
V reports whether verbosity at the call site is at least the requested level. The returned value is a boolean of type Verbose, which implements Info, Infoln and Infof. These methods will write to the Info log if called. Thus, one may write either
if glog.V(2) { glog.Info("log this") }
or
glog.V(2).Info("log this")
The second form is shorter but the first is cheaper if logging is off because it does not evaluate its arguments.
Whether an individual call to V generates a log record depends on the setting of the -v and --vmodule flags; both are off by default. If the level in the call to V is at least the value of -v, or of -vmodule for the source file containing the call, the V call will log.
type ModuleSpec ¶
type ModuleSpec struct {
// contains filtered or unexported fields
}
moduleSpec represents the setting of the -vmodule flag.
func (*ModuleSpec) Get ¶
func (m *ModuleSpec) Get() interface{}
Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the struct is not exported.
func (*ModuleSpec) Set ¶
func (m *ModuleSpec) Set(value string) error
Syntax: recordio=2,file=1,gfs*=3
func (*ModuleSpec) String ¶
func (m *ModuleSpec) String() string
type OutputStats ¶
type OutputStats struct {
// contains filtered or unexported fields
}
OutputStats tracks the number of output lines and bytes written.
func (*OutputStats) Bytes ¶
func (s *OutputStats) Bytes() int64
Bytes returns the number of bytes written.
func (*OutputStats) Lines ¶
func (s *OutputStats) Lines() int64
Lines returns the number of lines written.
type Severity ¶
type Severity int32 // sync/atomic int32
severity identifies the sort of log: info, warning etc. It also implements the flag.Value interface. The -stderrthreshold flag is of type severity and should be modified only through the flag.Value interface. The values match the corresponding constants in C++.
type Stats ¶
type Stats struct {
Info, Warning, Error OutputStats
}
Stats tracks the number of lines of output and number of bytes per severity level.
type TraceLocation ¶
type TraceLocation struct {
// contains filtered or unexported fields
}
traceLocation represents the setting of the -log_backtrace_at flag.
func (*TraceLocation) Set ¶
func (t *TraceLocation) Set(value string) error
Syntax: gopherflakes.go:234 Note that unlike vmodule the file extension is included here.
func (*TraceLocation) String ¶
func (t *TraceLocation) String() string