twelf

package
v0.0.0-...-444b24f Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: MIT Imports: 4 Imported by: 8

Documentation

Overview

Package twelf provides a *very* simple logging interface for Twelve-Factor applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(l Logger, fmt string, v ...interface{})

Debug writes a debug log message formatted according to a format specifier.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

fmt is the format specifier, as per fmt.Printf(), etc.

If l is nil, DefaultLogger is used.

func DebugString

func DebugString(l Logger, s string)

DebugString writes a pre-formatted debug log message.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

If l is nil, DefaultLogger is used.

func IsDebug

func IsDebug(l Logger) bool

IsDebug returns true if this logger will perform debug logging.

Generally the application should just call Debug() or DebugString() without calling IsDebug(), however it can be used to check if debug logging is necessary before executing expensive code that is only used to obtain debug information.

If l is nil, DefaultLogger is used.

func Log

func Log(l Logger, fmt string, v ...interface{})

Log writes an application log message formatted according to a format specifier.

It should be ussed for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

fmt is the format specifier, as per fmt.Printf(), etc.

If l is nil, DefaultLogger is used.

func LogString

func LogString(l Logger, s string)

LogString writes a pre-formatted application log message.

It should be ussed for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

If l is nil, DefaultLogger is used.

Types

type BufferedLogMessage

type BufferedLogMessage struct {
	Message string
	IsDebug bool
}

BufferedLogMessage is a log message stored by a BufferedLogger

func (BufferedLogMessage) String

func (m BufferedLogMessage) String() string

type BufferedLogger

type BufferedLogger struct {
	// CaptureDebug controls whether debug messages should be stored.
	CaptureDebug bool
	// contains filtered or unexported fields
}

BufferedLogger is an implementation of Logger that buffers log messages in memory.

func (*BufferedLogger) Debug

func (l *BufferedLogger) Debug(fmt string, v ...interface{})

Debug writes a debug log message formatted according to a format specifier.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

fmt is the format specifier, as per fmt.Printf(), etc.

func (*BufferedLogger) DebugString

func (l *BufferedLogger) DebugString(s string)

DebugString writes a pre-formatted debug log message.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

func (*BufferedLogger) FlushTo

func (l *BufferedLogger) FlushTo(dest Logger)

FlushTo logs the buffered messages to dest, and resets the logger.

func (*BufferedLogger) IsDebug

func (l *BufferedLogger) IsDebug() bool

IsDebug returns true if this logger will perform debug logging.

Generally the application should just call Debug() or DebugString() without calling IsDebug(), however it can be used to check if debug logging is necessary before executing expensive code that is only used to obtain debug information.

func (*BufferedLogger) Log

func (l *BufferedLogger) Log(fmt string, v ...interface{})

Log writes an application log message formatted according to a format specifier.

It should be used for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

fmt is the format specifier, as per fmt.Printf(), etc.

func (*BufferedLogger) LogString

func (l *BufferedLogger) LogString(s string)

LogString writes a pre-formatted application log message.

It should be used for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

func (*BufferedLogger) Messages

func (l *BufferedLogger) Messages() []BufferedLogMessage

Messages returns the messages that have been logged.

func (*BufferedLogger) Reset

func (l *BufferedLogger) Reset()

Reset removes all buffered log messages.

func (*BufferedLogger) TakeMessages

func (l *BufferedLogger) TakeMessages() []BufferedLogMessage

TakeMessages returns the messages that have been logged and resets the logger in a single operation.

type DiscardLogger

type DiscardLogger struct{}

DiscardLogger is a logger that produces no output.

func (DiscardLogger) Debug

func (DiscardLogger) Debug(fmt string, v ...interface{})

Debug is a no-op.

func (DiscardLogger) DebugString

func (DiscardLogger) DebugString(s string)

DebugString is a no-op.

func (DiscardLogger) IsDebug

func (DiscardLogger) IsDebug() bool

IsDebug always returns false.

func (DiscardLogger) Log

func (DiscardLogger) Log(fmt string, v ...interface{})

Log is a no-op.

func (DiscardLogger) LogString

func (DiscardLogger) LogString(s string)

LogString is a no-op.

type Logger

type Logger interface {
	// Log writes an application log message formatted according to a format
	// specifier.
	//
	// It should be ussed for messages that are intended for people responsible for
	// operating the application, such as the end-user or operations staff.
	//
	// fmt is the format specifier, as per fmt.Printf(), etc.
	Log(fmt string, v ...interface{})

	// LogString writes a pre-formatted application log message.
	//
	// It should be ussed for messages that are intended for people responsible for
	// operating the application, such as the end-user or operations staff.
	LogString(s string)

	// Debug writes a debug log message formatted according to a format
	// specifier.
	//
	// If IsDebug() returns false, no logging is performed.
	//
	// It should be used for messages that are intended for the software developers
	// that maintain the application.
	//
	// fmt is the format specifier, as per fmt.Printf(), etc.
	Debug(fmt string, v ...interface{})

	// DebugString writes a pre-formatted debug log message.
	//
	// If IsDebug() returns false, no logging is performed.
	//
	// It should be used for messages that are intended for the software developers
	// that maintain the application.
	DebugString(s string)

	// IsDebug returns true if this logger will perform debug logging.
	//
	// Generally the application should just call Debug() or DebugString() without
	// calling IsDebug(), however it can be used to check if debug logging is
	// necessary before executing expensive code that is only used to obtain debug
	// information.
	IsDebug() bool
}

Logger is an interface for writing log messages.

var (
	// DefaultLogger is a logger that only logs non-debug messages.
	DefaultLogger Logger = &StandardLogger{CaptureDebug: false}

	// DebugLogger is a logger that logs both debug and non-debug messages.
	DebugLogger Logger = &StandardLogger{CaptureDebug: true}

	// SilentLogger is a logger that does not log any messages.
	SilentLogger Logger = DiscardLogger{}
)

type StandardLogger

type StandardLogger struct {
	// Target is the standard Go logger used to write messages. If is is nil, logs
	// are sent to STDOUT as per the 12-factor logging recomendations. Note that
	// this differs to Go's default logger, which writes to STDERR.
	Target *log.Logger

	// CaptureDebug controls whether debug messages should be written to the target
	// logger.
	CaptureDebug bool
}

StandardLogger is an implementation of Logger that uses Go's standard logger package.

func (*StandardLogger) Debug

func (l *StandardLogger) Debug(fmt string, v ...interface{})

Debug writes a debug log message formatted according to a format specifier.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

fmt is the format specifier, as per fmt.Printf(), etc.

func (*StandardLogger) DebugString

func (l *StandardLogger) DebugString(s string)

DebugString writes a pre-formatted debug log message.

If IsDebug() returns false, no logging is performed.

It should be used for messages that are intended for the software developers that maintain the application.

func (*StandardLogger) IsDebug

func (l *StandardLogger) IsDebug() bool

IsDebug returns true if this logger will perform debug logging.

Generally the application should just call Debug() or DebugString() without calling IsDebug(), however it can be used to check if debug logging is necessary before executing expensive code that is only used to obtain debug information.

func (*StandardLogger) Log

func (l *StandardLogger) Log(fmt string, v ...interface{})

Log writes an application log message formatted according to a format specifier.

It should be ussed for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

fmt is the format specifier, as per fmt.Printf(), etc.

func (*StandardLogger) LogString

func (l *StandardLogger) LogString(s string)

LogString writes a pre-formatted application log message.

It should be ussed for messages that are intended for people responsible for operating the application, such as the end-user or operations staff.

Jump to

Keyboard shortcuts

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