Skip to content

Latest commit

 

History

History
67 lines (54 loc) · 1.82 KB

README.md

File metadata and controls

67 lines (54 loc) · 1.82 KB

glog-logrus

This packages is a replacement for glog in projects that use the 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:

[[override]]
  name = "github.com/golang/glog"
  source = "github.com/kubermatic/glog-logrus"

In your main.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.