ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - heartwilltell/log: Simple leveled logging wrapper around standard log package
Simple leveled logging wrapper around standard log package - heartwilltell/log
Visit Site

GitHub - heartwilltell/log: Simple leveled logging wrapper around standard log package

GitHub - heartwilltell/log: Simple leveled logging wrapper around standard log package

log - Simple leveled logging based on standard log package

Documentation

Build codecov

Benefits

  • ๐Ÿ˜ป Leveled logging
  • ๐Ÿ˜š Simple API
  • ๐Ÿค fmt friendly
  • ๐Ÿ‘Œ Zero dependencies
  • ๐Ÿ˜ฎโ€๐Ÿ’จ No global logger
  • ๐Ÿ‘ No structured logging bullshit

Installation

go get github.com/heartwilltell/log

Leveled logging

The StdLog implements a simple interface:

// Logger formats the message according to standard format specifiers from the fmt package
// and writes the message to writer specified by the concrete interface implementation.
type Logger interface {
	// Error formats and writes the error level message.
	Error(format string, v ...any)
	// Warning formats and writes the warning level message.
	Warning(format string, v ...any)
	// Info formats and writes the information level message.
	Info(format string, v ...any)
	// Debug formats and writes the debug level message.
	Debug(format string, v ...any)
}

Usage

๐Ÿ‘‡ The usage is pretty simple. Just create a logger instance and call any of leveled methods.

logger := log.New()
logger.Info("Listen on port: %d", 8080)

๐Ÿ‘‡ Sets the logging level to debug level.

logger := log.New(log.WithLevel(log.DBG))

๐Ÿ‘‡ Parses string to level and creates logger with warning level.

level, levelErr := log.ParseLevel("warning")
if levelErr != nil {
	// handle error here
}

logger := log.New(log.WithLevel(level))

๐Ÿ‘‡ Creates logger with different io.Writer.

var w bytes.Buffer 

logger := log.New(log.WithWriter(w))

๐Ÿ‘‡ Disables the colorful output.

logger := log.New(log.WithNoColor())

๐Ÿ‘‡ Sets the UTC time format.

logger := log.New(log.WithUTC())

๐Ÿ‘‡ Enables printing the code line number.

// Short format:
// INF: 2022/07/08 11:22:30 server.go:111: message
logger := log.New(log.WithLineNum(log.ShortFmt))

OR

// Long format:
// INF: 2022/07/08 11:22:30 /Users/heartwilltell/Go/app/server.go:111: message
logger := log.New(log.WithLineNum(log.LongFmt))

๐Ÿ‘‡ Sets the level mark at the end of log prefix.

logger := log.New(log.WithLevelAtPrefixEnd())

Will produce this ๐Ÿ‘‡

// 2022/07/08 11:22:30 INF: message

Instead of this ๐Ÿ‘‡

// INF: 2022/07/08 11:22:30: message

๐Ÿ‘‡ Creates nop logger which implements log.Logger interface.

logger := log.NewNopLog()

๐Ÿ’ก Useful for tests or places where logger should be disabled by default

License

MIT License.

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