From 1d329ad042a28dd4694bc10a1e6ce3b9a5e67a3c Mon Sep 17 00:00:00 2001 From: Andrew Burian Date: Mon, 21 Nov 2016 10:09:59 -0800 Subject: [PATCH 1/4] 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 2/4] 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 26809363aac4cc10d49171447009ac6bccc9c655 Mon Sep 17 00:00:00 2001 From: Simon Eskildsen Date: Thu, 1 Dec 2016 18:53:16 -0500 Subject: [PATCH 3/4] 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 4/4] 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