
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
github.com/xuperchain/log15
This depository is a fork of log15. Add time-based log rotation and some other improvements.
For the original log15 depository, please click the link.
Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's io
and net/http
packages and is an alternative to the standard library's log
package.
The API of the master branch of log15 should always be considered unstable. If you want to rely on a stable API, you must vendor the library.
import "github.com/xuperchain/log15"
// List of predefined log Levels
const (
LvlCrit Lvl = iota
LvlError
LvlWarn
LvlInfo
LvlTrace
LvlDebug
)
// all loggers can have key/value context
srvlog := log.New("module", "app/server")
// all log messages can have key/value context
srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
// child loggers with inherited context
connlog := srvlog.New("raddr", c.RemoteAddr())
connlog.Info("connection open")
// lazy evaluation
connlog.Debug("ping remote", "latency", log.Lazy{pingRemote})
// flexible configuration
srvlog.SetHandler(log.MultiHandler(
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler("errors.json", log.JsonFormat()))))
Will result in output that looks like this:
WARN[06-17|21:58:10] abnormal conn rate module=app/server rate=0.500 low=0.100 high=0.800
INFO[06-17|21:58:10] connection open module=app/server raddr=10.0.0.1
Using RotateFileHandler to create time-based rotation strategy.
l := New()
fmtr := LogfmtFormat()
// rotate every 1 minutes and keep 2 backup log files
l.SetHandler(MultiHandler(
BoundLvlFilterHandler(
LvlDebug,
LvlInfo,
Must.RotateFileHandler("./log/test.log", fmtr, 1, 2)),
LvlFilterHandler(
LvlWarn,
Must.RotateFileHandler("./log/test.log.wf", fmtr, 1, 2))))
times := 150
for i := 0; i < times; i++ {
l.Info("this is a info", "index", i)
l.Warn("this is a warn", "index", i)
time.Sleep(time.Second * 1)
}
The log file look like:
-rw-r--r-- 1 work work 990 Dec 18 13:48 test.log
-rw-r--r-- 1 work work 0 Dec 18 13:48 test.log.201812181347
-rw-r--r-- 1 work work 990 Dec 18 13:48 test.log.wf
-rw-r--r-- 1 work work 0 Dec 18 13:48 test.log.wf.201812181347
The following commits broke API stability. This reference is intended to help you understand the consequences of updating to a newer version of log15.
Get()
method to the Logger
interface to retrieve the current handlerRecord
field Call
changed to stack.Call
with switch to github.com/go-stack/stack
syslog.Priority
argument to the SyslogXxx
handler constructorsYes. Use log.Ctx
:
srvlog := log.New(log.Ctx{"module": "app/server"})
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
go get -u github.com/kevinburke/write_mailmap
write_mailmap > CONTRIBUTORS
Apache
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.