logger

package
v0.15.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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 Flags

func Flags() int

Flags returns the output flags for the standard logger.

func LevelFilter

func LevelFilter() *logutils.LevelFilter

LevelFilter returns a LevelFilter that is configured with the log levels that we use.

func Output

func Output(calldepth int, s string) error

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 Prefix

func Prefix() string

Prefix returns the output prefix for the standard logger.

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 SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

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) V

func (g *GRPCLogger) V(l int) bool

V 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

type GatedWriter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

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.

func (*GatedWriter) Write

func (w *GatedWriter) Write(p []byte) (n int, err error)

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

func (*LogFile) Write

func (l *LogFile) Write(b []byte) (n int, err error)

Write is used to implement io.Writer

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

type LogWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func NewLogWriter(buf int) *LogWriter

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

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (n int, err error)

Write is used to accumulate new logs

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

func New(out io.Writer, prefix string, flag int) *Logger

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) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to l.Printf() 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) Flags

func (l *Logger) Flags() int

Flags returns the output flags for the logger.

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string) error

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) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

Panicf is equivalent to l.Printf() 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) Prefix

func (l *Logger) Prefix() string

Prefix returns the output prefix for the logger.

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

func (l *Logger) Printf(format string, v ...interface{})

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.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the output destination for the logger.

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.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL