Documentation ¶
Overview ¶
Package log provides logging for dist.ribut.us.
Index ¶
- Constants
- Variables
- func Debug(data ...interface{})
- func Error(err error) bool
- func Fatal(err error)
- func Format(value interface{}) string
- func GetDebug() bool
- func Go()
- func Info(data ...interface{})
- func Mute()
- func NoTrace()
- func Panic(err error)
- func SetDebug(debug bool)
- func SetTrace(start, end, pathDepth int)
- func To(w io.Writer)
- func ToFile(path ...string) error
- func ToStdOut()
- type KV
- type Lbl
- type Log
- func (l *Log) Child(data ...interface{}) *Log
- func (l *Log) Close() error
- func (l *Log) Debug(data ...interface{})
- func (l *Log) Error(err error) bool
- func (l *Log) Fatal(data ...interface{})
- func (l *Log) GetDebug() bool
- func (l *Log) Info(data ...interface{})
- func (l *Log) Mute()
- func (l *Log) NoTrace()
- func (l *Log) Panic(err error)
- func (l *Log) SetDebug(debug bool)
- func (l *Log) SetTrace(start, end, pathDepth int)
- func (l *Log) To(w io.Writer)
- type Val
Constants ¶
const ( // Truncate is a reference to os.O_TRUNC Truncate = os.O_TRUNC // Append is a reference to os.O_APPEND Append = os.O_APPEND )
Variables ¶
var Contents = Append
Contents determines how the existing contents of the log will be treated. It should be set to either Truncate or Append.
var Formatter = Format
Formatter is what the log uses to format values to strings. It defaults to Format, but can be replaced.
var PathDepth = 1
PathDepth sets how many directories to include when showing file names in calls to Line
var TimeFormat = "2006-01-02_15:04:05.00"
TimeFormat to format time in the log
var Trim uint = 2
Trim removes the bottom layers from the stack trace when calling Line. These are always the runtime and so not useful information.
Functions ¶
func Format ¶
func Format(value interface{}) string
Format takes a value and converts it to a string. It makes sure any string values are wrapped in quotes. Anything fulfilling Val takes priority.
func SetTrace ¶
func SetTrace(start, end, pathDepth int)
SetTrace to include line in default logger log messages
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log writes data to a log. Each entry is one line
func File ¶
File opens a file as a log. If no path is given, it will creat a file in the working directory with the same name as the program followed by ".log". If more than one path is given, everything beyond the first is ingored.
func (*Log) Child ¶
Child creates a new log that uses the same writer. All data passed in will be written on every line written to this log.
func (*Log) Close ¶
Close will close the writer if the underlying type has a Close method. It will only return an error if one is generated while closing the writer. If the writer is not actually a WriterCloser, no error will be returned.
func (*Log) Debug ¶
func (l *Log) Debug(data ...interface{})
Debug will write data to the log only if debug is enabled
func (*Log) Error ¶
Error takes an error and if it is not nil writes it to the log. It returns a bool indicating if there was an error.
func (*Log) Fatal ¶
func (l *Log) Fatal(data ...interface{})
Fatal writes data to the log with the FATAL flag and call os.Exit(1). Fatal should only be called from a main package.
func (*Log) Info ¶
func (l *Log) Info(data ...interface{})
Info writes data to the log with the INFO flag
func (*Log) Panic ¶
Panic takes an error and if it is not nil, writes it to the log then panics. Panic should only be called from a main package.
type Val ¶
type Val interface {
LogVal() string
}
Val takes priority in Format.
func TraceDepth ¶
TraceDepth returns a formatted slice of the stack trace. The start arg determines how close to the calling line to return and end determines how close to the top of the stack trace to return.
If start is positive, that many lines from the beginning will be removed. If start is negative, that is how many lines will be returned (and end will be the anchor).
If end is negative, that is how far from the top of the stack trace end will be. If end is positive, that is how many lines will be returned (and start will be the anchor).
If start is negative and end is positive, then I don't know what happens!