Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kubermatic/glog-logrus
https://github.com/kubermatic/glog-logrus
glog logrus
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kubermatic/glog-logrus
- Owner: kubermatic
- License: mit
- Created: 2018-08-29T08:55:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-29T08:55:39.000Z (about 6 years ago)
- Last Synced: 2024-06-19T20:50:32.319Z (5 months ago)
- Topics: glog, logrus
- Language: Go
- Size: 2.93 KB
- Stars: 2
- Watchers: 9
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# glog-logrus
This packages is a replacement for [glog](github.com/golang/glog)
in projects that use the [logrus](https://godoc.org/github.com/sirupsen/logrus).It is inspired by istio's glog package for zap:
https://github.com/istio/glog## Usage
Override the official glog package with this one.
This simply replaces the code in `vendor/golang/glog` with the code of this package.In your `Gopkg.toml`:
```toml
[[override]]
name = "github.com/golang/glog"
source = "github.com/kubermatic/glog-logrus"
```In your `main.go`:
```go
// Import the package like it is original glog
import (
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)// Create logrus logger in your main.go
logger := logrus.New()
logger.Formatter = &logrus.JSONFormatter{DisableTimestamp: true}// Overriding the default glog with our logrus glog implementation.
// Thus we need to pass it our logrus logger object.
glog.SetLogger(logger.WithField("foo", "bar"))
```Setting the logger to the glog package **MUST** happen before using glog in any package.
The functionality of logging the filename and line number is not preserved at this time.
## Function Levels
| glog | logrus |
| ------------ | ------ |
| Info | Debug |
| InfoDepth | Debug |
| Infof | Debug |
| Infoln | Debug |
| Warning | Warn |
| WarningDepth | Warn |
| Warningf | Warn |
| Warningln | Warn |
| Error | Error |
| ErrorDepth | Error |
| Errorf | Error |
| Errorln | Error |
| Exit | Fatal |
| ExitDepth | Fatal |
| Exitf | Fatal |
| Exitln | Fatal |
| Fatal | Fatal |
| FatalDepth | Fatal |
| Fatalf | Fatal |
| Fatalln | Fatal |This table is rather opinionated and build for use with the Kubernetes' [Go client](https://github.com/kubernetes/client-go).