Thanks to visit codestin.com
Credit goes to pkg.go.dev

log

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 4 Imported by: 4

README

log

Godoc Report Tests Coverage Sponsor

An O(1) constant time logging system that allows you to connect one log to multiple writers (e.g. stdout, a file and a TCP connection).

Installation

go get -u github.com/aerogo/log/...

Example

hello := log.New()                          // Create a new log
hello.AddWriter(log.File("hello.log"))      // Add a writer

hello.Info("Hello World %d %d %d", 1, 2, 3) // Write non-critical data (buffered)
hello.Error("Something went wrong")         // Force an immediate I/O flush for error messages

Under the hood

All Write calls are queued into a channel that is read in a separate goroutine. Once the channel receives new data it writes the data to all registered outputs.

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(path string) *os.File

File provides a simple interface to create a log file. The given file path must be writable, otherwise it will panic.

Types

type Log

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

Log is a log data source used for a specific part of your application, e.g. "web", "database", "api" or other categories. It can be connected to multiple writers.

func New

func New() *Log

New creates a new Log.

func (*Log) AddWriter added in v0.2.0

func (log *Log) AddWriter(writer io.Writer)

AddWriter adds an output to the log.

func (*Log) Error

func (log *Log) Error(format string, values ...interface{})

Error writes critical information to the log. It will instantly flush the I/O buffers and guarantees that the message will have been written persistenly to disk at the time this function returns.

func (*Log) Info

func (log *Log) Info(format string, values ...interface{})

Info writes non-critical information to the log. Unlike Error, it does not guarantee that the message will have been written persistenly to disk at the time this function returns.

func (*Log) Write

func (log *Log) Write(b []byte) (n int, err error)

Write implements the io.Writer interface. As long as buffer capacity is available, this call will not block and have O(1) behaviour, regardless of how many writers are used.

Jump to

Keyboard shortcuts

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