ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - azer/logger: Minimalistic logging library for Go.
Minimalistic logging library for Go. Contribute to azer/logger development by creating an account on GitHub.
Visit Site

GitHub - azer/logger: Minimalistic logging library for Go.

GitHub - azer/logger: Minimalistic logging library for Go.

logger

Minimalistic logging library for Go. Features:

Install

$ go get github.com/azer/logger

Getting Started

Create an instance with a preferred name;

import "github.com/azer/logger"

var log = logger.New("example-app")

Every logger has three methods: Info, Timer and Error.

log.Info("Running at %d", 8080)

err := DoSomething()

if err != nil {
  log.Error("Failed: %s", err.Error())
}

Done. Now run your app, passing LOG=* environment variable. If you don't pass LOG=*, (logging will be silent by default);

$ LOG=* go run example-app.go
01:23:21.251 example-app Running at 8080

You can filter logs by level, too. The hierarchy is; mute, info, timer and error. After the package selector, you can optionally specify minimum log level:

$ LOG=*@timer go run example-app.go
01:23:21.251 example-app Running at 8080

The above example will only show timer and error levels. If you choose error, it'll show only error logs.

Check out examples for a more detailed example.

Filters

You can enable all logs by specifying *:

$ LOG=* go run example-app.go

Or, choose specific packages that you want to see logs from:

$ LOG=images,users go run example-app.go

In the above example, you'll only see logs from images and users packages. What if we want to see only timer and error level logs?

$ LOG=images@timer,users go run example-app.go

Another example; show error logs from all packages, but hide logs from database package:

$ LOG=*@error,database@mute go run example-app.go

Timers

You can use timer logs for measuring your program. For example;

timer := log.Timer()

image, err := PullImage("http://foo.com/bar.jpg")

timer.End("Fetched foo.com/bar.jpg")

Timer log lines will be outputting the elapsed time in time.Duration in a normal terminal, or in int64 format when your program is running on a non-terminal environment. See below documentation for more info.

Structured Output

When your app isn't running on a terminal, it'll change the output in JSON:

{ "time":"2014-10-04 11:44:22.418595705 -0700 PDT", "package":"database", "level":"INFO", "msg":"Connecting to mysql://azer@localhost:9900/foobar" }
{ "time":"2014-10-04 11:44:22.418600851 -0700 PDT", "package":"images", "level":"INFO", "msg":"Requesting an image at foo/bar.jpg" }
{ "time":"2014-10-04 11:44:22.668645527 -0700 PDT", "package":"images", "level":"TIMER", "elapsed":"250032416", "msg":"Fetched foo/bar.jpg" }
{ "time":"2014-10-04 11:44:22.668665527 -0700 PDT", "package":"database", "level":"ERROR", "msg":"Fatal connection error." }

So you can parse & process the output easily. Here is a command that lets you see the JSON output in your terminal;

LOG=* go run examples/simple.go 2>&1 | less

Attributes

To add custom attributes to the structured output;

log.Info("Sending an e-mail...", logger.Attrs{
  "from": "[email protected]",
  "to": "[email protected]",
})

The above log will appear in the structured output as:

{ "time":"2014-10-04 11:44:22.919726985 -0700 PDT", "package":"mail", "level":"INFO", "msg":"Sending an e-mail", "from": "[email protected]", "to": "[email protected]" }

In your command-line as:

Programmatical Usage

Customizing the default behavior is easy. You can implement your own output;

import (
  "github.com/azer/logger"
)

type CustomWriter struct {}

func (cw CustomWriter) Write (log *logger.Log) {
  fmt.Println("custom log -> ", log.Package, log.Level, log.Message, log.Attrs)
}

func main () {
  logger.Hook(&CustomWriter{})
}

See examples/programmatical.go for a working version of this example.

Hooks

  • Slack: Stream logs into a Slack channel.

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