Yet another minimalist logging library

Overview

yell Go Report Card go.dev ref

yell is yet another minimalist logging library. It comes with:

  • four severity levels (info, warn, error, fatal)
  • simple API
  • io.Writer & sync.Locker support
  • package-specific loggers
  • customizations (severity names, time format, local or UTC time)
  • easy, granular request location (file.go:line) logging
  • semantic versioning

Example

mypkg.go:

package mypkg

import (
	"os"
	"github.com/jfcg/yell"
)

// log to stdout with warn or higher severity (for example).
var Logger = yell.New(": mypkg:", os.Stdout, yell.Swarn)

// Info tries to log message list with info severity
func Info(msg ...interface{}) error {
	return Logger.Log(yell.Sinfo, msg...)
}

// Warn tries to log message list with warn severity
func Warn(msg ...interface{}) error {
	return Logger.Log(yell.Swarn, msg...)
}

// Error tries to log message list with error severity
func Error(msg ...interface{}) (err error) {
	err = Logger.Log(yell.Serror, msg...)
	// extra stuff for error severity
	return
}

// Fatal tries to log message list with fatal severity and panics
func Fatal(msg ...interface{}) (err error) {
	err = Logger.Log(yell.Sfatal, msg...)
	pm := Logger.Name() + yell.Sname[yell.Sfatal]
	if err != nil {
		pm += err.Error()
	}
	// probably panic or os.Exit(1) in a fatal situation
	panic(pm)
}

myApp.go:

package main

import (
	"fmt"
	"mypkg"
	"github.com/jfcg/yell"
)

func log() {
	defer func() {
		fmt.Println("recovering:", recover())
	}()

	// uses mypkg.Logger. yell records calling line in file.go:line format
	mypkg.Info("some info:", 1, "more")

	// uses yell.Default Logger, minimum severity is warning by default
	yell.Warn("some warning:", "few details")

	// record log() caller instead of this line
	mypkg.Error(yell.Caller(1), "bad error", 3.5, "data")

	// Fatal() logs & panicks
	yell.Fatal("fatal mistake", 2, "hard to recover")
}

func main() {
	// minimum severity for mypkg.Logger is warning, so ignored
	mypkg.Info("some info:", 3, "more")

	// set min severity level to info
	mypkg.Logger.SetLevel(yell.Sinfo)
	log()

	// yell library uses local time by default, to get coordinated universal time
	yell.UTC = true
	log()

	// change time format
	yell.TimeFormat = yell.TimeFormat[:19]
	log()

	// customized severity names (increasing severity)
	yell.Sname = [...]string{"信息:", "警告:", "错误:", "致命的:"}
	yell.UTC = false
	log()

	// disable logging for yell.Default
	yell.Default.SetLevel(yell.Snolog)
	log()
}

output:

2021-03-28 21:48:53.591948: mypkg:info: myApp.go:15: some info: 1 more
2021-03-28 21:48:53.592051: myApp:warn: myApp.go:18: some warning: few details
2021-03-28 21:48:53.592063: mypkg:error: myApp.go:33: bad error 3.5 data
2021-03-28 21:48:53.592082: myApp:fatal: myApp.go:24: fatal mistake 2 hard to recover
recovering: myApp:fatal:
2021-03-28 18:48:53.592100: mypkg:info: myApp.go:15: some info: 1 more
2021-03-28 18:48:53.592110: myApp:warn: myApp.go:18: some warning: few details
2021-03-28 18:48:53.592118: mypkg:error: myApp.go:37: bad error 3.5 data
2021-03-28 18:48:53.592126: myApp:fatal: myApp.go:24: fatal mistake 2 hard to recover
recovering: myApp:fatal:
2021-03-28 18:48:53: mypkg:info: myApp.go:15: some info: 1 more
2021-03-28 18:48:53: myApp:warn: myApp.go:18: some warning: few details
2021-03-28 18:48:53: mypkg:error: myApp.go:41: bad error 3.5 data
2021-03-28 18:48:53: myApp:fatal: myApp.go:24: fatal mistake 2 hard to recover
recovering: myApp:fatal:
2021-03-28 21:48:53: mypkg:信息: myApp.go:15: some info: 1 more
2021-03-28 21:48:53: myApp:警告: myApp.go:18: some warning: few details
2021-03-28 21:48:53: mypkg:错误: myApp.go:46: bad error 3.5 data
2021-03-28 21:48:53: myApp:致命的: myApp.go:24: fatal mistake 2 hard to recover
recovering: myApp:致命的:
2021-03-28 21:48:53: mypkg:信息: myApp.go:15: some info: 1 more
2021-03-28 21:48:53: mypkg:错误: myApp.go:50: bad error 3.5 data
recovering: myApp:致命的:

Support

If you use yell and like it, please support via ETH:0x464B840ee70bBe7962b90bD727Aac172Fa8B9C15

Owner
Serhat Şevki Dinçer
test-driv'em
Serhat Şevki Dinçer
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 24 Nov 23, 2021
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 136 Jan 3, 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
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 39 Jan 19, 2021
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

Azer Koçulu 148 Nov 30, 2021
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 Jan 12, 2022
A pure Go contextual logging library with "batteries included"

Cue Overview Cue implements contextual logging with "batteries included". It has thorough test coverage and supports logging to stdout/stderr, file, s

Bob Ziuchkovski 26 Sep 16, 2019
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.7k Jan 5, 2022
Hierarchical, leveled, and structured logging library for Go

spacelog Please see http://godoc.org/github.com/spacemonkeygo/spacelog for info License Copyright (C) 2014 Space Monkey, Inc. Licensed under the Apach

Space Monkey Go 98 Apr 27, 2021
Minimal structured logging library for Go

slog slog is a minimal structured logging library for Go. Install go get cdr.dev/slog Features Minimal API First class context.Context support First c

Coder 233 Jan 10, 2022
GoVector is a vector clock logging library written in Go.

GoVector is a vector clock logging library written in Go. The vector clock algorithm is used to order events in distributed systems in the absence of a centralized clock. GoVector implements the vector clock algorithm and provides feature-rich logging and encoding infrastructure.

Distributed clocks 158 Dec 23, 2021
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 35 Dec 29, 2021
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
Logging library for Leadjet backend services

Logger Logging library for Leadjet backend services. Install go get -u github.com/Leadjet/logger Usage Initiate a Zap logger; err := zap.RegisterLog(

Leadjet 1 Oct 24, 2021
📝 🪵 A minimal level based logging library for Go

slogx A minimal level based logging library for Go. Installation Example Usage Logger Log Level Format Output Contribute License Installation go get g

私はレオンです 1 Dec 19, 2021
Simple Yet Powerful Logger

sypl sypl provides a Simple Yet Powerful Logger built on top of the Golang sypl. A sypl logger can have many Outputs, and each Output is responsible f

Sauce Labs 8 Nov 17, 2021
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 25 Nov 10, 2021