cockroach: github.com/abhinavdahiya/cockroach/util/log Index | Files | Directories

package log

import "github.com/abhinavdahiya/cockroach/util/log"

Package log implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style logging and adaptions for use as a structured logging engine.

Basic examples:

	log.Info("Prepare to repel boarders")

	log.Fatal("Initialization failed", err)

 // Log with context.
 log.Infoc(context, "client error: %s", err)

See the documentation for the V function for an explanation of these examples:

if log.V(2) {
	log.Info("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 flags that modify this behavior. These are provided via the pflags library; see InitFlags.

--logtostderr=true
	Logs are written to standard error instead of to files.
--alsologtostderr=INFO
	Logs are written to standard error as well as to files.
--log-dir=""
	Log files will be written to this directory instead of the
	default temporary directory.

Other flags provide aids to debugging.

--log-backtrace-at=""
	When set to a file and line number holding a logging statement,
	such as
		-log_backtrace_at=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.)
--verbosity=0
	Enable V-leveled logging at the specified level.
--vmodule=""
	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,
		-vmodule=gopher*=3
	sets the V level to 3 in all Go files whose names begin "gopher".

Index

Package Files

clog.go doc.go file.go flags.go log.go structured.go trace.go

Variables

var MaxSize uint64 = 1024 * 1024 * 10

MaxSize is the maximum size of a log file in bytes.

var Stats struct {
    Info, Warning, Error outputStats
}

Stats tracks the number of lines of output and number of bytes per severity level. Values must be read with atomic.LoadInt64.

func DirSet Uses

func DirSet() bool

DirSet returns true of the log directory has been changed from its default.

func DisableLogFileOutput Uses

func DisableLogFileOutput()

DisableLogFileOutput turns off logging. For unittesting only.

func EnableLogFileOutput Uses

func EnableLogFileOutput(dir string)

EnableLogFileOutput turns on logging using the specified directory. For unittesting only.

func Error Uses

func Error(args ...interface{})

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended.

func Errorc Uses

func Errorc(ctx context.Context, format string, args ...interface{})

Errorc logs to the ERROR, WARNING, and INFO logs. It extracts values from Field keys specified in this package and logs them along with the given message and any additional pairs specified as consecutive elements in kvs.

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf logs to the ERROR, WARNING, and INFO logs. Don't use it; use Error Info or Errorc instead. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func ErrorfDepth Uses

func ErrorfDepth(depth int, format string, args ...interface{})

ErrorfDepth logs to the ERROR, WARNING, and INFO logs, offsetting the caller's stack frame by 'depth'. Passing an empty string for `format` causes this method to naturally format `args`.

func Fatal Uses

func Fatal(args ...interface{})

Fatal logs to the INFO, WARNING, ERROR, and FATAL 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.

func FatalOnPanic Uses

func FatalOnPanic()

FatalOnPanic recovers from a panic and exits the process with a Fatal log. This is useful for avoiding a panic being caught through a CGo exported function or preventing HTTP handlers from recovering panics and ignoring them.

func Fatalc Uses

func Fatalc(ctx context.Context, format string, args ...interface{})

Fatalc logs to the INFO, WARNING, ERROR, and FATAL logs, including a stack trace of all running goroutines, then calls os.Exit(255). It extracts values from the context using the Field keys specified in this package and logs them along with the given message and any additional pairs specified as consecutive elements in kvs.

func Fatalf Uses

func Fatalf(format string, args ...interface{})

Fatalf logs to the INFO, WARNING, ERROR, and FATAL 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.

func FatalfDepth Uses

func FatalfDepth(depth int, format string, args ...interface{})

FatalfDepth logs to the INFO, WARNING, ERROR, and FATAL logs, including a stack trace of all running goroutines, then calls os.Exit(255), offsetting the caller's stack frame by 'depth'. Passing an empty string for `format` causes this method to naturally format `args`.

func FetchEntriesFromFiles Uses

func FetchEntriesFromFiles(severity Severity, startTimestamp, endTimestamp int64, maxEntries int,
    pattern *regexp.Regexp) ([]Entry, error)

FetchEntriesFromFiles fetches all available log entires on disk that match the log 'severity' (or worse) and are between the 'startTimestamp' and 'endTimestamp'. It will stop reading new files if the number of entries exceeds 'maxEntries'. Log entries are further filtered by the regexp 'pattern' if provided. The logs entries are returned in reverse chronological order.

func Flush Uses

func Flush()

Flush flushes all pending log I/O.

func GetLogReader Uses

func GetLogReader(filename string, restricted bool) (io.ReadCloser, error)

GetLogReader returns a reader for the specified filename. In restricted mode, the filename must be the base name of a file in this process's log directory (this is safe for cases when the filename comes from external sources, such as the admin UI via HTTP). In unrestricted mode any path is allowed, with the added feature that relative paths will be searched in both the current directory and this process's log directory.

func Info Uses

func Info(args ...interface{})

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended.

func Infoc Uses

func Infoc(ctx context.Context, format string, args ...interface{})

Infoc logs to the WARNING and INFO logs. It extracts values from the context using the Field keys specified in this package and logs them along with the given message and any additional pairs specified as consecutive elements in kvs.

func Infof Uses

func Infof(format string, args ...interface{})

Infof logs to the INFO log. Don't use it; use Info or Infoc instead. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func InfofDepth Uses

func InfofDepth(depth int, format string, args ...interface{})

InfofDepth logs to the INFO log, offsetting the caller's stack frame by 'depth'. Passing an empty string for `format` causes this method to naturally format `args`.

func ListLogFiles Uses

func ListLogFiles() ([]FileInfo, error)

ListLogFiles returns a slice of FileInfo structs for each log file on the local node, in any of the configured log directories.

func NewStdLogger Uses

func NewStdLogger(severity Severity) *stdLog.Logger

NewStdLogger creates a *stdLog.Logger that forwards messages to the Google logs for the specified severity.

func SetExitFunc Uses

func SetExitFunc(f func(int))

SetExitFunc allows setting a function that will be called to exit the process when a Fatal message is generated.

func Trace Uses

func Trace(ctx context.Context, msg string)

Trace looks for an opentracing.Trace in the context and logs the given message to it on success.

func V Uses

func V(level level) bool

V returns true if the logging verbosity is set to the specified level or higher.

func VDepth Uses

func VDepth(level level, depth int) bool

VDepth reports whether verbosity at the call site is at least the requested level.

func Warning Uses

func Warning(args ...interface{})

Warning logs to the WARNING and INFO logs. Warningf logs to the WARNING and INFO logs. Don't use it; use Warning or Arguments are handled in the manner of fmt.Print; a newline is appended.

func Warningc Uses

func Warningc(ctx context.Context, format string, args ...interface{})

Warningc logs to the WARNING and INFO logs. It extracts values from the context using the Field keys specified in this package and logs them along with the given message and any additional pairs specified as consecutive elements in kvs.

func Warningf Uses

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING and INFO logs. Don't use it; use Warning or Warningc instead. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func WarningfDepth Uses

func WarningfDepth(depth int, format string, args ...interface{})

WarningfDepth logs to the WARNING and INFO logs, offsetting the caller's stack frame by 'depth'. Passing an empty string for `format` causes this method to naturally format `args`.

type Entry Uses

type Entry struct {
    Severity int    `json:"severity"` // Log message severity.
    Time     int64  `json:"time"`     // Time, measured in nanoseconds since the epoch.
    File     string `json:"file"`     // File which generated log statement.
    Line     int    `json:"line"`     // Line in file which generated log statement.
    // TODO(pmattis): The json output should be called `message` as well. Need to
    // fix the UI.
    Message string `json:"format"` // Log message.
}

Entry represents a cockroach structured log entry.

type EntryDecoder Uses

type EntryDecoder struct {
    // contains filtered or unexported fields
}

EntryDecoder reads successive encoded log entries from the input buffer. Each entry is preceded by a single big-ending uint32 describing the next entry's length.

func NewEntryDecoder Uses

func NewEntryDecoder(in io.Reader) *EntryDecoder

NewEntryDecoder creates a new instance of EntryDecoder.

func (*EntryDecoder) Decode Uses

func (d *EntryDecoder) Decode(entry *Entry) error

Decode decodes the next log entry into the provided protobuf message.

type FileDetails Uses

type FileDetails struct {
    Program  string
    Host     string
    UserName string
    Severity Severity
    Time     time.Time
    PID      uint
}

A FileDetails holds all of the particulars that can be parsed by the name of a log file.

type FileInfo Uses

type FileInfo struct {
    Name         string // base name
    SizeBytes    int64
    ModTimeNanos int64 // most recent mode time in unix nanos
    Details      FileDetails
}

A FileInfo holds the filename and size of a log file.

type Severity Uses

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++.

const (
    InfoLog Severity = iota
    WarningLog
    ErrorLog
    FatalLog
    NumSeverity = 4
)

These constants identify the log levels in order of increasing Severity. A message written to a high-Severity log file is also written to each lower-Severity log file.

func SeverityByName Uses

func SeverityByName(s string) (Severity, bool)

SeverityByName attempts to parse the passed in string into a severity. (i.e. ERROR, INFO). If it succeeds, the returned bool is set to true.

func (*Severity) Name Uses

func (s *Severity) Name() string

Name returns the string representation of the severity (i.e. ERROR, INFO).

func (*Severity) Set Uses

func (s *Severity) Set(value string) error

Set is part of the flag.Value interface.

func (*Severity) String Uses

func (s *Severity) String() string

String is part of the flag.Value interface.

Directories

PathSynopsis
logflags

Package log imports 24 packages (graph). Updated 2017-03-13. Refresh now. Tools for package owners. This is a dead-end fork (no commits since the fork).