Merge pull request #467 from bengadbois/small_code_cleanup
Small var declaration cleanup
diff --git a/README.md b/README.md
index 05d678a..206c746 100644
--- a/README.md
+++ b/README.md
@@ -87,8 +87,8 @@
// 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)
@@ -240,6 +240,7 @@
| [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
diff --git a/text_formatter.go b/text_formatter.go
index 3fcd7f0..076de5d 100644
--- a/text_formatter.go
+++ b/text_formatter.go
@@ -28,10 +28,6 @@
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
@@ -115,8 +111,10 @@
levelText := strings.ToUpper(entry.Level.String())[0:4]
- if !f.FullTimestamp {
- fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message)
+ 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, 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)
}
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 @@
"errors"
"testing"
"time"
+ "strings"
)
func TestQuoting(t *testing.T) {
@@ -57,5 +58,14 @@
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.