Categorygithub.com/kdar/factorlog
modulepackage
0.0.0-20211012144011-6ea75a169038
Repository: https://github.com/kdar/factorlog.git
Documentation: pkg.go.dev

# README

FactorLog

FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily be a replacement for Go's log in the standard library (though it doesn't support functions such as SetFlags()).

It has a modular formatter interface, and even have a GELF and glog formatter in the contrib.

Documentation here: http://godoc.org/github.com/kdar/factorlog

factorlog

Features

  • Various log severities: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, STACK, FATAL, PANIC
  • Configurable, formattable logger. Check factorlog-contrib for examples.
  • Modular formatter. Care about speed? Use GlogFormatter or roll your own.
  • Designed with speed in mind (it's really fast).
  • Many logging functions to fit your style of logging. (Trace, Tracef, Traceln, etc...)
  • Supports colors.
  • Settable verbosity like glog.
  • Filter by severity.
  • Used in a production system, so it will get some love.

Motivation

There are many good logging libraries out there but none of them worked the way I wanted them to. For example, some libraries have an API like log.Info(), but behind the scenes it's using fmt.Sprintf. What this means is I couldn't do things like log.Info(err). I would instead have to do log.Info("%s", err.Error()). This kept biting me as I was coding. In FactorLog, log.Info behaves exactly like fmt.Sprint. log.Infof uses fmt.Sprintf and log.Infoln uses fmt.Sprintln.

I really like glog, but I don't like that it takes over your command line arguments. I may implement more of its features into FactorLog.

I also didn't want a library that read options from a configuration file. You could easily handle that yourself if you wanted to. FactorLog doesn't include any code for logging to different backends (files, syslog, etc...). The reason for this is I was structuring this after http://12factor.net/. There are many programs out there that can parse your log output from stdout/stderr and redirect it to the appropriate place. However, FactorLog doesn't prevent you from writing this code yourself. I think it would be better if there was a third party library that did backend work itself. Then every logging library could benefit from it.

Examples

You can use the API provided by the package itself just like Go's log does:

package main

import (
  log "github.com/kdar/factorlog"
)

func main() {
  log.Println("Hello there!")
}

Or, you can make your own log from FactorLog:

package main

import (
  "github.com/kdar/factorlog"
  "os"
)

func main() {
  log := factorlog.New(os.Stdout, factorlog.NewStdFormatter("%{Date} %{Time} %{File}:%{Line} %{Message}"))
  log.Println("Hello there!")
}

Check the examples/ directory for more.

Documentation

http://godoc.org/github.com/kdar/factorlog

API Stability

I'm using this in software that is rapidly changing, so I haven't stabilized the API of this just yet.

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
I64toa is the same as itoa but for 64bit integers.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
itoa converts an integer d to its ascii representation i is the deintation index in buf algorithm from https://www.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920.
No description provided by the author
nDigits converts an integer d to its ascii representation n is how many digits to use i is the destination index in buf.
New creates a FactorLog with the given output and format.
Available verbs: %{SEVERITY} - TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, STACK, FATAL, PANIC %{Severity} - Trace, Debug, Info, Warn, Error, Critical, Stack, Fatal, Panic %{severity} - trace, debug, info, warn, error, critical, stack, fatal, panic %{SEV} - TRAC, DEBG, INFO, WARN, EROR, CRIT, STAK, FATL, PANC %{Sev} - Trac, Debg, Info, Warn, Eror, Crit, Stak, Fatl, Panc %{sev} - trac, debg, info, warn, eror, crit, stak, fatl, panc %{S} - T, D, I, W, E, C, S, F, P %{s} - t, d, i, w, e, c, s, f, p %{Date} - Shorthand for 2006-01-02 %{Time} - Shorthand for 15:04:05 %{Time "<fmt>"} - Specify a format (read time.Format for details).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SetFormatter sets the formatter for the standard logger.
No description provided by the author
SetOutput sets the output destination for the standard logger.
No description provided by the author
No description provided by the author
We use this function to convert a severity to an index that we can then use to index variables like UcSeverityStrings.
No description provided by the author
No description provided by the author
No description provided by the author
Convert an uppercase string to a severity.
No description provided by the author
No description provided by the author
No description provided by the author
twoDigits converts an integer d to its ascii representation i is the destination index in buf.
Ui64toa is the same as itoa but for 64bit unsigned integers.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

FactorLog is a logging object that outputs data to an io.Writer.
Structure used to hold the data used for formatting.
Creates a logger that outputs to nothing.
No description provided by the author
Verbose is a structure that enables syntatic sugar when testing for verbosity and calling a log function.

# Interfaces

Interface to format anything.
No description provided by the author

# Type aliases

Level represents the level of verbosity.
Severity represents the severity of the log.