Documentation ¶
Index ¶
- Constants
- func Close() error
- func Debug(v ...interface{})
- func DebugPackage(b bool)
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func JSON(data map[string]interface{}, format string, v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetLogger(l Interface)
- type BasicLogable
- type Interface
- type Logable
- type Logger
- type SetLoggerer
- type SwapLogger
- type ToMany
- func (l *ToMany) Append(lg ...Interface) *ToMany
- func (l *ToMany) Close() (err error)
- func (l *ToMany) Len() (n int)
- func (l *ToMany) Loggers() (loggers []Interface)
- func (l *ToMany) Print(v ...interface{})
- func (l *ToMany) Printf(format string, v ...interface{})
- func (l *ToMany) Println(v ...interface{})
- func (l *ToMany) Reset() (loggers []Interface)
- type Writer
Constants ¶
const Discard = devNull(0)
Discard is a logger that discards all log messages.
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 ¶
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.
Types ¶
type BasicLogable ¶
type BasicLogable struct {
// contains filtered or unexported fields
}
BasicLogable provides an embeddable implementation of a Logable.
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 PrefixWith ¶
PrefixWith returns a logger, wrapping the given logger l, that automatically prepends 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 ¶
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 ¶
Close calls Close on each of the associated loggers, if the logger satisfies the io.Closer interface.
func (*ToMany) Print ¶
func (l *ToMany) Print(v ...interface{})
Print logs the given data to the slice of loggers.
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 ¶
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) Write ¶
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 ¶
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 ¶
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 ¶
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'.