Skip to content

Commit

Permalink
Merge pull request #23 from x-cray/feature/update-terminal-detection
Browse files Browse the repository at this point in the history
Use IsTerminal implementation from golang.org/x/crypto/ssh/terminal
  • Loading branch information
x-cray authored Jul 31, 2017
2 parents 3abfd71 + d4c6fac commit bb2702d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package prefixed
import (
"bytes"
"fmt"
"io"
"os"
"regexp"
"sort"
"strings"
Expand All @@ -11,6 +13,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/mgutz/ansi"
"golang.org/x/crypto/ssh/terminal"
)

const defaultTimestampFormat = time.RFC3339
Expand Down Expand Up @@ -144,7 +147,16 @@ func (f *TextFormatter) init(entry *logrus.Entry) {
f.QuoteCharacter = "\""
}
if entry.Logger != nil {
f.isTerminal = logrus.IsTerminal(entry.Logger.Out)
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
}
}

Expand Down

0 comments on commit bb2702d

Please sign in to comment.