blob: 8f8e75c6f60494672721be17075b78c44df9a86f [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vlog
import (
// TODO(cnicolaou): remove this dependency in the future. For now this
// saves us some code.
"github.com/cosnicolaou/llog"
)
type InfoLog interface {
// Info logs to the INFO log.
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
Info(args ...interface{})
// Infoln logs to the INFO log.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
Infof(format string, args ...interface{})
// InfoDepth acts as Info but uses depth to determine which call frame to log.
// A depth of 0 is equivalent to calling Info.
InfoDepth(depth int, args ...interface{})
// InfofDepth acts as Infof but uses depth to determine which call frame to log.
// A depth of 0 is equivalent to calling Infof.
InfofDepth(depth int, format string, args ...interface{})
// InfoStack logs the current goroutine's stack if the all parameter
// is false, or the stacks of all goroutines if it's true.
InfoStack(all bool)
}
type Verbosity interface {
// V returns true if the configured logging level is greater than or equal to its parameter
V(level Level) bool
// VI is like V, except that it returns an instance of the Info
// interface that will either log (if level >= the configured level)
// or discard its parameters. This allows for logger.VI(2).Info
// style usage.
VI(level Level) InfoLog
}
// Level specifies a level of verbosity for V logs.
// It can be set via the Level optional parameter to Configure.
// It implements the flag.Value interface to support command line option parsing.
type Level llog.Level
// Set is part of the flag.Value interface.
func (l *Level) Set(v string) error {
return (*llog.Level)(l).Set(v)
}
// Get is part of the flag.Value interface.
func (l *Level) Get(v string) interface{} {
return *l
}
// String is part of the flag.Value interface.
func (l *Level) String() string {
return (*llog.Level)(l).String()
}
// StderrThreshold identifies the sort of log: info, warning etc.
// The values match the corresponding constants in C++ - e.g WARNING etc.
// It can be set via the StderrThreshold optional parameter to Configure.
// It implements the flag.Value interface to support command line option parsing.
type StderrThreshold llog.Severity
// Set is part of the flag.Value interface.
func (s *StderrThreshold) Set(v string) error {
return (*llog.Severity)(s).Set(v)
}
// Get is part of the flag.Value interface.
func (s *StderrThreshold) Get(v string) interface{} {
return *s
}
// String is part of the flag.Value interface.
func (s *StderrThreshold) String() string {
return (*llog.Severity)(s).String()
}
// ModuleSpec allows for the setting of specific log levels for specific
// modules. The syntax is recordio=2,file=1,gfs*=3
// It can be set via the ModuleSpec optional parameter to Configure.
// It implements the flag.Value interface to support command line option parsing.
type ModuleSpec struct {
llog.ModuleSpec
}
// FilepathSpec allows for the setting of specific log levels for specific
// files matched by a regular expression. The syntax is <re>=3,<re1>=2.
// It can be set via the FilepathSpec optional parameter to Configure.
// It implements the flag.Value interface to support command line option parsing.
type FilepathSpec struct {
llog.FilepathSpec
}
// TraceLocation specifies the location, file:N, which when encountered will
// cause logging to emit a stack trace.
// It can be set via the TraceLocation optional parameter to Configure.
// It implements the flag.Value interface to support command line option parsing.
type TraceLocation struct {
llog.TraceLocation
}
// LevelStats tracks the number of lines of output and number of bytes
// per severity level.
type LevelStats llog.Stats
type Logger interface {
InfoLog
Verbosity
// Flush flushes all pending log I/O.
FlushLog()
// Error logs to the ERROR and INFO logs.
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
Error(args ...interface{})
// ErrorDepth acts as Error but uses depth to determine which call frame to log.
// A depth of 0 is equivalent to calling Error.
ErrorDepth(depth int, args ...interface{})
// Errorf logs to the ERROR and INFO logs.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
Errorf(format string, args ...interface{})
// Fatal logs to the FATAL, ERROR and INFO logs,
// including a stack trace of all running goroutines, then calls os.Exit(255).
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
Fatal(args ...interface{})
// FatalDepth acts as Fatal but uses depth to determine which call frame to log.
// A depth of 0 is equivalent to calling Fatal.
FatalDepth(depth int, args ...interface{})
// Fatalf logs to the FATAL, ERROR and INFO logs,
// including a stack trace of all running goroutines, then calls os.Exit(255).
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
Fatalf(format string, args ...interface{})
// Panic is equivalent to Error() followed by a call to panic().
Panic(args ...interface{})
// PanicDepth acts as Panic but uses depth to determine which call frame to log.
// A depth of 0 is equivalent to calling Panic.
PanicDepth(depth int, args ...interface{})
// Panicf is equivalent to Errorf() followed by a call to panic().
Panicf(format string, args ...interface{})
// Configure configures all future logging. Some options
// may not be usable if Configure is called from an init function,
// in which case an error will be returned. The Configured error is
// returned if ConfigureLogger has already been called unless the
// OverridePriorConfiguration options is included.
// Some options only take effect if they are set before the logger
// is used. Once anything is logged using the logger, these options
// will silently be ignored. For example, LogDir, LogToStderr or
// AlsoLogToStderr fall in this category.
Configure(opts ...LoggingOpts) error
// Stats returns stats on how many lines/bytes haven been written to
// this set of logs per severity level.
Stats() LevelStats
// LogDir returns the currently configured directory for storing logs.
LogDir() string
}