Compare commits

...

29 Commits

Author SHA1 Message Date
re 22f067d83b fix repos 2022-12-21 15:59:06 +03:00
re b06ab7d9aa upd 2022-12-21 15:31:06 +03:00
re e451092dba Update 'go.mod' 2022-12-12 14:27:58 +03:00
David Bariod f8bf7650dc
Merge pull request #1343 from sirupsen/dbd-upd-dep
update dependencies
2022-07-19 09:08:54 +02:00
David Bariod ebc9029252 update dependencies 2022-07-19 08:45:10 +02:00
Simon Eskildsen 56c843c73d
Merge pull request #1337 from izhakmo/fix-cve
update gopkg.in/yaml.v3 to v3.0.1
2022-06-13 07:17:07 -04:00
izhakmo 41b4ee686d update gopkg.in/yaml.v3 to v3.0.1 2022-06-06 18:41:45 +03:00
David Bariod f98ed3eb76
Merge pull request #1333 from nathanejohnson/bumpxsys
bump version of golang.org/x/sys dependency
2022-06-06 06:16:01 +02:00
Nathan Johnson 2b8f60a012 bump version of golangci-lint 2022-06-02 09:52:03 -05:00
Nathan Johnson 0db10ef84a bump version of golang.org/x/sys dependency
fixes #1332
2022-06-01 20:17:29 -05:00
Simon Eskildsen 85981c0459
Merge pull request #1263 from rubensayshi/fix-race 2022-01-12 18:45:10 -05:00
David Bariod 79c5ab66aa
Merge pull request #1283 from sirupsen/dbd-log-doc
Improve Log methods documentation
2021-09-12 16:09:16 +02:00
David Bariod 5f8c666a13 Improve Log methods documentation 2021-09-12 16:03:49 +02:00
David Bariod 5418b6e7a4
Merge pull request #1282 from sirupsen/dbd-ci-no-cross
reduce the list of cross build target
2021-09-12 16:02:09 +02:00
David Bariod 25e89b7d23 do not run the linter on windows 2021-09-12 15:59:08 +02:00
David Bariod f25cd754cf remove duplicated build constraints line 2021-09-12 15:58:50 +02:00
David Bariod 51f2599bdd reduce the list of cross build target 2021-09-12 15:52:09 +02:00
David Bariod accc7da667
Merge pull request #1277 from anajavi/patch-1
ci: add go 1.17 to test matrix
2021-09-12 08:16:54 +02:00
anajavi 0926db15e5
ci: run only on go 1.17 2021-09-12 08:49:26 +03:00
David Bariod 22d63b740b
Merge pull request #1281 from sirupsen/dbd-auto-stale-issues
indicates issues as stale automatically
2021-09-11 15:01:29 +02:00
David Bariod 526e535580 indicates issues as stale automatically 2021-09-11 15:00:32 +02:00
David Bariod b53d94c8ad
Merge pull request #1266 from runphp/patch-1
Update README.md
2021-09-11 14:47:43 +02:00
David Bariod de2d2027ff
Merge pull request #1280 from sirupsen/bug-1275
bump golang.org/x/sys depency version
2021-09-11 14:20:32 +02:00
David Bariod dff9872c76 bump golang.org/x/sys depency version 2021-09-11 14:09:47 +02:00
anajavi 15b98b1d72
ci: add go 1.17 to test matrix 2021-09-02 13:45:20 +03:00
heui f5f6a033d3
Update README.md 2021-06-24 09:52:04 +08:00
Ruben de Vries 78f838918d
fix race condition for SetFormatter and properly fix SetReportCaller race as well 2021-06-16 11:57:31 +02:00
David Bariod b50299cfaa
Merge pull request #1253 from edoger/buffer-pool
Add support for the logger private buffer pool.
2021-04-22 15:34:36 +02:00
Qingshan Luo 1818363d79 Add support for the logger private buffer pool. 2021-04-20 10:48:30 +08:00
34 changed files with 232 additions and 109 deletions

View File

@ -15,20 +15,20 @@ jobs:
timeout-minutes: 10 timeout-minutes: 10
strategy: strategy:
matrix: matrix:
platform: [ubuntu-latest, windows-latest] platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2 - uses: golangci/golangci-lint-action@v2
with: with:
# must be specified without patch version # must be specified without patch version
version: v1.36 version: v1.46
cross: cross:
name: Cross name: Cross
timeout-minutes: 10 timeout-minutes: 10
strategy: strategy:
matrix: matrix:
go-version: [1.16.x] go-version: [1.17.x]
platform: [ubuntu-latest] platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
@ -47,7 +47,7 @@ jobs:
timeout-minutes: 10 timeout-minutes: 10
strategy: strategy:
matrix: matrix:
go-version: [1.14.x, 1.15.x, 1.16.x] go-version: [1.17.x]
platform: [ubuntu-latest, windows-latest] platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:

22
.github/workflows/stale.yaml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v3
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,5 +1,5 @@
language: go language: go
go_import_path: github.com/sirupsen/logrus go_import_path: git.internal/re/logrus
git: git:
depth: 1 depth: 1
env: env:

View File

@ -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://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 <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 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:
`github.com/sirupsen/logrus`. Any package that isn't, should be changed. `git.internal/re/logrus`. Any package that isn't, should be changed.
To fix Glide, see [these To fix Glide, see [these
comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437). comments](https://git.internal/re/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://github.com/sirupsen/logrus/issues/570#issuecomment-313933276). comment](https://git.internal/re/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: `github.com/sirupsen/logrus`. the lower-case import: `git.internal/re/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 "github.com/sirupsen/logrus" log "git.internal/re/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 "github.com/sirupsen/logrus"` replace your `log` imports everywhere with `log "git.internal/re/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 "github.com/sirupsen/logrus" log "git.internal/re/logrus"
) )
func init() { func init() {
@ -190,7 +190,7 @@ package main
import ( import (
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/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 "github.com/sirupsen/logrus" log "git.internal/re/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 "github.com/sirupsen/logrus/hooks/syslog" logrus_syslog "git.internal/re/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://github.com/sirupsen/logrus/wiki/Hooks) A list of currently known service hooks can be found in this wiki [page](https://git.internal/re/logrus/wiki/Hooks)
#### Level logging #### Level logging
@ -338,10 +338,10 @@ could do:
```go ```go
import ( import (
log "github.com/sirupsen/logrus" log "git.internal/re/logrus"
) )
init() { func init() {
// do something here to set environment depending on an environment variable // do something here to set environment depending on an environment variable
// or command-line flag // or command-line flag
if Environment == "production" { if Environment == "production" {
@ -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/github.com/sirupsen/logrus#TextFormatter). * All options are listed in the [generated docs](https://godoc.org/git.internal/re/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/github.com/sirupsen/logrus#JSONFormatter). * All options are listed in the [generated docs](https://godoc.org/git.internal/re/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(
"github.com/sirupsen/logrus" "git.internal/re/logrus"
"github.com/sirupsen/logrus/hooks/test" "git.internal/re/logrus/hooks/test"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
) )

View File

@ -26,15 +26,6 @@ func (p *defaultPool) Get() *bytes.Buffer {
return p.pool.Get().(*bytes.Buffer) return p.pool.Get().(*bytes.Buffer)
} }
func getBuffer() *bytes.Buffer {
return bufferPool.Get()
}
func putBuffer(buf *bytes.Buffer) {
buf.Reset()
bufferPool.Put(buf)
}
// SetBufferPool allows to replace the default logrus buffer pool // SetBufferPool allows to replace the default logrus buffer pool
// to better meets the specific needs of an application. // to better meets the specific needs of an application.
func SetBufferPool(bp BufferPool) { func SetBufferPool(bp BufferPool) {

View File

@ -1,4 +1,4 @@
module github.com/sirupsen/logrus/ci module git.internal/re/logrus/ci
go 1.15 go 1.15

View File

@ -1,4 +1,4 @@
// +build mage //go:build mage
package main package main
@ -7,13 +7,34 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"sort"
"github.com/magefile/mage/mg" "github.com/magefile/mage/mg"
"github.com/magefile/mage/sh" "github.com/magefile/mage/sh"
) )
func intersect(a, b []string) []string {
sort.Strings(a)
sort.Strings(b)
res := make([]string, 0, func() int {
if len(a) < len(b) {
return len(a)
}
return len(b)
}())
for _, v := range a {
idx := sort.SearchStrings(b, v)
if idx < len(b) && b[idx] == v {
res = append(res, v)
}
}
return res
}
// getBuildMatrix returns the build matrix from the current version of the go compiler // getBuildMatrix returns the build matrix from the current version of the go compiler
func getBuildMatrix() (map[string][]string, error) { func getFullBuildMatrix() (map[string][]string, error) {
jsonData, err := sh.Output("go", "tool", "dist", "list", "-json") jsonData, err := sh.Output("go", "tool", "dist", "list", "-json")
if err != nil { if err != nil {
return nil, err return nil, err
@ -38,6 +59,31 @@ func getBuildMatrix() (map[string][]string, error) {
return matrix, nil return matrix, nil
} }
func getBuildMatrix() (map[string][]string, error) {
minimalMatrix := map[string][]string{
"linux": []string{"amd64"},
"darwin": []string{"amd64", "arm64"},
"freebsd": []string{"amd64"},
"js": []string{"wasm"},
"solaris": []string{"amd64"},
"windows": []string{"amd64", "arm64"},
}
fullMatrix, err := getFullBuildMatrix()
if err != nil {
return nil, err
}
for os, arches := range minimalMatrix {
if fullV, ok := fullMatrix[os]; !ok {
delete(minimalMatrix, os)
} else {
minimalMatrix[os] = intersect(arches, fullV)
}
}
return minimalMatrix, nil
}
func CrossBuild() error { func CrossBuild() error {
matrix, err := getBuildMatrix() matrix, err := getBuildMatrix()
if err != nil { if err != nil {

6
doc.go
View File

@ -1,13 +1,12 @@
/* /*
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 "github.com/sirupsen/logrus" log "git.internal/re/logrus"
) )
func main() { func main() {
@ -19,8 +18,9 @@ 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://github.com/sirupsen/logrus For a full guide visit https://git.internal/re/logrus
*/ */
package logrus package logrus

View File

@ -232,6 +232,7 @@ func (entry *Entry) log(level Level, msg string) {
newEntry.Logger.mu.Lock() newEntry.Logger.mu.Lock()
reportCaller := newEntry.Logger.ReportCaller reportCaller := newEntry.Logger.ReportCaller
bufPool := newEntry.getBufferPool()
newEntry.Logger.mu.Unlock() newEntry.Logger.mu.Unlock()
if reportCaller { if reportCaller {
@ -239,11 +240,11 @@ func (entry *Entry) log(level Level, msg string) {
} }
newEntry.fireHooks() newEntry.fireHooks()
buffer = bufPool.Get()
buffer = getBuffer()
defer func() { defer func() {
newEntry.Buffer = nil newEntry.Buffer = nil
putBuffer(buffer) buffer.Reset()
bufPool.Put(buffer)
}() }()
buffer.Reset() buffer.Reset()
newEntry.Buffer = buffer newEntry.Buffer = buffer
@ -260,6 +261,13 @@ func (entry *Entry) log(level Level, msg string) {
} }
} }
func (entry *Entry) getBufferPool() (pool BufferPool) {
if entry.Logger.BufferPool != nil {
return entry.Logger.BufferPool
}
return bufferPool
}
func (entry *Entry) fireHooks() { func (entry *Entry) fireHooks() {
var tmpHooks LevelHooks var tmpHooks LevelHooks
entry.Logger.mu.Lock() entry.Logger.mu.Lock()
@ -276,18 +284,21 @@ func (entry *Entry) fireHooks() {
} }
func (entry *Entry) write() { func (entry *Entry) write() {
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
serialized, err := entry.Logger.Formatter.Format(entry) serialized, err := entry.Logger.Formatter.Format(entry)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
return return
} }
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
if _, err := entry.Logger.Out.Write(serialized); err != nil { if _, err := entry.Logger.Out.Write(serialized); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
} }
} }
// Log will log a message at the level given as parameter.
// Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit.
// For this behaviour Entry.Panic or Entry.Fatal should be used instead.
func (entry *Entry) Log(level Level, args ...interface{}) { func (entry *Entry) Log(level Level, args ...interface{}) {
if entry.Logger.IsLevelEnabled(level) { if entry.Logger.IsLevelEnabled(level) {
entry.log(level, fmt.Sprint(args...)) entry.log(level, fmt.Sprint(args...))

View File

@ -269,6 +269,12 @@ func TestEntryLogfLevel(t *testing.T) {
func TestEntryReportCallerRace(t *testing.T) { func TestEntryReportCallerRace(t *testing.T) {
logger := New() logger := New()
entry := NewEntry(logger) entry := NewEntry(logger)
// logging before SetReportCaller has the highest chance of causing a race condition
// to be detected, but doing it twice just to increase the likelyhood of detecting the race
go func() {
entry.Info("should not race")
}()
go func() { go func() {
logger.SetReportCaller(true) logger.SetReportCaller(true)
}() }()
@ -276,3 +282,20 @@ func TestEntryReportCallerRace(t *testing.T) {
entry.Info("should not race") entry.Info("should not race")
}() }()
} }
func TestEntryFormatterRace(t *testing.T) {
logger := New()
entry := NewEntry(logger)
// logging before SetReportCaller has the highest chance of causing a race condition
// to be detected, but doing it twice just to increase the likelyhood of detecting the race
go func() {
entry.Info("should not race")
}()
go func() {
logger.SetFormatter(&TextFormatter{})
}()
go func() {
entry.Info("should not race")
}()
}

View File

@ -3,13 +3,13 @@ package logrus_test
import ( import (
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
func Example_basic() { func Example_basic() {
var log = logrus.New() 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

View File

@ -6,7 +6,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
func ExampleJSONFormatter_CallerPrettyfier() { func ExampleJSONFormatter_CallerPrettyfier() {

View File

@ -3,7 +3,7 @@ package logrus_test
import ( import (
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
type DefaultFieldHook struct { type DefaultFieldHook struct {

View File

@ -3,7 +3,7 @@ package logrus_test
import ( import (
"testing" "testing"
log "github.com/sirupsen/logrus" log "git.internal/re/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -3,15 +3,12 @@ package logrus_test
import ( import (
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
var ( var mystring string
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

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package logrus_test package logrus_test
@ -6,13 +7,13 @@ import (
"log/syslog" "log/syslog"
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
slhooks "github.com/sirupsen/logrus/hooks/syslog" slhooks "git.internal/re/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() {
var log = logrus.New() 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

4
go.mod
View File

@ -1,9 +1,9 @@
module github.com/sirupsen/logrus module git.internal/re/logrus
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
) )
go 1.13 go 1.13

4
go.sum
View File

@ -6,8 +6,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b h1:lAZ0/chPUDWwjqosYR0X4M490zQhMsiJ4K3DbA7o+3g= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

View File

@ -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"
. "github.com/sirupsen/logrus" . "git.internal/re/logrus"
"github.com/sirupsen/logrus/hooks/test" "git.internal/re/logrus/hooks/test"
. "github.com/sirupsen/logrus/internal/testutils" . "git.internal/re/logrus/internal/testutils"
) )
type TestHook struct { type TestHook struct {
@ -49,8 +49,7 @@ 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"

View File

@ -5,8 +5,8 @@
```go ```go
import ( import (
"log/syslog" "log/syslog"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog" lSyslog "git.internal/re/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"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog" lSyslog "git.internal/re/logrus/hooks/syslog"
) )
func main() { func main() {

View File

@ -1,3 +1,4 @@
//go:build !windows && !nacl && !plan9
// +build !windows,!nacl,!plan9 // +build !windows,!nacl,!plan9
package syslog package syslog
@ -7,7 +8,7 @@ import (
"log/syslog" "log/syslog"
"os" "os"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
// SyslogHook to send logs via syslog. // SyslogHook to send logs via syslog.

View File

@ -1,3 +1,4 @@
//go:build !windows && !nacl && !plan9
// +build !windows,!nacl,!plan9 // +build !windows,!nacl,!plan9
package syslog package syslog
@ -6,13 +7,12 @@ import (
"log/syslog" "log/syslog"
"testing" "testing"
"github.com/sirupsen/logrus" "git.internal/re/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.")
} }

View File

@ -6,7 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"sync" "sync"
"github.com/sirupsen/logrus" "git.internal/re/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,32 +20,26 @@ 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 {

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -40,7 +40,6 @@ 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

View File

@ -14,8 +14,8 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
log "github.com/sirupsen/logrus" log "git.internal/re/logrus"
"github.com/sirupsen/logrus/hooks/writer" "git.internal/re/logrus/hooks/writer"
) )
func main() { func main() {

View File

@ -3,7 +3,7 @@ package writer
import ( import (
"io" "io"
log "github.com/sirupsen/logrus" log "git.internal/re/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

View File

@ -5,7 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
log "github.com/sirupsen/logrus" log "git.internal/re/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
. "github.com/sirupsen/logrus" . "git.internal/re/logrus"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@ -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://github.com/sirupsen/logrus/issues/137 // https://git.internal/re/logrus/issues/137
data[k] = v.Error() data[k] = v.Error()
default: default:
data[k] = v data[k] = v

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@ -44,6 +44,9 @@ type Logger struct {
entryPool sync.Pool entryPool sync.Pool
// Function to exit the application, defaults to `os.Exit()` // Function to exit the application, defaults to `os.Exit()`
ExitFunc exitFunc ExitFunc exitFunc
// The buffer pool used to format the log. If it is nil, the default global
// buffer pool will be used.
BufferPool BufferPool
} }
type exitFunc func(int) type exitFunc func(int)
@ -192,6 +195,9 @@ func (logger *Logger) Panicf(format string, args ...interface{}) {
logger.Logf(PanicLevel, format, args...) logger.Logf(PanicLevel, format, args...)
} }
// Log will log a message at the level given as parameter.
// Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit.
// For this behaviour Logger.Panic or Logger.Fatal should be used instead.
func (logger *Logger) Log(level Level, args ...interface{}) { func (logger *Logger) Log(level Level, args ...interface{}) {
if logger.IsLevelEnabled(level) { if logger.IsLevelEnabled(level) {
entry := logger.newEntry() entry := logger.newEntry()
@ -402,3 +408,10 @@ func (logger *Logger) ReplaceHooks(hooks LevelHooks) LevelHooks {
logger.mu.Unlock() logger.mu.Unlock()
return oldHooks return oldHooks
} }
// SetBufferPool sets the logger buffer pool.
func (logger *Logger) SetBufferPool(pool BufferPool) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.BufferPool = pool
}

View File

@ -67,3 +67,31 @@ func TestWarninglnNotEqualToWarning(t *testing.T) {
assert.NotEqual(t, buf.String(), bufln.String(), "Warning() and Wantingln() should not be equal") assert.NotEqual(t, buf.String(), bufln.String(), "Warning() and Wantingln() should not be equal")
} }
type testBufferPool struct {
buffers []*bytes.Buffer
get int
}
func (p *testBufferPool) Get() *bytes.Buffer {
p.get++
return new(bytes.Buffer)
}
func (p *testBufferPool) Put(buf *bytes.Buffer) {
p.buffers = append(p.buffers, buf)
}
func TestLogger_SetBufferPool(t *testing.T) {
out := &bytes.Buffer{}
l := New()
l.SetOutput(out)
pool := new(testBufferPool)
l.SetBufferPool(pool)
l.Info("test")
assert.Equal(t, pool.get, 1, "Logger.SetBufferPool(): The BufferPool.Get() must be called")
assert.Len(t, pool.buffers, 1, "Logger.SetBufferPool(): The BufferPool.Put() must be called")
}

View File

@ -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"
. "github.com/sirupsen/logrus" . "git.internal/re/logrus"
. "github.com/sirupsen/logrus/internal/testutils" . "git.internal/re/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,
"github.com/sirupsen/logrus_test.TestReportCallerWhenConfigured.func3", fields[FieldKeyFunc]) "git.internal/re/logrus_test.TestReportCallerWhenConfigured.func3", fields[FieldKeyFunc])
}) })
LogAndAssertJSON(t, func(log *Logger) { LogAndAssertJSON(t, func(log *Logger) {
@ -328,7 +328,6 @@ 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
@ -356,7 +355,6 @@ 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) {
@ -379,7 +377,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,
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"]) "git.internal/re/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)))
@ -410,7 +408,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,
"github.com/sirupsen/logrus_test.TestNestedLoggingReportsCorrectCaller", fields["func"]) "git.internal/re/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)))

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"net/http" "net/http"
"github.com/sirupsen/logrus" "git.internal/re/logrus"
) )
func ExampleLogger_Writer_httpServer() { func ExampleLogger_Writer_httpServer() {