log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: CC0-1.0 Imports: 10 Imported by: 11

Documentation

Index

Constants

View Source
const Discard = devNull(0)

Discard is a logger that discards all log messages.

View Source
const Stderr = stderr(0)

Stderr logs all messages to os.Stderr

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the global logger, if it satisfies the io.Closer interface. Otherwise it does nothing.

func Debug

func Debug(v ...interface{})

Debug prints to the global logger, provided that debugging is turned on for this package (using DebugPackage). Arguments are handled in the manner of fmt.Print. It is permitted for the logger to silently drop log messages.

func DebugPackage

func DebugPackage(b bool)

DebugPackage toggles debugging logging for the current package. A value of 'true' turns on debugging for the current package, and a value of 'false' turns off debugging for the current package. Calls to Debug() in a given package produce non-empty output only if debugging is turned on for that package. By default, debugging is turned off in every package. The current package name is inferred from the source filename, and determined to be everything up to but not including the last occurrence of '/'.

func Debugf

func Debugf(format string, v ...interface{})

Debugf prints to the global logger, provided that debugging is turned on for this package (using DebugPackage). Arguments are handled in the manner of fmt.Printf. It is permitted for the logger to silently drop log messages.

func Debugln

func Debugln(v ...interface{})

Debugln prints to the global logger, provided that debugging is turned on for this package (using DebugPackage). Arguments are handled in the manner of fmt.Println. It is permitted for the logger to silently drop log messages.

func JSON

func JSON(data map[string]interface{}, format string, v ...interface{})

JSON prints to the global logger. The first argument data will be marshalled into JSON format using the Marshal function in the standard encoding/json package. The last two arguments define a message to be logged alongside data, and are handled in the manner of fmt.Printf. It is permitted for the logger to silently drop log messages.

func Print

func Print(v ...interface{})

Print prints to the global logger. Arguments are handled in the manner of fmt.Print. It is permitted for the logger to silently drop log messages.

func Printf

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

Printf prints to the global logger. Arguments are handled in the manner of fmt.Printf. It is permitted for the logger to silently drop log messages.

func Println

func Println(v ...interface{})

Println prints to the global logger. Arguments are handled in the manner of fmt.Println. It is permitted for the logger to silently drop log messages.

func SetLogger

func SetLogger(l Interface)

SetLogger changes the global logger to l.

Types

type BasicLogable

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

BasicLogable provides an embeddable implementation of a Logable.

func (*BasicLogable) Log

func (b *BasicLogable) Log() Interface

Log returns the logger.

func (*BasicLogable) SetLogger

func (b *BasicLogable) SetLogger(l Interface)

SetLogger sets the logger.

type Interface

type Interface interface {
	Printf(format string, v ...interface{})
}

Interface describing a logging object. There is no guarantee that a call to Printf will result in the message being successfully logged; the contract with the user is simply that the logger will do "its best". You should be prepared for the possibility that some log messages are silently dropped.

func Log

func Log() Interface

Log returns the current global logger.

func PrefixWith

func PrefixWith(l Interface, format string, v ...interface{}) Interface

PrefixWith returns a logger, wrapping the given logger l, that automatically prepends the given data to all log messages.

func ToLog

func ToLog(l Logger) Interface

ToLog allows logging directly to the given Logger.

func With

func With(l Interface, format string, v ...interface{}) Interface

With returns a logger, wrapping the given logger l, that automatically appends the given data to all log messages.

type Logable

type Logable interface {
	SetLoggerer
	Logger
}

Logable is the interface satisfied by the SetLogger and Log methods. It indicates an object that supports logging.

type Logger

type Logger interface {
	Log() Interface // Log returns the logger.
}

Logger is the interface satisfied by the Log method.

type SetLoggerer

type SetLoggerer interface {
	SetLogger(l Interface) // SetLogger sets a logger.
}

SetLoggerer is the interface satisfied by the SetLogger method.

type SwapLogger

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

SwapLogger wraps a logger that may be safely replaced while other go routines use the SwapLogger concurrently. The zero value for a SwapLogger will discard all log events without error.

func (*SwapLogger) Close

func (l *SwapLogger) Close() error

Close calls Close on the wrapped logger, if the wrapped logger satisfies the io.Closer interface. Otherwise it does nothing.

func (*SwapLogger) Print

func (l *SwapLogger) Print(v ...interface{})

Print logs the given data to the wrapped logger. It does not log anything if the wrapped logger is nil.

func (*SwapLogger) Printf

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

Printf logs the given message to the wrapped logger. It does not log anything if the wrapped logger is nil.

func (*SwapLogger) Println

func (l *SwapLogger) Println(v ...interface{})

Println logs the given data to the wrapped logger. It does not log anything if the wrapped logger is nil.

func (*SwapLogger) Swap

func (l *SwapLogger) Swap(lg Interface)

Swap replaces the currently wrapped logger with lg. This will panic if l is nil.

func (*SwapLogger) Unwrap

func (l *SwapLogger) Unwrap() Interface

Unwrap returns the wrapped logger. If the wrapped logger is nil, then Discard is returned.

type ToMany

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

ToMany combines multiple loggers, sending all log messages to each of loggers. ToMany is safe to be used concurrently. The zero value for a ToMany will discard all log events without an error.

func (*ToMany) Append

func (l *ToMany) Append(lg ...Interface) *ToMany

Append appends the given loggers to the slice of loggers being logged to. This will panic if l is nil. Returns l in order to simplify usage: for example,

l := new(log.ToMany).Append(lg, log.Stderr)

func (*ToMany) Close

func (l *ToMany) Close() (err error)

Close calls Close on each of the associated loggers, if the logger satisfies the io.Closer interface.

func (*ToMany) Len

func (l *ToMany) Len() (n int)

Len returns the number of loggers being logged to.

func (*ToMany) Loggers

func (l *ToMany) Loggers() (loggers []Interface)

Loggers returns the slice of loggers being logged to.

func (*ToMany) Print

func (l *ToMany) Print(v ...interface{})

Print logs the given data to the slice of loggers.

func (*ToMany) Printf

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

Printf logs the given message to the slice of loggers.

func (*ToMany) Println

func (l *ToMany) Println(v ...interface{})

Println logs the given data to the slice of loggers.

func (*ToMany) Reset

func (l *ToMany) Reset() (loggers []Interface)

Reset returns the current slice of loggers, and empties this slice.

type Writer

type Writer struct {
	L Interface // The logger
	// contains filtered or unexported fields
}

Writer wraps a logger and implements the io.Writer interface. Data written to the writer will be buffered until a new line '\n', at which point the buffered data will be passed to the underlying logger.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered bytes to the underlying logger. The returned error is always nil, but is included to match bufio.Writer's Flush.

func (*Writer) Len

func (w *Writer) Len() int

Len returns the number of bytes in the buffer.

func (*Writer) Write

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

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge. Buffered bytes will be written to the underlying logger upon encountering a new line '\n'.

func (*Writer) WriteByte

func (w *Writer) WriteByte(c byte) error

WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge. Buffered bytes will be written to the underlying logger upon encountering a new line '\n'.

func (*Writer) WriteRune

func (w *Writer) WriteRune(r rune) (n int, err error)

WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge. Buffered bytes will be written to the underlying logger upon encountering a new line '\n'.

func (*Writer) WriteString

func (w *Writer) WriteString(s string) (n int, err error)

WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge. Buffered bytes will be written to the underlying logger upon encountering a new line '\n'.

Jump to

Keyboard shortcuts

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