FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

Overview

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.

You might also like...
The Simplest and worst logging library ever written

gologger A Simple Easy to use go logger library. Displays Colored log into console in any unix or windows platform. You can even store your logs in fi

Go implementation of systemd Journal's native API for logging

journald Package journald offers Go implementation of systemd Journal's native API for logging. Key features are: based on a connection-less socket wo

Structured logging package for Go.
Structured logging package for Go.

Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on Medium. Handlers apexlog

Simple, configurable and scalable Structured Logging for Go.

log Log is a simple, highly configurable, Structured Logging library Why another logging library? There's allot of great stuff out there, but also tho

LogVoyage - logging SaaS written in GoLang
LogVoyage - logging SaaS written in GoLang

No longer maintained, sorry. Completely rewritten v2 is going to be released soon. Please follow http://github.com/logvoyage LogVoyage - fast and simp

Structured, composable logging for Go
Structured, composable logging for Go

log15 Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is mo

Minimalistic logging library for Go.
Minimalistic logging library for Go.

logger Minimalistic logging library for Go. Blog Post Features: Advanced output filters (package and/or level) Attributes Timers for measuring perform

Structured, pluggable logging for Go.
Structured, pluggable logging for Go.

Logrus Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. Logrus is in maintenance-mode. We wi

Logur is an opinionated collection of logging best practices
Logur is an opinionated collection of logging best practices

Logur is an opinionated collection of logging best practices. Table of Contents Preface Features Installation Usage FAQ Why not just X logger? Why not

Comments
  • %{File} and %{ShortFile} printing file system path with NewStdFormatter

    %{File} and %{ShortFile} printing file system path with NewStdFormatter

    I've recently started using this package and really like the custom formatting possibilities, however, I've run into a small bug. I'm using the following line to initialise my logger:

    var logger = factorlog.New(os.Stdout, factorlog.NewStdFormatter("[%{Date} %{Time}] {%{SEVERITY}:%{File}/%{Function}:%{Line}} %{SafeMessage}"))
    

    Ideally, the output would be something like "[1970-01-01 00:00:00] {DEBUG:main.go:main:50} Debugging", however, %{File} and %{ShortFile} always include the full file system path (e.g. "[1970-01-01 00:00:00] {DEBUG:C:\Users\MorpheusXAUT\Desktop\test\main.go:main:50} Debugging")

    %{ShortFile} does remove the ".go" extension from the filename, however, it still includes the file path.

    Am I overseeing some obvious mistake on my side (or have I misread the documentation), or does the current implementation always include the full path?

    opened by MorpheusXAUT 5
  • add %{Pid} std format string

    add %{Pid} std format string

    Pid was already initialized into the log context but never used. This PR adds a new simple format string %{Pid} to log the process id of the current process.

    opened by sni 0
  • Added verbosity methods to Logger interface, made NullLogger implement them

    Added verbosity methods to Logger interface, made NullLogger implement them

    Added log verbosity methods (V, SetVerbosity, and IsV) to factorlog.Logger interface

    Added those functions to factorlog.NullLogger

    This allows you to accept a Logger and pass it either a FactorLog or NullLogger object.

    opened by jmunson 0
Owner
Kevin Darlington
Kevin Darlington
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go

Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go.

Jacek Olszak 13 Nov 10, 2022
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Kristin Davidson 19 Sep 26, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Juan B. Rodriguez 28 Sep 28, 2022
Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log me

Seelog project repository 1.6k Nov 19, 2022
A hack example to servce file as a webserver with a Google Cloud Functions

Overview This project is a hack example to servce file as a webserver with a Google Cloud Functions (normally single purpose, only one entry point). I

guillaume blaquiere 0 Nov 26, 2021
A hello world project with NES.css and Netlify Functions

A hello world project powered by NES.css and Netlify Functions. The frontend part is a simple HTML page showing a progress bar. The input is received

Jang Rush 0 Jan 9, 2022
Logging, distilled

What is distillog? distillog aims to offer a minimalistic logging interface that also supports log levels. It takes the stdlib API and only slightly e

Akshay Moghe 30 Sep 26, 2022
Simple and blazing fast lockfree logging library for golang

glg is simple golang logging library Requirement Go 1.11 Installation go get github.com/kpango/glg Example package main import ( "net/http" "time"

Yusuke Kato 174 Nov 23, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Lajos Bencz 15 Sep 26, 2022
Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Guoqiang Chen 13 Sep 26, 2022