Merge pull request #635 from ernestoalejo/master

Split terminal check to add build tags to support App Engine.
This commit is contained in:
Simon Eskildsen 2017-12-05 15:30:37 -05:00 committed by GitHub
commit 49f0a85ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 14 deletions

View File

@ -0,0 +1,11 @@
// +build appengine
package logrus
import (
"io"
)
func checkIfTerminal(w io.Writer) bool {
return true
}

View File

@ -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
}
}

View File

@ -3,14 +3,10 @@ package logrus
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"os"
"sort" "sort"
"strings" "strings"
"sync" "sync"
"time" "time"
"golang.org/x/crypto/ssh/terminal"
) )
const ( const (
@ -65,16 +61,7 @@ type TextFormatter struct {
func (f *TextFormatter) init(entry *Entry) { func (f *TextFormatter) init(entry *Entry) {
if entry.Logger != nil { if entry.Logger != nil {
f.isTerminal = f.checkIfTerminal(entry.Logger.Out) f.isTerminal = 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
} }
} }