Documentation ¶
Overview ¶
This package performs basic setup of the logrus library with custom formatting.
Overview ¶
Zylog logger's primary features include:
- Exceedingly simple setup
- Colored output (enabled/disabled with a boolean)
- Logging level (lower-case string)
- Output (only stdout and stderr currently supported)
- ReportCaller (enabled/disabled with a boolean; prints package, function and line number)
- Custom format (similar to the Clojure twig library and the LFE logjam libraries)
Setup is done with the zylog logger, after which logrus may be used as designed by its author.
Installation
$ go get github.com/geomyidia/zylog/logger
Additionally, there is a demo you may install and run:
$ go get github.com/geomyidia/zylog/cmd/zylog-demo
Configuration ¶
To configure the logger, simply pass an options struct reference to SetupLogging. For example,
package main
import ( logger "github.com/geomyidia/zylog/logger" log "github.com/sirupsen/logrus" ) func main () { log.SetupLogging(&log.ZyLogOptions{ Colored: true, Level: "info", Output: "stdout", ReportCaller: false, }) // More app code log.Info("App started up!") }
Index ¶
Constants ¶
const ( LogLevelError string = "Could not set configured log level" LogOutputError string = "Unsupported log output: %s" NotImplementedError string = "Not yet implemented: %s" )
Variables ¶
var ( // Version is populated at compile from ./VERSION. Version string // GitCommit is populated at compile time. GitCommit string // GitSummary is populated at compile time. GitSummary string // GitBranch is current branch name the code is built off. GitBranch string // BuildDate is RFC3339 formatted UTC date. BuildDate string )
Functions ¶
func BuildString ¶
func BuildString() string
BuildString returns a build string that provides the git branch upon which the build was made, the git commit of that branch, as well as the build date. If a build string cannot be constructed, the string 'NA' is returned.
func ColorLevel ¶
Determine the color of the log level based upon the string value of the log level.
func VersionString ¶
func VersionString() string
VersionString returns a version string as set by the Makefile when the library was last compiled. If a version cannot be extracted, the string 'NA' is returned.
Types ¶
type TextFormatter ¶
type TextFormatter struct { // Force disabling colors. DisableColors bool }
TextFormatter formats logs into text.
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(entry *log.Entry) ([]byte, error)
Provides the custom formatting of the zylog logger.
In particular, logs output in the following form:
YYYY-mm-DDTHH:MM:SS-TZ:00 LEVEL ▶ logged message ...
If the ReportCaller option is set to true, the log output will have the following form:
YYYY-mm-DDTHH:MM:SS-TZ:00 LEVEL [pkghost/auth/proj/file.Func:LINENUM] ▶ logged message ...
Any structured data passed as logrus fields will be appended to the above line forms.