ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - jfcg/yell: :ledger: Yet another minimalist logging library
:ledger: Yet another minimalist logging library. Contribute to jfcg/yell development by creating an account on GitHub.
Visit Site

GitHub - jfcg/yell: :ledger: Yet another minimalist logging library

GitHub - jfcg/yell: :ledger: Yet another minimalist logging library

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:

  • BTC:bc1qr8m7n0w3xes6ckmau02s47a23e84umujej822e
  • ETH:0x3a844321042D8f7c5BB2f7AB17e20273CA6277f6

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory