https://github.com/fredmaggiowski/gonyan
Gonyan is a simple stream based logging library for Go
https://github.com/fredmaggiowski/gonyan
go log-stream logger logging stream
Last synced: over 1 year ago
JSON representation
Gonyan is a simple stream based logging library for Go
- Host: GitHub
- URL: https://github.com/fredmaggiowski/gonyan
- Owner: fredmaggiowski
- License: mit
- Created: 2017-09-16T12:16:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-17T13:00:39.000Z (over 6 years ago)
- Last Synced: 2025-01-11T08:44:53.598Z (over 1 year ago)
- Topics: go, log-stream, logger, logging, stream
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gonyan
Gonyan is a simple stream based logging library for Go.
[](https://goreportcard.com/report/github.com/fredmaggiowski/gonyan)
[](https://travis-ci.org/fredmaggiowski/gonyan)
[](https://godoc.org/github.com/fredmaggiowski/gonyan)
[](https://codecov.io/gh/fredmaggiowski/gonyan)
[](https://github.com/fredmaggiowski/gonyan)
The idea behind the package is to allow the creation of a logging utility capable of sending machine readable logs to different targets (called _Streams_) based on the desired logging level.
### Example
```go
package main
import (
"os"
"github.com/fredmaggiowski/gonyan"
)
func main() {
log := gonyan.NewLogger("GH-Example", true)
log.RegisterStream(gonyan.Fatal, os.Stderr)
if verboseMode {
log.RegisterStream(gonyan.Debug, os.Stdout)
}
log.Debug("Hello, World!")
if err := doSomething(); err != nil {
log.Errorf("doSomething() failed: %s", err.Error())
return
}
log.Debug("doSomething() worked fine")
}
```
In this example two streams are registered for two different logging levels: `stdout` for `Debug` level and `stderr` for `Error` level. Log messages sent for the `Debug` level will be streamed only to `stdout` stream while those sent with `Error` level will be streamed only to `stderr` stream.
Please note that streams are completely optional, you can call all logging functions even without registering any stream, your program won't crash but won't even log anything (of course).
Also, each logging level can have multiple stream registered and custom streams can be defined and used leaving you the power to decide what log, how, where and when.
## Stream
> Yeah, but what is a stream?
A stream is whatever `struct` that implements the function `Write([]byte) (int, error)` this choice allows Gonyan to natively support many `I/O` structures (e.g. `File`, `bytes.Buffer`, `bufio.Writer`, etc..) and being agnostic regarding where the log will be actually used.
With time, many streams will be provided out-of-the-box but everyone can create its own custom stream object and transparently provide it to the Gonyan logger.
### Formatting
As of now log messages are streamed as JSON strings, better support for other/custom formats has to be defined.
Example:
```
{"tag":"GH-Example","timestamp":1515161633123,"message":"Hello, World!"}
```