golog

package
v0.0.0-...-61e6862 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2015 License: MIT Imports: 6 Imported by: 72

Documentation

Overview

Package golog provides a customizable logging class which can be used as a standalone or as a building block for other loggers.

Basic example:

logger := golog.New(os.Stdout, log.Info)
logger.Info("Connecting to the server...")
logger.Errorf("Connection failed: %q", err)

Will output:

2014-04-02 18:09:15.862 INFO Connecting to the API...
2014-04-02 18:10:14.347 ERROR Connection failed (Server is unavailable).

Log*() functions can be used to avoid evaluating arguments when it is expensive and unnecessary:

logger.Debug("Memory usage: %s", getMemoryUsage())
if logger.LogDebug() { logger.Debug("Memory usage: %s", getMemoryUsage()) }

If debug logging is off getMemoryUsage() will be executed on the first line while it will not be executed on the second line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	Formatter func(*bytes.Buffer, log.Level, ...interface{})
	Writer    func(io.Writer, []byte, log.Level)
	// 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, threshold log.Level) *Logger

New creates a new Logger. The out variable sets the destination to which log data will be written. The threshold variable defines the level under which logging will be ignored.

func (*Logger) Alert

func (logger *Logger) Alert(args ...interface{})

Alert logs with an alert level.

func (*Logger) Alertf

func (logger *Logger) Alertf(format string, args ...interface{})

Alertf logs with an alert level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Close

func (logger *Logger) Close() error

Close does nothing and is just here so that Logger satisfies the log.Logger interface.

func (*Logger) Critical

func (logger *Logger) Critical(args ...interface{})

Critical logs with a critical level.

func (*Logger) Criticalf

func (logger *Logger) Criticalf(format string, args ...interface{})

Criticalf logs with a critical level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Debug

func (logger *Logger) Debug(args ...interface{})

Debug logs with a debug level.

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, args ...interface{})

Debugf logs with a debug level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Emergency

func (logger *Logger) Emergency(args ...interface{})

Emergency logs with an emergency level.

func (*Logger) Emergencyf

func (logger *Logger) Emergencyf(format string, args ...interface{})

Emergencyf logs with an emergency level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Error

func (logger *Logger) Error(args ...interface{})

Error logs with an error level.

func (*Logger) Errorf

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

Errorf logs with an error level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Info

func (logger *Logger) Info(args ...interface{})

Info logs with an info level.

func (*Logger) Infof

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

Infof logs with an info level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Log

func (logger *Logger) Log(level log.Level, args ...interface{})

Log logs at the level passed in argument.

func (*Logger) LogAlert

func (logger *Logger) LogAlert() bool

LogAlert returns true if the log level is at alert or lower.

func (*Logger) LogCritical

func (logger *Logger) LogCritical() bool

LogCritical returns true if the log level is at critical or lower.

func (*Logger) LogDebug

func (logger *Logger) LogDebug() bool

LogDebug returns true only if the log level is at debug.

func (*Logger) LogEmergency

func (logger *Logger) LogEmergency() bool

LogEmergency returns true if the log level is at emergency or lower.

func (*Logger) LogError

func (logger *Logger) LogError() bool

LogError returns true if the log level is at error or lower.

func (*Logger) LogInfo

func (logger *Logger) LogInfo() bool

LogInfo returns true if the log level is at info or debug.

func (*Logger) LogLevel

func (logger *Logger) LogLevel(level log.Level) bool

LogLevel returns true if the log level is at or below the level argument.

func (*Logger) LogNotice

func (logger *Logger) LogNotice() bool

LogNotice returns true if the log level is at notice or lower.

func (*Logger) LogWarning

func (logger *Logger) LogWarning() bool

LogWarning returns true if the log level is at warning or lower.

func (*Logger) Logf

func (logger *Logger) Logf(level log.Level, format string, args ...interface{})

Logf logs at the level passed in argument. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Notice

func (logger *Logger) Notice(args ...interface{})

Notice logs with a notice level.

func (*Logger) Noticef

func (logger *Logger) Noticef(format string, args ...interface{})

Noticef logs with a notice level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Warning

func (logger *Logger) Warning(args ...interface{})

Warning logs with a warning level.

func (*Logger) Warningf

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

Warningf logs with a warning level. Arguments are handled in the manner of fmt.Printf.

Jump to

Keyboard shortcuts

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