Documentation ¶
Index ¶
- Constants
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func Flags() int
- func LevelFilter() *logutils.LevelFilter
- func Output(calldepth int, s string) error
- 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 Setup(config *Config, ui cli.Ui) (*logutils.LevelFilter, *GatedWriter, *LogWriter, io.Writer, bool)
- func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool
- type Config
- type GRPCLogger
- func (g *GRPCLogger) Error(args ...interface{})
- func (g *GRPCLogger) Errorf(format string, args ...interface{})
- func (g *GRPCLogger) Errorln(args ...interface{})
- func (g *GRPCLogger) Fatal(args ...interface{})
- func (g *GRPCLogger) Fatalf(format string, args ...interface{})
- func (g *GRPCLogger) Fatalln(args ...interface{})
- func (g *GRPCLogger) Info(args ...interface{})
- func (g *GRPCLogger) Infof(format string, args ...interface{})
- func (g *GRPCLogger) Infoln(args ...interface{})
- func (g *GRPCLogger) V(l int) bool
- func (g *GRPCLogger) Warning(args ...interface{})
- func (g *GRPCLogger) Warningf(format string, args ...interface{})
- func (g *GRPCLogger) Warningln(args ...interface{})
- type GatedWriter
- type LogFile
- type LogHandler
- type LogWriter
- type Logger
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) Flags() int
- func (l *Logger) Output(calldepth int, s string) 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) Writer() io.Writer
- type SyslogWrapper
Constants ¶
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone LstdFlags = Ldate | Ltime | Lshortfile | Lmicroseconds // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, duce,
2009/01/23 0
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
func Fatal(v ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func Fatalln ¶
func Fatalln(v ...interface{})
Fatalln is equivalent to Println() followed by a call to os.Exit(1).
func LevelFilter ¶
func LevelFilter() *logutils.LevelFilter
LevelFilter returns a LevelFilter that is configured with the log levels that we use.
func Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.
func Panic ¶
func Panic(v ...interface{})
Panic is equivalent to Print() followed by a call to panic().
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf is equivalent to Printf() followed by a call to panic().咯个
func Panicln ¶
func Panicln(v ...interface{})
Panicln is equivalent to Println() followed by a call to panic().
func Print ¶
func Print(v ...interface{})
Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.
func Println ¶
func Println(v ...interface{})
Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the output prefix for the standard logger.
func Setup ¶
func Setup(config *Config, ui cli.Ui) (*logutils.LevelFilter, *GatedWriter, *LogWriter, io.Writer, bool)
Setup is used to perform setup of several logging objects:
- A LevelFilter is used to perform filtering by log level.
- A GatedWriter is used to buffer logs until startup UI operations are complete. After this is flushed then logs flow directly to output destinations.
- A LogWriter provides a mean to temporarily hook logs, such as for running a command like "consul monitor".
- An io.Writer is provided as the sink for all logs to flow to.
The provided ui object will get any log messages related to setting up logging itself, and will also be hooked up to the gated logger. The final bool parameter indicates if logging was set up successfully.
func ValidateLevelFilter ¶
func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool
ValidateLevelFilter verifies that the log levels within the filter are valid.
Types ¶
type Config ¶
type Config struct { // LogLevel is the minimum level to be logged. LogLevel string // EnableSyslog controls forwarding to syslog. EnableSyslog bool // SyslogFacility is the destination for syslog forwarding. SyslogFacility string //LogFilePath is the path to write the logs to the user specified file. LogFilePath string //LogRotateDuration is the user specified time to rotate logs LogRotateDuration time.Duration //LogRotateBytes is the user specified byte limit to rotate logs LogRotateBytes int //LogRotateMaxFiles is the maximum number of past archived log files to keep LogRotateMaxFiles int }
Config is used to set up logging.
type GRPCLogger ¶
type GRPCLogger struct {
// contains filtered or unexported fields
}
GRPCLogger wrapps a *log.Logger and implements the grpclog.LoggerV2 interface allowing gRPC servers to log to the standard Consul logger.
func NewGRPCLogger ¶
func NewGRPCLogger(config *Config, logger *log.Logger) *GRPCLogger
NewGRPCLogger creates a grpclog.LoggerV2 that will output to the supplied logger with Severity/Verbosity level appropriate for the given config.
Note that grpclog has Info, Warning, Error, Fatal severity levels AND integer verbosity levels for additional info. Verbose logs in glog are always INFO severity so we map Info,V0 to INFO, Info,V1 to DEBUG, and Info,V>1 to TRACE.
func (*GRPCLogger) Error ¶
func (g *GRPCLogger) Error(args ...interface{})
Error implements grpclog.LoggerV2
func (*GRPCLogger) Errorf ¶
func (g *GRPCLogger) Errorf(format string, args ...interface{})
Errorf implements grpclog.LoggerV2
func (*GRPCLogger) Errorln ¶
func (g *GRPCLogger) Errorln(args ...interface{})
Errorln implements grpclog.LoggerV2
func (*GRPCLogger) Fatal ¶
func (g *GRPCLogger) Fatal(args ...interface{})
Fatal implements grpclog.LoggerV2
func (*GRPCLogger) Fatalf ¶
func (g *GRPCLogger) Fatalf(format string, args ...interface{})
Fatalf implements grpclog.LoggerV2
func (*GRPCLogger) Fatalln ¶
func (g *GRPCLogger) Fatalln(args ...interface{})
Fatalln implements grpclog.LoggerV2
func (*GRPCLogger) Info ¶
func (g *GRPCLogger) Info(args ...interface{})
Info implements grpclog.LoggerV2
func (*GRPCLogger) Infof ¶
func (g *GRPCLogger) Infof(format string, args ...interface{})
Infof implements grpclog.LoggerV2
func (*GRPCLogger) Infoln ¶
func (g *GRPCLogger) Infoln(args ...interface{})
Infoln implements grpclog.LoggerV2
func (*GRPCLogger) Warning ¶
func (g *GRPCLogger) Warning(args ...interface{})
Warning implements grpclog.LoggerV2
func (*GRPCLogger) Warningf ¶
func (g *GRPCLogger) Warningf(format string, args ...interface{})
Warningf implements grpclog.LoggerV2
func (*GRPCLogger) Warningln ¶
func (g *GRPCLogger) Warningln(args ...interface{})
Warningln implements grpclog.LoggerV2
type GatedWriter ¶
GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.
func (*GatedWriter) Flush ¶
func (w *GatedWriter) Flush()
Flush tells the GatedWriter to flush any buffered data and to stop buffering.
type LogFile ¶
type LogFile struct { //LastCreated represents the creation time of the latest log LastCreated time.Time //FileInfo is the pointer to the current file being written to FileInfo *os.File //MaxBytes is the maximum number of desired bytes for a log file MaxBytes int //BytesWritten is the number of bytes written in the current log file BytesWritten int64 // Max rotated files to keep before removing them. MaxFiles int // contains filtered or unexported fields }
LogFile is used to setup a file based logger that also performs log rotation
type LogHandler ¶
type LogHandler interface {
HandleLog(string)
}
LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism
type LogWriter ¶
LogWriter implements io.Writer so it can be used as a log sink. It maintains a circular buffer of logs, and a set of handlers to which it can stream the logs to.
func NewLogWriter ¶
NewLogWriter creates a LogWriter with the given buffer capacity
func (*LogWriter) DeregisterHandler ¶
func (l *LogWriter) DeregisterHandler(lh LogHandler)
DeregisterHandler removes a LogHandler and prevents more invocations
func (*LogWriter) RegisterHandler ¶
func (l *LogWriter) RegisterHandler(lh LogHandler)
RegisterHandler adds a log handler to receive logs, and sends the last buffered logs to the handler
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 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 variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(v ...interface{})
Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
func (*Logger) Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.
func (*Logger) Panic ¶
func (l *Logger) Panic(v ...interface{})
Panic is equivalent to l.Print() followed by a call to panic().
func (*Logger) Panicln ¶
func (l *Logger) Panicln(v ...interface{})
Panicln is equivalent to l.Println() followed by a call to panic().
func (*Logger) Print ¶
func (l *Logger) Print(v ...interface{})
Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Printf ¶
Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.
type SyslogWrapper ¶
type SyslogWrapper struct {
// contains filtered or unexported fields
}
SyslogWrapper is used to cleanup log messages before writing them to a Syslogger. Implements the io.Writer interface.