Circular logging for Golang

Overview

Chainsaw

Circular buffer logging framework for Go.

This logging library will keep the last N log messages around. This allows you to dump the logs at trace or debug level if you encounter an error, contextualizing the error.

It also allows you to start a stream of log messages, making it suitable for applications which have sub-applications where you might wanna look at different streams of logs. Say in an application which has a bunch of goroutines which have more or less independent log.

Example usage

package main

import (
	"context"
	"fmt"
	log "github.com/celerway/chainsaw"
	"os"
	"time"
)

func main() {
	log.Info("Application starting up")
	log.Trace("This is a trace message. Doesn't get printed directly")
	logMessages := log.GetMessages(log.TraceLevel)
	for i, mess := range logMessages {
		fmt.Println("Fetched message: ", i, ":", mess.Content)
	}
	log.RemoveWriter(os.Stdout) // stop writing to stdout
	time.Sleep(10 * time.Millisecond)
	log.Info("Doesn't show up on screen.")
	ctx, cancel := context.WithCancel(context.Background())
	stream := log.GetStream(ctx)
	go func() {
		for mess := range stream {
			fmt.Println("From stream: ", mess.Content)
		}
		fmt.Println("Log stream is closed")
	}()
	log.Info("Should reach the stream above")
	cancel()
	time.Sleep(time.Second)
}

Caveats: things to be aware of

The API is async. Control messages are sent internally, and it might take a few ms before they are handled. This is why where is a bit of sleep in the example above. The control messages could be made sync at the cost of some performance.

Also, if you request a log stream you have to service the channel. If you don't the application will lock up.

log.go is generated by gen/main.go

chainsaw is pretty slow. Channels in Go aren't really that fast and if you're logging thousands of messages per second you might wanna do something else.

Todo:

  • Increase compatibility with other logging libraries.
  • Consider making the control messages synchronous.
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 18 Dec 20, 2021
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 25 Jun 11, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

FactorLog FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily b

Kevin Darlington 54 Oct 12, 2021
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Luke Zhang 0 Nov 10, 2021
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 161 Jul 2, 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 14 Aug 26, 2021
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

null 91 Apr 21, 2022
Utilities for slightly better logging in Go (Golang).

logutils logutils is a Go package that augments the standard library "log" package to make logging a bit more modern, without fragmenting the Go ecosy

HashiCorp 324 Jun 14, 2022
A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages 简体中文 Русский Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Ozzo Framework 118 Jan 11, 2022
Golang logging library

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Örjan Fors 1.8k Jun 23, 2022
Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Gyoza Tech 37 Apr 19, 2022
Cloud logging library in golang

?? logg Open Source Cloud logging library in Go. About the project Connect your golang microservices logs with this engine! Send your logs to kafka, r

yuri 3 Nov 8, 2021
Go-logging-logrus - Learn how to log management in golang with logrus

Learn how to logging in golang with logrus How to run this project git clone htt

Vandy Ahmad 0 Jan 19, 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 26 Mar 10, 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 12 May 23, 2022
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

Sadlil Rhythom 41 Jun 22, 2022
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

Grigory Zubankov 31 Jul 5, 2022
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

Apex 1.2k Jun 28, 2022
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

Go Playgound 280 Jun 22, 2022