forked from mirror/logrus
Compare commits
No commits in common. "master" and "dbd-upd-dep" have entirely different histories.
master
...
dbd-upd-de
|
@ -1,5 +1,5 @@
|
||||||
language: go
|
language: go
|
||||||
go_import_path: git.internal/re/logrus
|
go_import_path: github.com/sirupsen/logrus
|
||||||
git:
|
git:
|
||||||
depth: 1
|
depth: 1
|
||||||
env:
|
env:
|
||||||
|
|
34
README.md
34
README.md
|
@ -1,4 +1,4 @@
|
||||||
# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Build Status](https://git.internal/re/logrus/workflows/CI/badge.svg)](https://git.internal/re/logrus/actions?query=workflow%3ACI) [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![Go Reference](https://pkg.go.dev/badge/git.internal/re/logrus.svg)](https://pkg.go.dev/git.internal/re/logrus)
|
# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Build Status](https://github.com/sirupsen/logrus/workflows/CI/badge.svg)](https://github.com/sirupsen/logrus/actions?query=workflow%3ACI) [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![Go Reference](https://pkg.go.dev/badge/github.com/sirupsen/logrus.svg)](https://pkg.go.dev/github.com/sirupsen/logrus)
|
||||||
|
|
||||||
Logrus is a structured logger for Go (golang), completely API compatible with
|
Logrus is a structured logger for Go (golang), completely API compatible with
|
||||||
the standard library logger.
|
the standard library logger.
|
||||||
|
@ -28,12 +28,12 @@ import Logrus as both upper- and lower-case. Due to the Go package environment,
|
||||||
this caused issues in the community and we needed a standard. Some environments
|
this caused issues in the community and we needed a standard. Some environments
|
||||||
experienced problems with the upper-case variant, so the lower-case was decided.
|
experienced problems with the upper-case variant, so the lower-case was decided.
|
||||||
Everything using `logrus` will need to use the lower-case:
|
Everything using `logrus` will need to use the lower-case:
|
||||||
`git.internal/re/logrus`. Any package that isn't, should be changed.
|
`github.com/sirupsen/logrus`. Any package that isn't, should be changed.
|
||||||
|
|
||||||
To fix Glide, see [these
|
To fix Glide, see [these
|
||||||
comments](https://git.internal/re/logrus/issues/553#issuecomment-306591437).
|
comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437).
|
||||||
For an in-depth explanation of the casing issue, see [this
|
For an in-depth explanation of the casing issue, see [this
|
||||||
comment](https://git.internal/re/logrus/issues/570#issuecomment-313933276).
|
comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276).
|
||||||
|
|
||||||
Nicely color-coded in development (when a TTY is attached, otherwise just
|
Nicely color-coded in development (when a TTY is attached, otherwise just
|
||||||
plain text):
|
plain text):
|
||||||
|
@ -109,7 +109,7 @@ go test -bench=.*CallerTracing
|
||||||
|
|
||||||
The organization's name was changed to lower-case--and this will not be changed
|
The organization's name was changed to lower-case--and this will not be changed
|
||||||
back. If you are getting import conflicts due to case sensitivity, please use
|
back. If you are getting import conflicts due to case sensitivity, please use
|
||||||
the lower-case import: `git.internal/re/logrus`.
|
the lower-case import: `github.com/sirupsen/logrus`.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ The simplest way to use Logrus is simply the package-level exported logger:
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -130,7 +130,7 @@ func main() {
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that it's completely api-compatible with the stdlib logger, so you can
|
Note that it's completely api-compatible with the stdlib logger, so you can
|
||||||
replace your `log` imports everywhere with `log "git.internal/re/logrus"`
|
replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"`
|
||||||
and you'll now have the flexibility of Logrus. You can customize it all you
|
and you'll now have the flexibility of Logrus. You can customize it all you
|
||||||
want:
|
want:
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -190,7 +190,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a new instance of the logger. You can have any number of instances.
|
// Create a new instance of the logger. You can have any number of instances.
|
||||||
|
@ -265,9 +265,9 @@ Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "airbrake"
|
"gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "airbrake"
|
||||||
logrus_syslog "git.internal/re/logrus/hooks/syslog"
|
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ func init() {
|
||||||
```
|
```
|
||||||
Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md).
|
Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md).
|
||||||
|
|
||||||
A list of currently known service hooks can be found in this wiki [page](https://git.internal/re/logrus/wiki/Hooks)
|
A list of currently known service hooks can be found in this wiki [page](https://github.com/sirupsen/logrus/wiki/Hooks)
|
||||||
|
|
||||||
|
|
||||||
#### Level logging
|
#### Level logging
|
||||||
|
@ -338,7 +338,7 @@ could do:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -370,9 +370,9 @@ The built-in logging formatters are:
|
||||||
* When colors are enabled, levels are truncated to 4 characters by default. To disable
|
* When colors are enabled, levels are truncated to 4 characters by default. To disable
|
||||||
truncation set the `DisableLevelTruncation` field to `true`.
|
truncation set the `DisableLevelTruncation` field to `true`.
|
||||||
* When outputting to a TTY, it's often helpful to visually scan down a column where all the levels are the same width. Setting the `PadLevelText` field to `true` enables this behavior, by adding padding to the level text.
|
* When outputting to a TTY, it's often helpful to visually scan down a column where all the levels are the same width. Setting the `PadLevelText` field to `true` enables this behavior, by adding padding to the level text.
|
||||||
* All options are listed in the [generated docs](https://godoc.org/git.internal/re/logrus#TextFormatter).
|
* All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter).
|
||||||
* `logrus.JSONFormatter`. Logs fields as JSON.
|
* `logrus.JSONFormatter`. Logs fields as JSON.
|
||||||
* All options are listed in the [generated docs](https://godoc.org/git.internal/re/logrus#JSONFormatter).
|
* All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter).
|
||||||
|
|
||||||
Third party logging formatters:
|
Third party logging formatters:
|
||||||
|
|
||||||
|
@ -460,8 +460,8 @@ Logrus has a built in facility for asserting the presence of log messages. This
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import(
|
import(
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"git.internal/re/logrus/hooks/test"
|
"github.com/sirupsen/logrus/hooks/test"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module git.internal/re/logrus/ci
|
module github.com/sirupsen/logrus/ci
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
|
|
6
doc.go
6
doc.go
|
@ -1,12 +1,13 @@
|
||||||
/*
|
/*
|
||||||
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
|
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
|
||||||
|
|
||||||
|
|
||||||
The simplest way to use Logrus is simply the package-level exported logger:
|
The simplest way to use Logrus is simply the package-level exported logger:
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -18,9 +19,8 @@ The simplest way to use Logrus is simply the package-level exported logger:
|
||||||
}
|
}
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
|
|
||||||
time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10
|
time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10
|
||||||
|
|
||||||
For a full guide visit https://git.internal/re/logrus
|
For a full guide visit https://github.com/sirupsen/logrus
|
||||||
*/
|
*/
|
||||||
package logrus
|
package logrus
|
||||||
|
|
|
@ -3,13 +3,13 @@ package logrus_test
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Example_basic() {
|
func Example_basic() {
|
||||||
log := logrus.New()
|
var log = logrus.New()
|
||||||
log.Formatter = new(logrus.JSONFormatter)
|
log.Formatter = new(logrus.JSONFormatter)
|
||||||
log.Formatter = new(logrus.TextFormatter) // default
|
log.Formatter = new(logrus.TextFormatter) //default
|
||||||
log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors
|
log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors
|
||||||
log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
|
log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
|
||||||
log.Level = logrus.TraceLevel
|
log.Level = logrus.TraceLevel
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleJSONFormatter_CallerPrettyfier() {
|
func ExampleJSONFormatter_CallerPrettyfier() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package logrus_test
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DefaultFieldHook struct {
|
type DefaultFieldHook struct {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package logrus_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,15 @@ package logrus_test
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mystring string
|
var (
|
||||||
|
mystring string
|
||||||
|
)
|
||||||
|
|
||||||
type GlobalHook struct{}
|
type GlobalHook struct {
|
||||||
|
}
|
||||||
|
|
||||||
func (h *GlobalHook) Levels() []logrus.Level {
|
func (h *GlobalHook) Levels() []logrus.Level {
|
||||||
return logrus.AllLevels
|
return logrus.AllLevels
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//go:build !windows
|
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package logrus_test
|
package logrus_test
|
||||||
|
@ -7,13 +6,13 @@ import (
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
slhooks "git.internal/re/logrus/hooks/syslog"
|
slhooks "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An example on how to use a hook
|
// An example on how to use a hook
|
||||||
func Example_hook() {
|
func Example_hook() {
|
||||||
log := logrus.New()
|
var log = logrus.New()
|
||||||
log.Formatter = new(logrus.TextFormatter) // default
|
log.Formatter = new(logrus.TextFormatter) // default
|
||||||
log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors
|
log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors
|
||||||
log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
|
log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module git.internal/re/logrus
|
module github.com/sirupsen/logrus
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
. "git.internal/re/logrus"
|
. "github.com/sirupsen/logrus"
|
||||||
"git.internal/re/logrus/hooks/test"
|
"github.com/sirupsen/logrus/hooks/test"
|
||||||
. "git.internal/re/logrus/internal/testutils"
|
. "github.com/sirupsen/logrus/internal/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestHook struct {
|
type TestHook struct {
|
||||||
|
@ -49,7 +49,8 @@ func TestHookFires(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModifyHook struct{}
|
type ModifyHook struct {
|
||||||
|
}
|
||||||
|
|
||||||
func (hook *ModifyHook) Fire(entry *Entry) error {
|
func (hook *ModifyHook) Fire(entry *Entry) error {
|
||||||
entry.Data["wow"] = "whale"
|
entry.Data["wow"] = "whale"
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
lSyslog "git.internal/re/logrus/hooks/syslog"
|
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -24,8 +24,8 @@ If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
lSyslog "git.internal/re/logrus/hooks/syslog"
|
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//go:build !windows && !nacl && !plan9
|
|
||||||
// +build !windows,!nacl,!plan9
|
// +build !windows,!nacl,!plan9
|
||||||
|
|
||||||
package syslog
|
package syslog
|
||||||
|
@ -8,7 +7,7 @@ import (
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SyslogHook to send logs via syslog.
|
// SyslogHook to send logs via syslog.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//go:build !windows && !nacl && !plan9
|
|
||||||
// +build !windows,!nacl,!plan9
|
// +build !windows,!nacl,!plan9
|
||||||
|
|
||||||
package syslog
|
package syslog
|
||||||
|
@ -7,12 +6,13 @@ import (
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLocalhostAddAndPrint(t *testing.T) {
|
func TestLocalhostAddAndPrint(t *testing.T) {
|
||||||
log := logrus.New()
|
log := logrus.New()
|
||||||
hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unable to connect to local syslog.")
|
t.Errorf("Unable to connect to local syslog.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hook is a hook designed for dealing with logs in test scenarios.
|
// Hook is a hook designed for dealing with logs in test scenarios.
|
||||||
|
@ -20,26 +20,32 @@ type Hook struct {
|
||||||
|
|
||||||
// NewGlobal installs a test hook for the global logger.
|
// NewGlobal installs a test hook for the global logger.
|
||||||
func NewGlobal() *Hook {
|
func NewGlobal() *Hook {
|
||||||
|
|
||||||
hook := new(Hook)
|
hook := new(Hook)
|
||||||
logrus.AddHook(hook)
|
logrus.AddHook(hook)
|
||||||
|
|
||||||
return hook
|
return hook
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLocal installs a test hook for a given local logger.
|
// NewLocal installs a test hook for a given local logger.
|
||||||
func NewLocal(logger *logrus.Logger) *Hook {
|
func NewLocal(logger *logrus.Logger) *Hook {
|
||||||
|
|
||||||
hook := new(Hook)
|
hook := new(Hook)
|
||||||
logger.Hooks.Add(hook)
|
logger.Hooks.Add(hook)
|
||||||
|
|
||||||
return hook
|
return hook
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNullLogger creates a discarding logger and installs the test hook.
|
// NewNullLogger creates a discarding logger and installs the test hook.
|
||||||
func NewNullLogger() (*logrus.Logger, *Hook) {
|
func NewNullLogger() (*logrus.Logger, *Hook) {
|
||||||
|
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
logger.Out = ioutil.Discard
|
logger.Out = ioutil.Discard
|
||||||
|
|
||||||
return logger, NewLocal(logger)
|
return logger, NewLocal(logger)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Hook) Fire(e *logrus.Entry) error {
|
func (t *Hook) Fire(e *logrus.Entry) error {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ func TestAllHooks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggingWithHooksRace(t *testing.T) {
|
func TestLoggingWithHooksRace(t *testing.T) {
|
||||||
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
unlocker := rand.Int() % 100
|
unlocker := rand.Int() % 100
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"git.internal/re/logrus/hooks/writer"
|
"github.com/sirupsen/logrus/hooks/writer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package writer
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hook is a hook that writes logs of specified LogLevels to specified Writer
|
// Hook is a hook that writes logs of specified LogLevels to specified Writer
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
log "git.internal/re/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "git.internal/re/logrus"
|
. "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
|
@ -66,7 +66,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case error:
|
case error:
|
||||||
// Otherwise errors are ignored by `encoding/json`
|
// Otherwise errors are ignored by `encoding/json`
|
||||||
// https://git.internal/re/logrus/issues/137
|
// https://github.com/sirupsen/logrus/issues/137
|
||||||
data[k] = v.Error()
|
data[k] = v.Error()
|
||||||
default:
|
default:
|
||||||
data[k] = v
|
data[k] = v
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
. "git.internal/re/logrus"
|
. "github.com/sirupsen/logrus"
|
||||||
. "git.internal/re/logrus/internal/testutils"
|
. "github.com/sirupsen/logrus/internal/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestReportCaller verifies that when ReportCaller is set, the 'func' field
|
// TestReportCaller verifies that when ReportCaller is set, the 'func' field
|
||||||
|
@ -40,7 +40,7 @@ func TestReportCallerWhenConfigured(t *testing.T) {
|
||||||
assert.Equal(t, "testWithCaller", fields["msg"])
|
assert.Equal(t, "testWithCaller", fields["msg"])
|
||||||
assert.Equal(t, "info", fields["level"])
|
assert.Equal(t, "info", fields["level"])
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
"git.internal/re/logrus_test.TestReportCallerWhenConfigured.func3", fields[FieldKeyFunc])
|
"github.com/sirupsen/logrus_test.TestReportCallerWhenConfigured.func3", fields[FieldKeyFunc])
|
||||||
})
|
})
|
||||||
|
|
||||||
LogAndAssertJSON(t, func(log *Logger) {
|
LogAndAssertJSON(t, func(log *Logger) {
|
||||||
|
@ -328,6 +328,7 @@ func TestTimeOverrideMultipleLogs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
|
func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
|
||||||
|
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
var fields Fields
|
var fields Fields
|
||||||
|
|
||||||
|
@ -355,6 +356,7 @@ func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {
|
||||||
assert.Equal(t, "omg it is!", fields["msg"])
|
assert.Equal(t, "omg it is!", fields["msg"])
|
||||||
assert.Equal(t, "eating raw fish", fields["context"])
|
assert.Equal(t, "eating raw fish", fields["context"])
|
||||||
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
|
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
|
@ -377,7 +379,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
assert.Equal(t, "looks delicious", fields["msg"])
|
assert.Equal(t, "looks delicious", fields["msg"])
|
||||||
assert.Equal(t, "eating raw fish", fields["context"])
|
assert.Equal(t, "eating raw fish", fields["context"])
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
"git.internal/re/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
||||||
|
@ -408,7 +410,7 @@ func TestNestedLoggingReportsCorrectCaller(t *testing.T) {
|
||||||
assert.Equal(t, "The hardest workin' man in show business", fields["msg"])
|
assert.Equal(t, "The hardest workin' man in show business", fields["msg"])
|
||||||
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
|
assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
"git.internal/re/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
assert.Equal(t, filepath.ToSlash(fmt.Sprintf("%s/logrus_test.go:%d", cwd, line-1)), filepath.ToSlash(fields["file"].(string)))
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.internal/re/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleLogger_Writer_httpServer() {
|
func ExampleLogger_Writer_httpServer() {
|
||||||
|
|
Loading…
Reference in New Issue