Documentation
¶
Index ¶
- Variables
- func CloseTestLog()
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Log(level LogLevel, v ...interface{})
- func Logf(level LogLevel, format string, v ...interface{})
- func NewSyncWriter(writer io.Writer) io.Writer
- func SetDefaultLogger(logger *Logger)
- func SetTestLog(t TestLogInterface)
- func Stderr() io.Writer
- func Stdout() io.Writer
- func Trace(v ...interface{})
- func Tracef(format string, v ...interface{})
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- type AsyncHandler
- type Closer
- type ConsoleHandler
- type DiscardHandler
- type FileHandler
- type Handler
- type LevelFilter
- type LevelFilterChain
- func (h *LevelFilterChain) GetHandler() Handler
- func (h *LevelFilterChain) GetNextHandler() Handler
- func (h *LevelFilterChain) LogEntry(logEntry LogEntry) error
- func (h *LevelFilterChain) SetHandler(handler Handler)
- func (h *LevelFilterChain) SetLevel(minLevel LogLevel) *LevelFilterChain
- func (h *LevelFilterChain) SetNextHandler(handler Handler)
- func (h *LevelFilterChain) SetPrefix(prefix string) Handler
- type LogEntry
- type LogLevel
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) GetHandler() Handler
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Log(level LogLevel, v ...interface{})
- func (l *Logger) LogEntry(logEntry LogEntry) error
- func (l *Logger) Logf(level LogLevel, format string, v ...interface{})
- func (l *Logger) SetHandler(handler Handler)
- func (l *Logger) SetPrefix(prefix string) Handler
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- type MemoryHandler
- func (h *MemoryHandler) Empty() bool
- func (h *MemoryHandler) LogEntry(logEntry LogEntry) error
- func (h *MemoryHandler) Logs() []string
- func (h *MemoryHandler) Pop() string
- func (h *MemoryHandler) PopWithLevel() (level LogLevel, prefix, message string)
- func (h *MemoryHandler) Reset()
- func (h *MemoryHandler) SetPrefix(prefix string) Handler
- func (h *MemoryHandler) Size() int64
- func (h *MemoryHandler) TransferTo(receiver Handler) bool
- type MiddlewareHandler
- type Prefixer
- type SafeHandler
- type StandardLogHandler
- type StandardLogger
- func (l *StandardLogger) Fatal(v ...interface{})
- func (l *StandardLogger) Fatalf(format string, v ...interface{})
- func (l *StandardLogger) Fatalln(v ...interface{})
- func (l *StandardLogger) Panic(v ...interface{})
- func (l *StandardLogger) Panicf(format string, v ...interface{})
- func (l *StandardLogger) Panicln(v ...interface{})
- func (l *StandardLogger) Print(v ...interface{})
- func (l *StandardLogger) Printf(format string, v ...interface{})
- func (l *StandardLogger) Println(v ...interface{})
- func (l *StandardLogger) RegisterExitFunc(exitFunc func()) *StandardLogger
- type TeeHandler
- type TestHandler
- type TestLogInterface
- type TextHandler
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoRegisteredHandler = errors.New("no registered handler") ErrHandlerClosed = errors.New("handler is closed") ErrMessageDiscarded = errors.New("this message is not going anywhere") ErrNoPrimaryHandler = errors.New("no primary handler registered") ErrNoBackupHandler = errors.New("no backup handler registered") )
All errors that can be returned by the clog package
Functions ¶
func CloseTestLog ¶ added in v0.1.0
func CloseTestLog()
CloseTestLog at the end of the test otherwise the logger will keep a reference on t. For a description on how to use it, see SetTestLog()
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf sends error information to the console
func Log ¶
func Log(level LogLevel, v ...interface{})
Log sends a log entry with the specified level
func NewSyncWriter ¶ added in v0.10.0
NewSyncWriter creates a thread-safe io.Writer
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger sets the logger used when using the package methods
func SetTestLog ¶
func SetTestLog(t TestLogInterface)
SetTestLog install a test logger as the default logger. A test logger redirects all logs sent through the package methods to the Log/Logf methods of your test
IMPORTANT: don't forget to CloseTestLog() at the end of the test
Example:
func TestLog(t *testing.T) { SetTestLog(t) defer CloseTestLog() // These two calls are equivalent: clog.Debug("debug message") t.Log("debug message") }
func Stderr ¶ added in v0.4.0
Stderr returns a thread-safe io.Writer to os.Stderr. Calling this function multiple times always returns the same instance of io.Writer.
func Stdout ¶ added in v0.4.0
Stdout returns a thread-safe io.Writer to os.Stdout. Calling this function multiple times always returns the same instance of io.Writer.
func Trace ¶ added in v0.6.0
func Trace(v ...interface{})
Trace sends trace information for heavy debugging
Types ¶
type AsyncHandler ¶ added in v0.7.0
type AsyncHandler struct {
// contains filtered or unexported fields
}
AsyncHandler asynchronously send log messages to the next handler in the chain
Example ¶
// Close the async handler before finishing your application or you might miss the last few log messages handler := NewAsyncHandler(NewTextHandler("async ", 0)) defer handler.Close() logger := NewLogger(handler) logger.Info("hello world")
Output: async hello world
func NewAsyncHandler ¶ added in v0.7.0
func NewAsyncHandler(destination Handler) *AsyncHandler
NewAsyncHandler returns a handler that sends logs asynchronously.
func NewAsyncHandlerWithCapacity ¶ added in v0.7.0
func NewAsyncHandlerWithCapacity(next Handler, capacity uint) *AsyncHandler
NewAsyncHandlerWithCapacity returns a handler that sends logs asynchronously.
func (*AsyncHandler) Close ¶ added in v0.7.0
func (h *AsyncHandler) Close()
Close blocks until all log messages have been delivered
func (AsyncHandler) GetHandler ¶ added in v0.7.0
func (h AsyncHandler) GetHandler() Handler
GetHandler returns the next handler in the chain
func (*AsyncHandler) LogEntry ¶ added in v0.7.0
func (h *AsyncHandler) LogEntry(logEntry LogEntry) error
LogEntry sends the log message asynchronously to the next handler. Please note the call will block when the buffer capacity is reached. It will return an error if there's no "next" handler, of if we called the Close method. Otherwise it will always return nil as it doesn't know if the message will be delivered.
func (AsyncHandler) SetHandler ¶ added in v0.7.0
func (h AsyncHandler) SetHandler(handler Handler)
SetHandler sets the next handler in the chain
func (*AsyncHandler) SetPrefix ¶ added in v0.7.0
func (h *AsyncHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type Closer ¶ added in v0.12.0
type Closer interface {
Close() error
}
Closer is an optional interface on handler that supports closing its output
type ConsoleHandler ¶
type ConsoleHandler struct {
// contains filtered or unexported fields
}
ConsoleHandler logs messages to the console (in colour)
func NewConsoleHandler ¶
func NewConsoleHandler(prefix string, flag int) *ConsoleHandler
NewConsoleHandler creates a new handler to send logs to the console
func (*ConsoleHandler) Colouring ¶
func (h *ConsoleHandler) Colouring(colouring bool) *ConsoleHandler
Colouring activate of deactivate displaying messages in colour in the console, and returns the ConsoleHandler for chaining.
func (*ConsoleHandler) LogEntry ¶
func (h *ConsoleHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level
func (*ConsoleHandler) SetPrefix ¶ added in v0.5.0
func (h *ConsoleHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message, and returns the Handler interface for chaining.
func (*ConsoleHandler) SetTheme ¶
func (h *ConsoleHandler) SetTheme(theme string) *ConsoleHandler
SetTheme sets a new color theme, and returns the ConsoleHandler for chaining. Accepted values are: "none", "light", "dark"
type DiscardHandler ¶
type DiscardHandler struct{}
DiscardHandler forgets any log message
func NewDiscardHandler ¶ added in v0.4.0
func NewDiscardHandler() *DiscardHandler
NewDiscardHandler returns a handler that forgets all the logs you throw at it.
func (*DiscardHandler) LogEntry ¶
func (h *DiscardHandler) LogEntry(LogEntry) error
LogEntry discards the LogEntry
type FileHandler ¶
type FileHandler struct { *StandardLogHandler // contains filtered or unexported fields }
FileHandler logs messages to a file
func NewFileHandler ¶
func NewFileHandler(filename string, prefix string, flag int) (*FileHandler, error)
NewFileHandler creates a new file logger
Remember to Close() the logger at the end
func (*FileHandler) Close ¶
func (l *FileHandler) Close()
Close the logfile when no longer needed
please note this method reinstate the standard console output as default
type Handler ¶
Handler for a logger.
The LogEntry method should return an error if the handler didn't manage to save the log (file, remote, etc.) It's up to the parent handler to take action on the error: the default Logger is always going to ignore it.
type LevelFilter ¶
type LevelFilter struct {
// contains filtered or unexported fields
}
LevelFilter is a log middleware that is only passing log entries of level >= minimum level
Example ¶
logger := NewLogger(NewLevelFilter(LevelInfo, NewTextHandler("", 0))) logger.Debug("won't be displayed") logger.Info("hello world")
Output: hello world
func NewLevelFilter ¶
func NewLevelFilter(minLevel LogLevel, destination Handler) *LevelFilter
NewLevelFilter creates a new LevelFilter handler passing log entries to destination if level >= minimum level
func (*LevelFilter) GetHandler ¶
func (h *LevelFilter) GetHandler() Handler
GetHandler returns the current handler used by the filter
func (*LevelFilter) LogEntry ¶
func (h *LevelFilter) LogEntry(logEntry LogEntry) error
LogEntry the LogEntry
func (*LevelFilter) SetHandler ¶
func (h *LevelFilter) SetHandler(handler Handler)
SetHandler sets a new handler for the filter
func (*LevelFilter) SetLevel ¶
func (h *LevelFilter) SetLevel(minLevel LogLevel) *LevelFilter
SetLevel changes the minimum level the log entries are going to be sent to the destination logger
func (*LevelFilter) SetPrefix ¶ added in v0.5.0
func (h *LevelFilter) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type LevelFilterChain ¶ added in v0.9.0
type LevelFilterChain struct {
// contains filtered or unexported fields
}
LevelFilterChain is a log middleware that is only passing log entries of level >= minimum level
Example ¶
logger := NewLogger( NewLevelFilterChain(LevelInfo, NewTextHandler("info and more: ", 0), NewLevelFilterChain(LevelDebug, NewTextHandler("debug: ", 0), nil))) logger.Debug("some debug") logger.Info("some info")
Output: debug: some debug info and more: some info
func NewLevelFilterChain ¶ added in v0.9.0
func NewLevelFilterChain(minLevel LogLevel, destination, next Handler) *LevelFilterChain
NewLevelFilterChain creates a new LevelFilterChain handler passing log entries to destination handler if level >= minimum level, and passing them to next handler if level < minimum level
func (*LevelFilterChain) GetHandler ¶ added in v0.9.0
func (h *LevelFilterChain) GetHandler() Handler
GetHandler returns the current handler used by the filter
func (*LevelFilterChain) GetNextHandler ¶ added in v0.9.0
func (h *LevelFilterChain) GetNextHandler() Handler
GetNextHandler returns the next handler in chain
func (*LevelFilterChain) LogEntry ¶ added in v0.9.0
func (h *LevelFilterChain) LogEntry(logEntry LogEntry) error
LogEntry the LogEntry
func (*LevelFilterChain) SetHandler ¶ added in v0.9.0
func (h *LevelFilterChain) SetHandler(handler Handler)
SetHandler sets a new handler for the filter
func (*LevelFilterChain) SetLevel ¶ added in v0.9.0
func (h *LevelFilterChain) SetLevel(minLevel LogLevel) *LevelFilterChain
SetLevel changes the minimum level the log entries are going to be sent to the destination logger
func (*LevelFilterChain) SetNextHandler ¶ added in v0.9.0
func (h *LevelFilterChain) SetNextHandler(handler Handler)
SetNextHandler sets the next handler in chain
func (*LevelFilterChain) SetPrefix ¶ added in v0.9.0
func (h *LevelFilterChain) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type LogEntry ¶
type LogEntry struct { Calldepth int // Calldepth is used to calculate the right place where we called the log method Level LogLevel // Debug, Info, Warning or Error Format string // Format for *printf (leave blank for *print) Values []interface{} // Values for *print and *printf OR a string func at index 0 with params from index 1 }
LogEntry represents a log entry
func NewLogEntry ¶ added in v0.5.0
NewLogEntry creates a new LogEntry composed of values.
values parameter is comparable to fmt.Sprint(values...)
func NewLogEntryf ¶ added in v0.5.0
NewLogEntryf creates a new formatted LogEntry with values.
parameters are comparable to fmt.Sprintf(format, values...)
func (LogEntry) GetMessage ¶
GetMessage returns the formatted message from Format & Values
func (LogEntry) GetMessageWithLevelPrefix ¶
GetMessageWithLevelPrefix returns the formatted message from Format & Values prefixed with the level name
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger frontend
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
GetDefaultLogger returns the logger used when using the package methods
func NewConsoleLogger ¶
func NewConsoleLogger() *Logger
NewConsoleLogger is a shortcut to create a Logger with a ConsoleHandler
func NewFilteredConsoleLogger ¶
NewFilteredConsoleLogger is a shortcut to create a Logger with a FilteredHandler sending to a ConsoleHandler
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error sends error information to the console
func (*Logger) GetHandler ¶
GetHandler returns the current handler used by the logger
func (*Logger) SetHandler ¶
SetHandler sets a new handler for the logger
func (*Logger) Trace ¶ added in v0.6.0
func (l *Logger) Trace(v ...interface{})
Trace sends trace information for heavy debugging
type MemoryHandler ¶
type MemoryHandler struct {
// contains filtered or unexported fields
}
MemoryHandler save messages in memory (useful for unit testing).
func NewMemoryHandler ¶
func NewMemoryHandler() *MemoryHandler
NewMemoryHandler creates a new MemoryHandler that keeps logs in memory.
func (*MemoryHandler) Empty ¶ added in v0.13.0
func (h *MemoryHandler) Empty() bool
Empty return true when the internal list of logs is empty
func (*MemoryHandler) LogEntry ¶
func (h *MemoryHandler) LogEntry(logEntry LogEntry) error
LogEntry keep the message in memory.
func (*MemoryHandler) Logs ¶ added in v0.11.0
func (h *MemoryHandler) Logs() []string
Logs return a list of all the messages sent to the logger
func (*MemoryHandler) Pop ¶ added in v0.11.1
func (h *MemoryHandler) Pop() string
Pop returns the latest log from the internal storage (and removes it)
func (*MemoryHandler) PopWithLevel ¶ added in v0.14.0
func (h *MemoryHandler) PopWithLevel() (level LogLevel, prefix, message string)
PopWithLevel returns the latest log from the internal storage (and removes it)
func (*MemoryHandler) Reset ¶ added in v0.14.0
func (h *MemoryHandler) Reset()
Reset clears internally buffered log
func (*MemoryHandler) SetPrefix ¶ added in v0.5.0
func (h *MemoryHandler) SetPrefix(prefix string) Handler
SetPrefix adds a prefix to every log message. Please note no space is added between the prefix and the log message
func (*MemoryHandler) Size ¶ added in v0.14.0
func (h *MemoryHandler) Size() int64
Size return the estimated amount of memory used by this handler
func (*MemoryHandler) TransferTo ¶ added in v0.14.0
func (h *MemoryHandler) TransferTo(receiver Handler) bool
TransferTo transfers (and removes) all messages from the internal storage to another handler. Returns true as messages were transferred.
type MiddlewareHandler ¶ added in v0.7.0
MiddlewareHandler is a Handler that act as a middleware => you can get and set the next handler in the chain
type Prefixer ¶ added in v0.9.0
Prefixer is an optional interface on handler that supports prefixing a log message
type SafeHandler ¶
type SafeHandler struct {
// contains filtered or unexported fields
}
SafeHandler sends logs to an alternate destination when the primary destination fails
Example ¶
// a safe handler is a middleware with two targets (Handler): // - it will send all messages to the primary handler // - it will only send the messages again to the backup handler if the primary returned an error // let's create a safe handler with these two targets: a DiscardHandler and a TextHandler // the DiscardHandler is a special handler that always discards your log messages and returns an error logger := NewLogger(NewSafeHandler(NewDiscardHandler(), NewTextHandler("backup ", 0))) logger.Infof("hello %s", "world")
Output: backup hello world
func NewSafeHandler ¶
func NewSafeHandler(primary, backup Handler) *SafeHandler
NewSafeHandler creates a handler that redirects logs to a backup handler when the primary fails
func (*SafeHandler) LogEntry ¶
func (h *SafeHandler) LogEntry(logEntry LogEntry) error
LogEntry send messages to primaryHandler first, then to backupHandler if it had fail
func (*SafeHandler) SetPrefix ¶ added in v0.5.0
func (h *SafeHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type StandardLogHandler ¶
type StandardLogHandler struct {
// contains filtered or unexported fields
}
StandardLogHandler send messages to a io.Writer using the standard logger.
func NewStandardLogHandler ¶
func NewStandardLogHandler(output io.Writer, prefix string, flag int) *StandardLogHandler
NewStandardLogHandler creates a handler to send the logs to io.Writer through a standard logger.
func (*StandardLogHandler) Close ¶ added in v0.12.0
func (h *StandardLogHandler) Close() error
Close the output writer
func (*StandardLogHandler) LogEntry ¶
func (h *StandardLogHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level.
func (*StandardLogHandler) SetOutput ¶
func (h *StandardLogHandler) SetOutput(output io.Writer) *StandardLogHandler
SetOutput sets the output destination for the logger.
func (*StandardLogHandler) SetPrefix ¶ added in v0.5.0
func (h *StandardLogHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type StandardLogger ¶ added in v0.2.0
type StandardLogger struct {
// contains filtered or unexported fields
}
StandardLogger can be used when you need to plug-in a standard library logger (via an interface)
func NewStandardLogger ¶ added in v0.2.0
func NewStandardLogger(level LogLevel, handler Handler) *StandardLogger
NewStandardLogger creates a new logger that can be used in place of a standard library logger (via an interface)
func (*StandardLogger) Fatal ¶ added in v0.2.0
func (l *StandardLogger) Fatal(v ...interface{})
Fatal is equivalent to l.Print() followed by a call to os.Exit(1). You can change the exit function with RegisterExitFunc if needed.
func (*StandardLogger) Fatalf ¶ added in v0.2.0
func (l *StandardLogger) Fatalf(format string, v ...interface{})
Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1). You can change the exit function with RegisterExitFunc if needed.
func (*StandardLogger) Fatalln ¶ added in v0.2.0
func (l *StandardLogger) Fatalln(v ...interface{})
Fatalln is equivalent to l.Println() followed by a call to os.Exit(1). You can change the exit function with RegisterExitFunc if needed.
func (*StandardLogger) Panic ¶ added in v0.2.0
func (l *StandardLogger) Panic(v ...interface{})
Panic is equivalent to l.Print() followed by a call to panic().
func (*StandardLogger) Panicf ¶ added in v0.2.0
func (l *StandardLogger) Panicf(format string, v ...interface{})
Panicf is equivalent to l.Printf() followed by a call to panic().
func (*StandardLogger) Panicln ¶ added in v0.2.0
func (l *StandardLogger) Panicln(v ...interface{})
Panicln is equivalent to l.Println() followed by a call to panic().
func (*StandardLogger) Print ¶ added in v0.2.0
func (l *StandardLogger) Print(v ...interface{})
Print writes the output for a logging event. Arguments are handled in the manner of fmt.Print. A newline is appended if the last character of s is not already a newline.
func (*StandardLogger) Printf ¶ added in v0.2.0
func (l *StandardLogger) Printf(format string, v ...interface{})
Printf writes the output for a logging event. Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of s is not already a newline.
func (*StandardLogger) Println ¶ added in v0.2.0
func (l *StandardLogger) Println(v ...interface{})
Println writes the output for a logging event. Arguments are handled in the manner of fmt.Println.
func (*StandardLogger) RegisterExitFunc ¶ added in v0.7.0
func (l *StandardLogger) RegisterExitFunc(exitFunc func()) *StandardLogger
RegisterExitFunc allows using a different "exit" function when calling Fatal, Fatalln or Fatalf. If not specified, os.Exit(1) is used
type TeeHandler ¶ added in v0.10.0
type TeeHandler struct {
// contains filtered or unexported fields
}
TeeHandler sends logs to two handlers at the same time
Example ¶
// a tee handler is a middleware with two targets (Handler) which // will send all messages to both handlers as targets // let's create a tee handler with two TextHandler targets logger := NewLogger(NewTeeHandler( NewTextHandler("logger 1 - ", 0), NewTextHandler("logger 2 - ", 0), )) logger.Infof("hello %s", "world")
Output: logger 1 - hello world logger 2 - hello world
func NewTeeHandler ¶ added in v0.10.0
func NewTeeHandler(a, b Handler) *TeeHandler
NewTeeHandler creates a handler that redirects logs to 2 handlers at the same time
func (*TeeHandler) LogEntry ¶ added in v0.10.0
func (h *TeeHandler) LogEntry(logEntry LogEntry) error
LogEntry send messages to both handlers
func (*TeeHandler) SetPrefix ¶ added in v0.10.0
func (h *TeeHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type TestHandler ¶
type TestHandler struct {
// contains filtered or unexported fields
}
TestHandler redirects all the logs to the testing framework logger
func NewTestHandler ¶
func NewTestHandler(t TestLogInterface) *TestHandler
NewTestHandler instantiates a new logger redirecting to the test framework logger or any other implementation of TestLogInterface for that matter
func (*TestHandler) LogEntry ¶
func (h *TestHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level
type TestLogInterface ¶
type TestLogInterface interface { Log(args ...interface{}) Logf(format string, args ...interface{}) }
TestLogInterface for use with testing.B or testing.T
type TextHandler ¶ added in v0.5.0
type TextHandler struct {
// contains filtered or unexported fields
}
TextHandler logs messages directly to the console
Example ¶
logger := NewLogger(NewTextHandler("example ", 0)) logger.Info("hello world")
Output: example hello world
func NewTextHandler ¶ added in v0.5.0
func NewTextHandler(prefix string, flag int) *TextHandler
NewTextHandler creates a new handler to send logs to the console
func (*TextHandler) LogEntry ¶ added in v0.5.0
func (h *TextHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level
func (*TextHandler) SetPrefix ¶ added in v0.5.0
func (h *TextHandler) SetPrefix(prefix string) Handler
SetPrefix sets a prefix on every log message
type Writer ¶ added in v0.3.0
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.Writer that writes into a Handler. This can be used to redirect a log.Logger into a handler.
Example ¶
// a writer can be used to redirect logs coming from a standard logger writer := NewWriter(LevelError, NewTextHandler("", 0)) // create a http server with a standard log.Logger redirecting to our writer server := &http.Server{ ErrorLog: log.New(writer, "http", 0), } server.Close()
Output:
Source Files
¶
- async_handler.go
- console_handler.go
- discard_handler.go
- entry.go
- errors.go
- file_handler.go
- filter_chain_handler.go
- filter_handler.go
- handler.go
- level.go
- log.go
- logger.go
- memory_handler.go
- middleware_handler.go
- overflow_handler.go
- safe_handler.go
- standard_output.go
- standardlog.go
- stdlog_handler.go
- sync_writer.go
- tee_handler.go
- test_handler.go
- text_handler.go
- writer.go