From 7d3ddc68a3c3aa2184059ed57648b0d1e18351c0 Mon Sep 17 00:00:00 2001 From: Ernesto Alejo Date: Wed, 6 Sep 2017 19:34:58 +0200 Subject: [PATCH] Split terminal check to add build tags to support App Engine. --- terminal_check_appengine.go | 11 +++++++++++ terminal_check_notappengine.go | 19 +++++++++++++++++++ text_formatter.go | 15 +-------------- 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 terminal_check_appengine.go create mode 100644 terminal_check_notappengine.go diff --git a/terminal_check_appengine.go b/terminal_check_appengine.go new file mode 100644 index 0000000..2403de9 --- /dev/null +++ b/terminal_check_appengine.go @@ -0,0 +1,11 @@ +// +build appengine + +package logrus + +import ( + "io" +) + +func checkIfTerminal(w io.Writer) bool { + return true +} diff --git a/terminal_check_notappengine.go b/terminal_check_notappengine.go new file mode 100644 index 0000000..116bcb4 --- /dev/null +++ b/terminal_check_notappengine.go @@ -0,0 +1,19 @@ +// +build !appengine + +package logrus + +import ( + "io" + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +func checkIfTerminal(w io.Writer) bool { + switch v := w.(type) { + case *os.File: + return terminal.IsTerminal(int(v.Fd())) + default: + return false + } +} diff --git a/text_formatter.go b/text_formatter.go index be412aa..61b21ca 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -3,14 +3,10 @@ package logrus import ( "bytes" "fmt" - "io" - "os" "sort" "strings" "sync" "time" - - "golang.org/x/crypto/ssh/terminal" ) const ( @@ -65,16 +61,7 @@ type TextFormatter struct { func (f *TextFormatter) init(entry *Entry) { if entry.Logger != nil { - f.isTerminal = f.checkIfTerminal(entry.Logger.Out) - } -} - -func (f *TextFormatter) checkIfTerminal(w io.Writer) bool { - switch v := w.(type) { - case *os.File: - return terminal.IsTerminal(int(v.Fd())) - default: - return false + f.isTerminal = checkIfTerminal(entry.Logger.Out) } }