remove os-specific IsTerminal methods, and use x/crypto/ssh/terminal instead

This commit is contained in:
dmathieu
2017-07-27 14:23:27 +02:00
parent 9aa7601a11
commit e66f22976f
5 changed files with 14 additions and 144 deletions
+14 -1
View File
@@ -3,10 +3,14 @@ package logrus
import (
"bytes"
"fmt"
"io"
"os"
"sort"
"strings"
"sync"
"time"
"golang.org/x/crypto/ssh/terminal"
)
const (
@@ -61,7 +65,16 @@ type TextFormatter struct {
func (f *TextFormatter) init(entry *Entry) {
if entry.Logger != nil {
f.isTerminal = 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
}
}