clog

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 9 Imported by: 27

README

Godoc reference Build Go Report Card codecov

clog (console-log)

All the fashionable loggers for Go tend to focus on structured logging, and that's perfectly fine: until you simply need a logger for a console application...

So here's yet another logger for Go:

  • unstructured logging
  • console logging in colour
  • file logging
  • simple to use
  • filter your logs from 5 levels of severity (Trace, Debug, Info, Warn, Error)
  • redirect your logs to an io.Writer
  • get logs coming from an io.Writer
  • using the logger from the standard library under the hood
  • extensible (via handlers and middleware)
  • unit test coverage of more than 90%
  • drop-in replacement for the standard library logger

Have a look at the examples if you like the look of it

Here's a very simple one:

package main

import (
	"fmt"
	"github.com/creativeprojects/clog"
)

func main() {
	log := clog.NewFilteredConsoleLogger(clog.LevelInfo)

	log.Info("will be displayed")
	log.Debug("will be discarded")
	log.Trace("will be discarded")
	log.Trace(func() string { return "will not be called" })

	log.Info(fmt.Sprintf, "generated and displayed(%d)", 1)
	log.Infof("generated and displayed(%d)", 2)
}

example

Documentation available on GoDoc

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
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 Debug

func Debug(v ...interface{})

Debug sends debugging information

func Debugf

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

Debugf sends debugging information

func Error

func Error(v ...interface{})

Error sends error information to the console

func Errorf

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

Errorf sends error information to the console

func Info

func Info(v ...interface{})

Info logs some noticeable information

func Infof

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

Infof logs some noticeable information

func Log

func Log(level LogLevel, v ...interface{})

Log sends a log entry with the specified level

func Logf

func Logf(level LogLevel, format string, v ...interface{})

Logf sends a log entry with the specified level

func NewSyncWriter added in v0.10.0

func NewSyncWriter(writer io.Writer) io.Writer

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

func Stderr() io.Writer

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

func Stdout() io.Writer

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

func Tracef added in v0.6.0

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

Tracef sends trace information for heavy debugging

func Warning

func Warning(v ...interface{})

Warning send some important message to the console

func Warningf

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

Warningf send some important message to the console

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

type Handler interface {
	LogEntry(LogEntry) error
}

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

func NewLogEntry(callDepth int, level LogLevel, values ...interface{}) LogEntry

NewLogEntry creates a new LogEntry composed of values.

values parameter is comparable to fmt.Sprint(values...)

func NewLogEntryf added in v0.5.0

func NewLogEntryf(callDepth int, level LogLevel, format string, values ...interface{}) LogEntry

NewLogEntryf creates a new formatted LogEntry with values.

parameters are comparable to fmt.Sprintf(format, values...)

func (LogEntry) GetMessage

func (l LogEntry) GetMessage() string

GetMessage returns the formatted message from Format & Values

func (LogEntry) GetMessageWithLevelPrefix

func (l LogEntry) GetMessageWithLevelPrefix() string

GetMessageWithLevelPrefix returns the formatted message from Format & Values prefixed with the level name

type LogLevel

type LogLevel int

LogLevel represents the importance of a log entry

const (
	LevelTrace LogLevel = iota
	LevelDebug
	LevelInfo
	LevelWarning
	LevelError
)

LogLevel

func (LogLevel) String

func (level LogLevel) String() string

String representation of a level (5 characters)

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

func NewFilteredConsoleLogger(minLevel LogLevel) *Logger

NewFilteredConsoleLogger is a shortcut to create a Logger with a FilteredHandler sending to a ConsoleHandler

func NewLogger

func NewLogger(handler Handler) *Logger

NewLogger creates a new logger

func SetPrefix added in v0.5.0

func SetPrefix(prefix string) *Logger

SetPrefix sets the output prefix for the standard logger

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug sends debugging information

func (*Logger) Debugf

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

Debugf sends debugging information

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error sends error information to the console

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf sends error information to the console

func (*Logger) GetHandler

func (l *Logger) GetHandler() Handler

GetHandler returns the current handler used by the logger

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info logs some noticeable information

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof logs some noticeable information

func (*Logger) Log

func (l *Logger) Log(level LogLevel, v ...interface{})

Log sends a log entry with the specified level

func (*Logger) LogEntry

func (l *Logger) LogEntry(logEntry LogEntry) error

LogEntry sends a LogEntry directly. Logger can also be used as a Handler

func (*Logger) Logf

func (l *Logger) Logf(level LogLevel, format string, v ...interface{})

Logf sends a log entry with the specified level

func (*Logger) SetHandler

func (l *Logger) SetHandler(handler Handler)

SetHandler sets a new handler for the logger

func (*Logger) SetPrefix added in v0.5.0

func (l *Logger) SetPrefix(prefix string) Handler

SetPrefix sets the output prefix for the standard logger

func (*Logger) Trace added in v0.6.0

func (l *Logger) Trace(v ...interface{})

Trace sends trace information for heavy debugging

func (*Logger) Tracef added in v0.6.0

func (l *Logger) Tracef(format string, v ...interface{})

Tracef sends trace information for heavy debugging

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

Warning send some important message to the console

func (*Logger) Warningf

func (l *Logger) Warningf(format string, v ...interface{})

Warningf send some important message to the console

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

type MiddlewareHandler interface {
	GetHandler() Handler
	SetHandler(handler Handler)
}

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

type Prefixer interface {
	SetPrefix(string) Handler
}

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:

func NewWriter added in v0.3.0

func NewWriter(level LogLevel, handler Handler) *Writer

NewWriter creates a new Writer to a Handler

func (*Writer) Write added in v0.3.0

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

Write bytes into the logger

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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