https://github.com/spatialcurrent/go-sync-logger
A logger safe for concurrent use
https://github.com/spatialcurrent/go-sync-logger
Last synced: 23 days ago
JSON representation
A logger safe for concurrent use
- Host: GitHub
- URL: https://github.com/spatialcurrent/go-sync-logger
- Owner: spatialcurrent
- License: mit
- Created: 2019-01-24T03:17:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-06T21:50:24.000Z (over 6 years ago)
- Last Synced: 2024-06-20T16:47:56.944Z (over 1 year ago)
- Language: Go
- Homepage: https://godoc.org/github.com/spatialcurrent/go-sync-logger
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
[](https://circleci.com/gh/spatialcurrent/go-sync-logger/tree/master) [](https://goreportcard.com/report/spatialcurrent/go-sync-logger) [](https://godoc.org/github.com/spatialcurrent/go-sync-logger) [](https://github.com/spatialcurrent/go-sync-logger/blob/master/LICENSE)
# go-sync-logger
# Description
**go-sync-logger** (aka GSL) is a simple concurrency-safe library for sharing writers (e.g., stdout, errors.log, etc.) among multiple log levels. With **GSL** you can have `info` and `error` messages share a log with messages being written in the proper sequence.
**go-sync-logger** depends on:
- [go-reader-writer](https://github.com/spatialcurrent/go-reader-writer) for writing to arbitrary locations.
- [go-simple-serializer](https://github.com/spatialcurrent/go-simple-serializer) for serializing log messages.
# Usage
**Go**
You can import **go-sync-logger** as a library with:
```go
import (
"github.com/spatialcurrent/go-sync-logger/gsl"
)
```
To initialize the logger, use `gsl.NewLogger` and pass it the writers, formats, and proper mapping of levels to writers. For example, the configuration below, has `error` and `warn` share a writer.
```go
... () {
logger := gsl.NewLogger(
map[string]int{"info": 0, "error": 1, "warn": 1},
[]grw.ByteWriteCloser{infoWriter, errorWriter},
[]string{infoFormat, errorFormat},
)
}
```
For a complete example on how to initialize the logger using configuration provided by [viper](https://github.com/spf13/viper) see [viper.md](https://github.com/spatialcurrent/go-sync-logger/tree/master/example/viper.md) in [examples](https://github.com/spatialcurrent/go-sync-logger/tree/master/example).
See [gsl](https://godoc.org/github.com/spatialcurrent/go-sync-logger/gsl) in GoDoc for information on how to use Go API.
# Contributing
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/go-sync-logger/blob/master/CONTRIBUTING.md) for how to get started.
# License
This work is distributed under the **MIT License**. See **LICENSE** file.