Categorygithub.com/creativeprojects/clog
modulepackage
0.14.0
Repository: https://github.com/creativeprojects/clog.git
Documentation: pkg.go.dev

# 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

# Packages

No description provided by the author

# Functions

CloseTestLog at the end of the test otherwise the logger will keep a reference on t.
Debug sends debugging information.
Debugf sends debugging information.
Error sends error information to the console.
Errorf sends error information to the console.
GetDefaultLogger returns the logger used when using the package methods.
Info logs some noticeable information.
Infof logs some noticeable information.
Log sends a log entry with the specified level.
Logf sends a log entry with the specified level.
NewAsyncHandler returns a handler that sends logs asynchronously.
NewAsyncHandlerWithCapacity returns a handler that sends logs asynchronously.
NewConsoleHandler creates a new handler to send logs to the console.
NewConsoleLogger is a shortcut to create a Logger with a ConsoleHandler.
NewDiscardHandler returns a handler that forgets all the logs you throw at it.
NewFileHandler creates a new file logger Remember to Close() the logger at the end.
NewFilteredConsoleLogger is a shortcut to create a Logger with a FilteredHandler sending to a ConsoleHandler.
NewLevelFilter creates a new LevelFilter handler passing log entries to destination if level >= minimum level.
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.
NewLogEntry creates a new LogEntry composed of values.
NewLogEntryf creates a new formatted LogEntry with values.
NewLogger creates a new logger.
NewMemoryHandler creates a new MemoryHandler that keeps logs in memory.
NewSafeHandler creates a handler that redirects logs to a backup handler when the primary fails.
NewStandardLogger creates a new logger that can be used in place of a standard library logger (via an interface).
NewStandardLogHandler creates a handler to send the logs to io.Writer through a standard logger.
NewSyncWriter creates a thread-safe io.Writer.
NewTeeHandler creates a handler that redirects logs to 2 handlers at the same time.
NewTestHandler instantiates a new logger redirecting to the test framework logger or any other implementation of TestLogInterface for that matter.
NewTextHandler creates a new handler to send logs to the console.
NewWriter creates a new Writer to a Handler.
SetDefaultLogger sets the logger used when using the package methods.
SetPrefix sets the output prefix for the standard logger.
SetTestLog install a test logger as the default logger.
Stderr returns a thread-safe io.Writer to os.Stderr.
Stdout returns a thread-safe io.Writer to os.Stdout.
Trace sends trace information for heavy debugging.
Tracef sends trace information for heavy debugging.
Warning send some important message to the console.
Warningf send some important message to the console.

# Constants

LogLevel.
LogLevel.
LogLevel.
LogLevel.
LogLevel.

# Variables

All errors that can be returned by the clog package.
All errors that can be returned by the clog package.
All errors that can be returned by the clog package.
All errors that can be returned by the clog package.
All errors that can be returned by the clog package.

# Structs

AsyncHandler asynchronously send log messages to the next handler in the chain.
ConsoleHandler logs messages to the console (in colour).
DiscardHandler forgets any log message.
FileHandler logs messages to a file.
LevelFilter is a log middleware that is only passing log entries of level >= minimum level.
LevelFilterChain is a log middleware that is only passing log entries of level >= minimum level.
LogEntry represents a log entry.
Logger frontend.
MemoryHandler save messages in memory (useful for unit testing).
SafeHandler sends logs to an alternate destination when the primary destination fails.
StandardLogger can be used when you need to plug-in a standard library logger (via an interface).
StandardLogHandler send messages to a io.Writer using the standard logger.
TeeHandler sends logs to two handlers at the same time.
TestHandler redirects all the logs to the testing framework logger.
TextHandler logs messages directly to the console.
Writer is an io.Writer that writes into a Handler.

# Interfaces

Closer is an optional interface on handler that supports closing its output.
Handler for a logger.
MiddlewareHandler is a Handler that act as a middleware => you can get and set the next handler in the chain.
Prefixer is an optional interface on handler that supports prefixing a log message.
TestLogInterface for use with testing.B or testing.T.

# Type aliases

LogLevel represents the importance of a log entry.