From a5dbcc756c9a2fa9bafac6fb91bbbc5c372fcd28 Mon Sep 17 00:00:00 2001 From: Toby Date: Mon, 18 Jul 2016 16:36:46 +0100 Subject: [PATCH 01/28] Renaming 'Sirupsen' to 'sirupsen' --- doc.go | 4 ++-- examples/basic/basic.go | 2 +- examples/hook/hook.go | 5 +---- hooks/syslog/syslog.go | 3 ++- hooks/syslog/syslog_test.go | 3 ++- hooks/test/test.go | 2 +- hooks/test/test_test.go | 2 +- json_formatter.go | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc.go b/doc.go index dddd5f8..da67aba 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,7 @@ The simplest way to use Logrus is simply the package-level exported logger: package main import ( - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" ) func main() { @@ -21,6 +21,6 @@ The simplest way to use Logrus is simply the package-level exported logger: Output: 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://github.com/sirupsen/logrus */ package logrus diff --git a/examples/basic/basic.go b/examples/basic/basic.go index a1623ec..b22468d 100644 --- a/examples/basic/basic.go +++ b/examples/basic/basic.go @@ -1,7 +1,7 @@ package main import ( - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" ) var log = logrus.New() diff --git a/examples/hook/hook.go b/examples/hook/hook.go index 3187f6d..892b231 100644 --- a/examples/hook/hook.go +++ b/examples/hook/hook.go @@ -1,9 +1,6 @@ package main -import ( - "github.com/Sirupsen/logrus" - "gopkg.in/gemnasium/logrus-airbrake-hook.v2" -) +import "github.com/sirupsen/logrus" var log = logrus.New() diff --git a/hooks/syslog/syslog.go b/hooks/syslog/syslog.go index a36e200..fef9804 100644 --- a/hooks/syslog/syslog.go +++ b/hooks/syslog/syslog.go @@ -4,9 +4,10 @@ package logrus_syslog import ( "fmt" - "github.com/Sirupsen/logrus" "log/syslog" "os" + + "github.com/sirupsen/logrus" ) // SyslogHook to send logs via syslog. diff --git a/hooks/syslog/syslog_test.go b/hooks/syslog/syslog_test.go index 42762dc..89bd1ec 100644 --- a/hooks/syslog/syslog_test.go +++ b/hooks/syslog/syslog_test.go @@ -1,9 +1,10 @@ package logrus_syslog import ( - "github.com/Sirupsen/logrus" "log/syslog" "testing" + + "github.com/sirupsen/logrus" ) func TestLocalhostAddAndPrint(t *testing.T) { diff --git a/hooks/test/test.go b/hooks/test/test.go index 0688125..48c06ab 100644 --- a/hooks/test/test.go +++ b/hooks/test/test.go @@ -3,7 +3,7 @@ package test import ( "io/ioutil" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" ) // test.Hook is a hook designed for dealing with logs in test scenarios. diff --git a/hooks/test/test_test.go b/hooks/test/test_test.go index d69455b..3f55cfe 100644 --- a/hooks/test/test_test.go +++ b/hooks/test/test_test.go @@ -3,7 +3,7 @@ package test import ( "testing" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) diff --git a/json_formatter.go b/json_formatter.go index 2ad6dc5..47da504 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -16,7 +16,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { switch v := v.(type) { case error: // Otherwise errors are ignored by `encoding/json` - // https://github.com/Sirupsen/logrus/issues/137 + // https://github.com/sirupsen/logrus/issues/137 data[k] = v.Error() default: data[k] = v From ed63efede8fb241e8cb6489c179c497b8a845519 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 27 Jul 2016 13:00:56 +0100 Subject: [PATCH 02/28] re-adding airbrake import --- examples/hook/hook.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/hook/hook.go b/examples/hook/hook.go index 892b231..04e08f4 100644 --- a/examples/hook/hook.go +++ b/examples/hook/hook.go @@ -1,6 +1,9 @@ package main -import "github.com/sirupsen/logrus" +import ( + "github.com/sirupsen/logrus" + airbrake "gopkg.in/gemnasium/logrus-airbrake-hook.v2" +) var log = logrus.New() From c8b0c0e43b04fa5af90bddaff775cbd8d6fec7d5 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 27 Jul 2016 13:12:26 +0100 Subject: [PATCH 03/28] Fixing import for airbrake and adding build constraint to example hook --- README.md | 18 +++++++++--------- alt_exit_test.go | 2 +- examples/hook/hook.go | 6 ++++++ hooks/syslog/README.md | 10 +++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f8302c3..8ce5db9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Logrus :walrus: [![Build Status](https://travis-ci.org/Sirupsen/logrus.svg?branch=master)](https://travis-ci.org/Sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/Sirupsen/logrus?status.svg)](https://godoc.org/github.com/Sirupsen/logrus) +# Logrus :walrus: [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus) Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. [Godoc][godoc]. **Please note the Logrus API is not @@ -54,7 +54,7 @@ The simplest way to use Logrus is simply the package-level exported logger: package main import ( - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" ) func main() { @@ -65,7 +65,7 @@ func main() { ``` 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 "github.com/sirupsen/logrus"` and you'll now have the flexibility of Logrus. You can customize it all you want: @@ -74,7 +74,7 @@ package main import ( "os" - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" ) func init() { @@ -123,7 +123,7 @@ application, you can also create an instance of the `logrus` Logger: package main import ( - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" ) // Create a new instance of the logger. You can have any number of instances. @@ -176,9 +176,9 @@ Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in ```go import ( - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake" - logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" + logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" "log/syslog" ) @@ -203,7 +203,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. | | [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. | | [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. | -| [Syslog](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. | +| [Syslog](https://github.com/sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. | | [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. | | [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. | | [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. | @@ -277,7 +277,7 @@ could do: ```go import ( - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" ) init() { diff --git a/alt_exit_test.go b/alt_exit_test.go index 022b778..d182963 100644 --- a/alt_exit_test.go +++ b/alt_exit_test.go @@ -44,7 +44,7 @@ var testprog = []byte(` package main import ( - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "flag" "fmt" "io/ioutil" diff --git a/examples/hook/hook.go b/examples/hook/hook.go index 04e08f4..91b41ee 100644 --- a/examples/hook/hook.go +++ b/examples/hook/hook.go @@ -1,3 +1,9 @@ +// +build ignore +// Do NOT include the above line in your code. This is a build contrainst used +// to prevent import loops in the code whilst go get'ting it. +// Read more about build contrains in golang here: +// https://golang.org/pkg/go/build/#hdr-Build_Constraints + package main import ( diff --git a/hooks/syslog/README.md b/hooks/syslog/README.md index 066704b..92b391c 100644 --- a/hooks/syslog/README.md +++ b/hooks/syslog/README.md @@ -5,8 +5,8 @@ ```go import ( "log/syslog" - "github.com/Sirupsen/logrus" - logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" + "github.com/sirupsen/logrus" + logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" ) func main() { @@ -24,8 +24,8 @@ If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or " ```go import ( "log/syslog" - "github.com/Sirupsen/logrus" - logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" + "github.com/sirupsen/logrus" + logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" ) func main() { @@ -36,4 +36,4 @@ func main() { log.Hooks.Add(hook) } } -``` \ No newline at end of file +``` From 2e779aca86f47cc5e073e555b50ea876423c371c Mon Sep 17 00:00:00 2001 From: Toby Date: Tue, 16 Aug 2016 17:04:58 +0100 Subject: [PATCH 04/28] Correcting typos --- examples/hook/hook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hook/hook.go b/examples/hook/hook.go index 91b41ee..707a5bb 100644 --- a/examples/hook/hook.go +++ b/examples/hook/hook.go @@ -1,7 +1,7 @@ // +build ignore -// Do NOT include the above line in your code. This is a build contrainst used +// Do NOT include the above line in your code. This is a build constraint used // to prevent import loops in the code whilst go get'ting it. -// Read more about build contrains in golang here: +// Read more about build constraints in golang here: // https://golang.org/pkg/go/build/#hdr-Build_Constraints package main From 98b74aac5b7a98855050754bab2631a4a8ea92e3 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Wed, 24 Aug 2016 16:59:41 -0500 Subject: [PATCH 05/28] Allow disabling timestamps with colored output --- text_formatter.go | 4 +++- text_formatter_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/text_formatter.go b/text_formatter.go index cce61f2..b282470 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -115,7 +115,9 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin levelText := strings.ToUpper(entry.Level.String())[0:4] - if !f.FullTimestamp { + if f.DisableTimestamp { + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message) + } else if !f.FullTimestamp { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message) } else { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) diff --git a/text_formatter_test.go b/text_formatter_test.go index e25a44f..107703f 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -5,6 +5,7 @@ import ( "errors" "testing" "time" + "strings" ) func TestQuoting(t *testing.T) { @@ -57,5 +58,14 @@ func TestTimestampFormat(t *testing.T) { checkTimeStr("") } +func TestDisableTimestampWithColoredOutput(t *testing.T) { + tf := &TextFormatter{DisableTimestamp: true, ForceColors: true} + + b, _ := tf.Format(WithField("test", "test")) + if strings.Contains(string(b), "[0000]") { + t.Error("timestamp not expected when DisableTimestamp is true") + } +} + // TODO add tests for sorting etc., this requires a parser for the text // formatter output. From 32472f55b62f98f9963e3be8d1c9de2138972a4c Mon Sep 17 00:00:00 2001 From: Sagar Sadashiv Patwardhan Date: Sun, 18 Sep 2016 12:42:16 -0700 Subject: [PATCH 06/28] Add scribe hook --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab48929..8255e54 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [Typetalk](https://github.com/dragon3/logrus-typetalk-hook) | Hook for logging to [Typetalk](https://www.typetalk.in/) | | [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch| | [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)| +| [Scribe](https://github.com/sagar8192/logrus-scribe-hook) | Hook for logging to [Scribe](https://github.com/facebookarchive/scribe)| | [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) | | [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | From f7be9f0695a9945a07b0d57f49536cdc37f12fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Depierrepont=20aka=20Toorop?= Date: Mon, 19 Sep 2016 16:09:08 +0200 Subject: [PATCH 07/28] Add Pushover Hook --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab48929..52b8325 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)| | [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) | | [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | +| [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) | #### Level logging From f76d643702a30fbffecdfe50831e11881c96ceb3 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Wed, 28 Sep 2016 11:55:00 +0100 Subject: [PATCH 08/28] Fix formatting of wrapped errors when colors are used There are two different code paths for rendering a key/value pair. The non-color version uses a type switch that handles specific types such as "error", and the color version uses the %+v printf format specifier. This causes an inconsistency between the two formats. In particular, errors created using the github.com/pkg/errors package will include a stack trace of where the error was created when printed to the terminal, but not to a file. Printing the stack trace as part of the log field is probably not the right behavior. The output is also inconsistent between the two forms because strings are not quoted/escaped when colors are used. This can make log output unparseable. Fix this by making both code paths use the type switch and escaping rules. Fix the escaping code to pass the error value to Fprintf, not the error itself, which seems to be necessary to avoid blank output with errors created by github.com/pkg/errors. --- text_formatter.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index cce61f2..9114b3c 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -122,7 +122,8 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin } for _, k := range keys { v := entry.Data[k] - fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=%+v", levelColor, k, v) + fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) + f.appendValue(b, v) } } @@ -142,7 +143,11 @@ func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interf b.WriteString(key) b.WriteByte('=') + f.appendValue(b, value) + b.WriteByte(' ') +} +func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { switch value := value.(type) { case string: if !needsQuoting(value) { @@ -155,11 +160,9 @@ func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interf if !needsQuoting(errmsg) { b.WriteString(errmsg) } else { - fmt.Fprintf(b, "%q", value) + fmt.Fprintf(b, "%q", errmsg) } default: fmt.Fprint(b, value) } - - b.WriteByte(' ') } From 0c8a99c9b84247e9d52936ae51d8f46f8889250f Mon Sep 17 00:00:00 2001 From: Alexandre Richonnier Date: Wed, 5 Oct 2016 09:20:26 +0200 Subject: [PATCH 09/28] Update README.md add link to Logrus and Viper integration Helper --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab48929..527eef1 100644 --- a/README.md +++ b/README.md @@ -367,6 +367,7 @@ entries. It should not be a feature of the application-level logger. | Tool | Description | | ---- | ----------- | |[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.| +|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper arround Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) | #### Testing From ea5eab4f4bfd0d7865aab70b6fc8ea50f749a4e6 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 9 Oct 2016 13:02:24 +0200 Subject: [PATCH 10/28] Adds new logz.io hook by @ripcurld00d --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab48929..ae61df2 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch| | [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)| | [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) | +| [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash | | [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | From 140886f9dcb2b0a8d6dd197666306b92d5decc2f Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Thu, 3 Nov 2016 01:28:25 -0400 Subject: [PATCH 11/28] Updated .travis.yml to ignore /examples/ /examples/hook/hook.go with it's child dependency on airbrake/gobrake is not backwards compatible pre-go1.6 due to use of the following: - os.LookupEnv (introduced in go1.5) - http.StatusTooManyRequests (introduced in go1.6) ignoring the fetch and explicit test of /examples/ fixes failing go1.3, go1.4, go1.5 builds. --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dee4eb2..abd0c9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,9 @@ go: - 1.4 - 1.5 - 1.6 + - 1.7 - tip install: - - go get -t ./... -script: GOMAXPROCS=4 GORACE="halt_on_error=1" go test -race -v ./... + - go get -t $(go list ./... | grep -v /examples/) +script: + - GOMAXPROCS=4 GORACE="halt_on_error=1" go test -race -v $(go list ./... | grep -v /examples/) From 65aed8c49364d404fab2d74522332a3679137d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Lafoucrie=CC=80re?= Date: Thu, 3 Nov 2016 21:59:20 -0400 Subject: [PATCH 12/28] Add pglogrus to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 126cd1f..f9cfb0a 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash | | [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | | [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) | +| [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) | #### Level logging From 528e33852cbb7234447974a9dd35d0081f068952 Mon Sep 17 00:00:00 2001 From: Simon Eskildsen Date: Fri, 11 Nov 2016 07:09:38 -0500 Subject: [PATCH 13/28] Remove legacy go versions --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index abd0c9c..ec7dd78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ language: go go: - - 1.3 - - 1.4 - - 1.5 - 1.6 - 1.7 - tip From 2173899f8f5b34385d0713b79ad2c4ff2071a850 Mon Sep 17 00:00:00 2001 From: Ryan Canty Date: Mon, 15 Aug 2016 11:04:25 -0700 Subject: [PATCH 14/28] Added customizable keys to JSON formatter --- json_formatter.go | 24 +++++++++++++++++++++--- json_formatter_test.go | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/json_formatter.go b/json_formatter.go index 2ad6dc5..7364fe8 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -8,6 +8,9 @@ import ( type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string + MessageKey string + LevelKey string + TimeKey string } func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { @@ -29,9 +32,24 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { timestampFormat = DefaultTimestampFormat } - data["time"] = entry.Time.Format(timestampFormat) - data["msg"] = entry.Message - data["level"] = entry.Level.String() + timeKey := f.TimeKey + if timeKey == "" { + timeKey = "time" + } + + messageKey := f.MessageKey + if messageKey == "" { + messageKey = "msg" + } + + levelKey := f.LevelKey + if levelKey == "" { + levelKey = "level" + } + + data[timeKey] = entry.Time.Format(timestampFormat) + data[messageKey] = entry.Message + data[levelKey] = entry.Level.String() serialized, err := json.Marshal(data) if err != nil { diff --git a/json_formatter_test.go b/json_formatter_test.go index 1d70873..0fa3466 100644 --- a/json_formatter_test.go +++ b/json_formatter_test.go @@ -3,7 +3,7 @@ package logrus import ( "encoding/json" "errors" - + "strings" "testing" ) @@ -118,3 +118,42 @@ func TestJSONEntryEndsWithNewline(t *testing.T) { t.Fatal("Expected JSON log entry to end with a newline") } } + +func TestJSONMessageKey(t *testing.T) { + formatter := &JSONFormatter{MessageKey: "message"} + + b, err := formatter.Format(&Entry{Message: "oh hai"}) + if err != nil { + t.Fatal("Unable to format entry: ", err) + } + s := string(b) + if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) { + t.Fatal("Expected JSON to format message key") + } +} + +func TestJSONLevelKey(t *testing.T) { + formatter := &JSONFormatter{LevelKey: "somelevel"} + + b, err := formatter.Format(WithField("level", "something")) + if err != nil { + t.Fatal("Unable to format entry: ", err) + } + s := string(b) + if !strings.Contains(s, "somelevel") { + t.Fatal("Expected JSON to format level key") + } +} + +func TestJSONTimeKey(t *testing.T) { + formatter := &JSONFormatter{TimeKey: "timeywimey"} + + b, err := formatter.Format(WithField("level", "something")) + if err != nil { + t.Fatal("Unable to format entry: ", err) + } + s := string(b) + if !strings.Contains(s, "timeywimey") { + t.Fatal("Expected JSON to format time key") + } +} From b2c6f8aa8b5298ac71ce8e3826c8cc417e6c7336 Mon Sep 17 00:00:00 2001 From: Ryan Canty Date: Thu, 17 Nov 2016 11:28:41 -0800 Subject: [PATCH 15/28] Added resolve method to clean up Format --- json_formatter.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/json_formatter.go b/json_formatter.go index 7364fe8..0c74e5a 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -5,6 +5,14 @@ import ( "fmt" ) +type fieldKey string + +const ( + DefaultKeyMsg = "msg" + DefaultKeyLevel = "level" + DefaultKeyTime = "time" +) + type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string @@ -32,24 +40,9 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { timestampFormat = DefaultTimestampFormat } - timeKey := f.TimeKey - if timeKey == "" { - timeKey = "time" - } - - messageKey := f.MessageKey - if messageKey == "" { - messageKey = "msg" - } - - levelKey := f.LevelKey - if levelKey == "" { - levelKey = "level" - } - - data[timeKey] = entry.Time.Format(timestampFormat) - data[messageKey] = entry.Message - data[levelKey] = entry.Level.String() + data[f.resolveKey(f.TimeKey, DefaultKeyTime)] = entry.Time.Format(timestampFormat) + data[f.resolveKey(f.MessageKey, DefaultKeyMsg)] = entry.Message + data[f.resolveKey(f.LevelKey, DefaultKeyLevel)] = entry.Level.String() serialized, err := json.Marshal(data) if err != nil { @@ -57,3 +50,10 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { } return append(serialized, '\n'), nil } + +func (f *JSONFormatter) resolveKey(key, defaultKey string) string { + if len(key) > 0 { + return key + } + return defaultKey +} From d5ca23f998921ce222ad9227e09a254e68fda4b8 Mon Sep 17 00:00:00 2001 From: Ryan Canty Date: Thu, 17 Nov 2016 15:16:46 -0800 Subject: [PATCH 16/28] Added FieldMap to reduce potential struct bloat --- json_formatter.go | 33 ++++++++++++++++----------------- json_formatter_test.go | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/json_formatter.go b/json_formatter.go index 0c74e5a..1e3e2bc 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -4,21 +4,27 @@ import ( "encoding/json" "fmt" ) - type fieldKey string +type FieldMap map[fieldKey]string const ( - DefaultKeyMsg = "msg" - DefaultKeyLevel = "level" - DefaultKeyTime = "time" + FieldKeyMsg = "msg" + FieldKeyLevel = "level" + FieldKeyTime = "time" ) +func (f FieldMap) resolve(key fieldKey) string { + if k, ok := f[key]; ok { + return k + } + + return string(key) +} + type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string - MessageKey string - LevelKey string - TimeKey string + FieldMap FieldMap } func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { @@ -40,9 +46,9 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { timestampFormat = DefaultTimestampFormat } - data[f.resolveKey(f.TimeKey, DefaultKeyTime)] = entry.Time.Format(timestampFormat) - data[f.resolveKey(f.MessageKey, DefaultKeyMsg)] = entry.Message - data[f.resolveKey(f.LevelKey, DefaultKeyLevel)] = entry.Level.String() + data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) + data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message + data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() serialized, err := json.Marshal(data) if err != nil { @@ -50,10 +56,3 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { } return append(serialized, '\n'), nil } - -func (f *JSONFormatter) resolveKey(key, defaultKey string) string { - if len(key) > 0 { - return key - } - return defaultKey -} diff --git a/json_formatter_test.go b/json_formatter_test.go index 0fa3466..5baa93e 100644 --- a/json_formatter_test.go +++ b/json_formatter_test.go @@ -120,7 +120,11 @@ func TestJSONEntryEndsWithNewline(t *testing.T) { } func TestJSONMessageKey(t *testing.T) { - formatter := &JSONFormatter{MessageKey: "message"} + formatter := &JSONFormatter{ + FieldMap: FieldMap{ + FieldKeyMsg: "message", + }, + } b, err := formatter.Format(&Entry{Message: "oh hai"}) if err != nil { @@ -133,7 +137,11 @@ func TestJSONMessageKey(t *testing.T) { } func TestJSONLevelKey(t *testing.T) { - formatter := &JSONFormatter{LevelKey: "somelevel"} + formatter := &JSONFormatter{ + FieldMap: FieldMap{ + FieldKeyLevel: "somelevel", + }, + } b, err := formatter.Format(WithField("level", "something")) if err != nil { @@ -146,7 +154,11 @@ func TestJSONLevelKey(t *testing.T) { } func TestJSONTimeKey(t *testing.T) { - formatter := &JSONFormatter{TimeKey: "timeywimey"} + formatter := &JSONFormatter{ + FieldMap: FieldMap{ + FieldKeyTime: "timeywimey", + }, + } b, err := formatter.Format(WithField("level", "something")) if err != nil { From fcf4b8f2294f4097a4cc70639c0f5eb067e1b49c Mon Sep 17 00:00:00 2001 From: Ryan Canty Date: Fri, 18 Nov 2016 11:02:11 -0800 Subject: [PATCH 17/28] Added comment documentation for FieldMap --- json_formatter.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/json_formatter.go b/json_formatter.go index 1e3e2bc..f3729bf 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" ) + type fieldKey string type FieldMap map[fieldKey]string @@ -24,7 +25,17 @@ func (f FieldMap) resolve(key fieldKey) string { type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string - FieldMap FieldMap + + // FieldMap allows users to customize the names of keys for various fields. + // As an example: + // formatter := &JSONFormatter{ + // FieldMap: FieldMap{ + // FieldKeyTime: "@timestamp", + // FieldKeyLevel: "@level", + // FieldKeyLevel: "@message", + // }, + // } + FieldMap FieldMap } func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { From 1d329ad042a28dd4694bc10a1e6ce3b9a5e67a3c Mon Sep 17 00:00:00 2001 From: Andrew Burian Date: Mon, 21 Nov 2016 10:09:59 -0800 Subject: [PATCH 18/28] Added option to disable JSON timestamp Tests verify both the default and disabled case. --- json_formatter.go | 7 ++++++- json_formatter_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/json_formatter.go b/json_formatter.go index f3729bf..266554e 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -26,6 +26,9 @@ type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string + // DisableTimestamp allows disabling automatic timestamps in output + DisableTimestamp bool + // FieldMap allows users to customize the names of keys for various fields. // As an example: // formatter := &JSONFormatter{ @@ -57,7 +60,9 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { timestampFormat = DefaultTimestampFormat } - data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) + if !f.DisableTimestamp { + data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) + } data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() diff --git a/json_formatter_test.go b/json_formatter_test.go index 5baa93e..2f9dae7 100644 --- a/json_formatter_test.go +++ b/json_formatter_test.go @@ -169,3 +169,31 @@ func TestJSONTimeKey(t *testing.T) { t.Fatal("Expected JSON to format time key") } } + +func TestJSONDisableTimestamp(t *testing.T) { + formatter := &JSONFormatter{ + DisableTimestamp: true, + } + + b, err := formatter.Format(WithField("level", "something")) + if err != nil { + t.Fatal("Unable to format entry: ", err) + } + s := string(b) + if strings.Contains(s, "time") { + t.Error("Did not prevent timestamp", s) + } +} + +func TestJSONEnableTimestamp(t *testing.T) { + formatter := &JSONFormatter{} + + b, err := formatter.Format(WithField("level", "something")) + if err != nil { + t.Fatal("Unable to format entry: ", err) + } + s := string(b) + if !strings.Contains(s, "time") { + t.Error("Timestamp not present", s) + } +} From c92f90003f2292b978bd2d6c47260c732173c9fa Mon Sep 17 00:00:00 2001 From: Andrew Burian Date: Mon, 21 Nov 2016 10:16:24 -0800 Subject: [PATCH 19/28] Switched hardcoded string for const value --- json_formatter_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_formatter_test.go b/json_formatter_test.go index 2f9dae7..51093a7 100644 --- a/json_formatter_test.go +++ b/json_formatter_test.go @@ -180,7 +180,7 @@ func TestJSONDisableTimestamp(t *testing.T) { t.Fatal("Unable to format entry: ", err) } s := string(b) - if strings.Contains(s, "time") { + if strings.Contains(s, FieldKeyTime) { t.Error("Did not prevent timestamp", s) } } @@ -193,7 +193,7 @@ func TestJSONEnableTimestamp(t *testing.T) { t.Fatal("Unable to format entry: ", err) } s := string(b) - if !strings.Contains(s, "time") { + if !strings.Contains(s, FieldKeyTime) { t.Error("Timestamp not present", s) } } From a89950b15175021d9d6606dcebe2e6c21af7cee6 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Wed, 23 Nov 2016 16:19:58 -0800 Subject: [PATCH 20/28] Revert "Updated .travis.yml to ignore /examples/" This reverts commit 140886f9dcb2b0a8d6dd197666306b92d5decc2f. --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec7dd78..efed8ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ language: go go: - 1.6 - - 1.7 - tip install: - - go get -t $(go list ./... | grep -v /examples/) -script: - - GOMAXPROCS=4 GORACE="halt_on_error=1" go test -race -v $(go list ./... | grep -v /examples/) + - go get -t ./... +script: GOMAXPROCS=4 GORACE="halt_on_error=1" go test -race -v ./... From 6ecd392994fb4b6022ffd537bfd281a10d2b3d20 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Wed, 23 Nov 2016 16:20:51 -0800 Subject: [PATCH 21/28] travis: build Go 1.7 as well, removed by revert Signed-off-by: Stephen J Day --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index efed8ea..804c569 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go go: - 1.6 + - 1.7 - tip install: - go get -t ./... From 90915c932628aa7dcf3d926b4370c72b23bcdbb6 Mon Sep 17 00:00:00 2001 From: Daniel Taylor Date: Tue, 29 Nov 2016 10:52:28 -0800 Subject: [PATCH 22/28] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f9cfb0a..ed1b140 100644 --- a/README.md +++ b/README.md @@ -408,7 +408,7 @@ logrus.RegisterExitHandler(handler) ... ``` -#### Thread safty +#### Thread safety By default Logger is protected by mutex for concurrent writes, this mutex is invoked when calling hooks and writing logs. If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking. From 26809363aac4cc10d49171447009ac6bccc9c655 Mon Sep 17 00:00:00 2001 From: Simon Eskildsen Date: Thu, 1 Dec 2016 18:53:16 -0500 Subject: [PATCH 23/28] Revert "Merge pull request #384 from mnzt/master" This reverts commit 42b84f9ec624953ecbf81a94feccb3f5935c5edf, reversing changes made to cf60a8c5d5961b200e093f8c9984640e31cb967d. --- README.md | 18 +++++++++--------- alt_exit_test.go | 2 +- doc.go | 4 ++-- examples/basic/basic.go | 2 +- examples/hook/hook.go | 10 ++-------- hooks/syslog/README.md | 10 +++++----- hooks/syslog/syslog.go | 3 +-- hooks/syslog/syslog_test.go | 3 +-- hooks/test/test.go | 2 +- hooks/test/test_test.go | 2 +- json_formatter.go | 2 +- 11 files changed, 25 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 429725a..ed1b140 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Logrus :walrus: [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus) +# Logrus :walrus: [![Build Status](https://travis-ci.org/Sirupsen/logrus.svg?branch=master)](https://travis-ci.org/Sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/Sirupsen/logrus?status.svg)](https://godoc.org/github.com/Sirupsen/logrus) Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. [Godoc][godoc]. **Please note the Logrus API is not @@ -54,7 +54,7 @@ The simplest way to use Logrus is simply the package-level exported logger: package main import ( - log "github.com/sirupsen/logrus" + log "github.com/Sirupsen/logrus" ) func main() { @@ -65,7 +65,7 @@ func main() { ``` 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 "github.com/Sirupsen/logrus"` and you'll now have the flexibility of Logrus. You can customize it all you want: @@ -74,7 +74,7 @@ package main import ( "os" - log "github.com/sirupsen/logrus" + log "github.com/Sirupsen/logrus" ) func init() { @@ -123,7 +123,7 @@ application, you can also create an instance of the `logrus` Logger: package main import ( - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" ) // Create a new instance of the logger. You can have any number of instances. @@ -176,9 +176,9 @@ Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in ```go import ( - log "github.com/sirupsen/logrus" + log "github.com/Sirupsen/logrus" "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake" - logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" + logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" "log/syslog" ) @@ -203,7 +203,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. | | [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. | | [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. | -| [Syslog](https://github.com/sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. | +| [Syslog](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. | | [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. | | [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. | | [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. | @@ -283,7 +283,7 @@ could do: ```go import ( - log "github.com/sirupsen/logrus" + log "github.com/Sirupsen/logrus" ) init() { diff --git a/alt_exit_test.go b/alt_exit_test.go index d182963..022b778 100644 --- a/alt_exit_test.go +++ b/alt_exit_test.go @@ -44,7 +44,7 @@ var testprog = []byte(` package main import ( - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" "flag" "fmt" "io/ioutil" diff --git a/doc.go b/doc.go index da67aba..dddd5f8 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,7 @@ The simplest way to use Logrus is simply the package-level exported logger: package main import ( - log "github.com/sirupsen/logrus" + log "github.com/Sirupsen/logrus" ) func main() { @@ -21,6 +21,6 @@ The simplest way to use Logrus is simply the package-level exported logger: Output: 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://github.com/Sirupsen/logrus */ package logrus diff --git a/examples/basic/basic.go b/examples/basic/basic.go index b22468d..a1623ec 100644 --- a/examples/basic/basic.go +++ b/examples/basic/basic.go @@ -1,7 +1,7 @@ package main import ( - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" ) var log = logrus.New() diff --git a/examples/hook/hook.go b/examples/hook/hook.go index 707a5bb..3187f6d 100644 --- a/examples/hook/hook.go +++ b/examples/hook/hook.go @@ -1,14 +1,8 @@ -// +build ignore -// Do NOT include the above line in your code. This is a build constraint used -// to prevent import loops in the code whilst go get'ting it. -// Read more about build constraints in golang here: -// https://golang.org/pkg/go/build/#hdr-Build_Constraints - package main import ( - "github.com/sirupsen/logrus" - airbrake "gopkg.in/gemnasium/logrus-airbrake-hook.v2" + "github.com/Sirupsen/logrus" + "gopkg.in/gemnasium/logrus-airbrake-hook.v2" ) var log = logrus.New() diff --git a/hooks/syslog/README.md b/hooks/syslog/README.md index 92b391c..066704b 100644 --- a/hooks/syslog/README.md +++ b/hooks/syslog/README.md @@ -5,8 +5,8 @@ ```go import ( "log/syslog" - "github.com/sirupsen/logrus" - logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" + "github.com/Sirupsen/logrus" + logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" ) func main() { @@ -24,8 +24,8 @@ If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or " ```go import ( "log/syslog" - "github.com/sirupsen/logrus" - logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" + "github.com/Sirupsen/logrus" + logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog" ) func main() { @@ -36,4 +36,4 @@ func main() { log.Hooks.Add(hook) } } -``` +``` \ No newline at end of file diff --git a/hooks/syslog/syslog.go b/hooks/syslog/syslog.go index fef9804..a36e200 100644 --- a/hooks/syslog/syslog.go +++ b/hooks/syslog/syslog.go @@ -4,10 +4,9 @@ package logrus_syslog import ( "fmt" + "github.com/Sirupsen/logrus" "log/syslog" "os" - - "github.com/sirupsen/logrus" ) // SyslogHook to send logs via syslog. diff --git a/hooks/syslog/syslog_test.go b/hooks/syslog/syslog_test.go index 89bd1ec..42762dc 100644 --- a/hooks/syslog/syslog_test.go +++ b/hooks/syslog/syslog_test.go @@ -1,10 +1,9 @@ package logrus_syslog import ( + "github.com/Sirupsen/logrus" "log/syslog" "testing" - - "github.com/sirupsen/logrus" ) func TestLocalhostAddAndPrint(t *testing.T) { diff --git a/hooks/test/test.go b/hooks/test/test.go index 48c06ab..0688125 100644 --- a/hooks/test/test.go +++ b/hooks/test/test.go @@ -3,7 +3,7 @@ package test import ( "io/ioutil" - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" ) // test.Hook is a hook designed for dealing with logs in test scenarios. diff --git a/hooks/test/test_test.go b/hooks/test/test_test.go index 3f55cfe..d69455b 100644 --- a/hooks/test/test_test.go +++ b/hooks/test/test_test.go @@ -3,7 +3,7 @@ package test import ( "testing" - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" "github.com/stretchr/testify/assert" ) diff --git a/json_formatter.go b/json_formatter.go index 47325a7..f3729bf 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -44,7 +44,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { switch v := v.(type) { case error: // Otherwise errors are ignored by `encoding/json` - // https://github.com/sirupsen/logrus/issues/137 + // https://github.com/Sirupsen/logrus/issues/137 data[k] = v.Error() default: data[k] = v From 3c3917e6254529d51056704e46bc9cbc973d028f Mon Sep 17 00:00:00 2001 From: Simon Eskildsen Date: Thu, 1 Dec 2016 18:55:03 -0500 Subject: [PATCH 24/28] readme: apologize for casing issue --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ed1b140..05d678a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Logrus :walrus: [![Build Status](https://travis-ci.org/Sirupsen/logrus.svg?branch=master)](https://travis-ci.org/Sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/Sirupsen/logrus?status.svg)](https://godoc.org/github.com/Sirupsen/logrus) +**Seeing weird case-sensitive problems?** See [this +issue](https://github.com/sirupsen/logrus/issues/451#issuecomment-264332021). +This change has been reverted. I apologize for causing this. I greatly +underestimated the impact this would have. Logrus strives for stability and +backwards compatibility and failed to provide that. + Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. [Godoc][godoc]. **Please note the Logrus API is not yet stable (pre 1.0). Logrus itself is completely stable and has been used in From 7d228b51ce25de4afcfa60e312d4a199c327cbb2 Mon Sep 17 00:00:00 2001 From: Craig Jellick Date: Thu, 1 Dec 2016 17:34:47 -0700 Subject: [PATCH 25/28] Update readme example for switching output Clarifies that stderr is the default, not stdout. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 05d678a..77cc72a 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ func init() { // Log as JSON instead of the default ASCII formatter. log.SetFormatter(&log.JSONFormatter{}) - // Output to stderr instead of stdout, could also be a file. - log.SetOutput(os.Stderr) + // Output to stdout instead of the default stderr, could also be a file. + log.SetOutput(os.Stdout) // Only log the warning severity or above. log.SetLevel(log.WarnLevel) From cf456d321e052c9c72e2a0f805c58da75e303ce0 Mon Sep 17 00:00:00 2001 From: puddingfactory Date: Sat, 10 Dec 2016 15:34:44 -0600 Subject: [PATCH 26/28] Add Logentrus, hook for Logentries, to list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 05d678a..0e22574 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/v | [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | | [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) | | [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) | +| [Logentrus](https://github.com/puddingfactory/logentrus) | Hook for logging to [Logentries](https://logentries.com/) | #### Level logging From 5ed3e7dc937463e459202a4a318d5c4daada50a4 Mon Sep 17 00:00:00 2001 From: at15 Date: Tue, 10 Jan 2017 21:43:36 -0800 Subject: [PATCH 27/28] Remove miniTS in TextFormatter - Related issues: https://github.com/sirupsen/logrus/issues/457 - miniTS use current time instead of time the log function is called, which is inaccurate when hook takes a long time - `miniTS` is removed and replaced by `int(entry.Time.Sub(baseTimestamp)/time.Second)` in `printColored` which is the only usage of `miniTS` --- text_formatter.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index 20f2d7e..dd86caa 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -28,10 +28,6 @@ func init() { isTerminal = IsTerminal() } -func miniTS() int { - return int(time.Since(baseTimestamp) / time.Second) -} - type TextFormatter struct { // Set to true to bypass checking for a TTY before outputting colors. ForceColors bool @@ -118,7 +114,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin if f.DisableTimestamp { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message) } else if !f.FullTimestamp { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message) + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message) } else { fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) } From f761cee9106ce559af64826f9c66a73f38e51c27 Mon Sep 17 00:00:00 2001 From: Ben Gadbois Date: Wed, 11 Jan 2017 19:19:12 +0100 Subject: [PATCH 28/28] Small var declaration cleanup --- text_formatter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text_formatter.go b/text_formatter.go index 9114b3c..3fcd7f0 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -58,7 +58,7 @@ type TextFormatter struct { func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { var b *bytes.Buffer - var keys []string = make([]string, 0, len(entry.Data)) + keys := make([]string, 0, len(entry.Data)) for k := range entry.Data { keys = append(keys, k) }