Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion terminal_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@

package logrus

import "golang.org/x/sys/unix"
import (
"io"

"golang.org/x/sys/unix"
)

const ioctlReadTermios = unix.TIOCGETA

type Termios unix.Termios

func initTerminal(w io.Writer) {
}
2 changes: 1 addition & 1 deletion terminal_check_notappengine.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !appengine,!gopherjs
// +build !appengine,!gopherjs,!windows

package logrus

Expand Down
20 changes: 20 additions & 0 deletions terminal_check_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build !appengine,!gopherjs,windows

package logrus

import (
"io"
"os"
"syscall"
)

func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
var mode uint32
err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
return err == nil
default:
return false
}
}
9 changes: 8 additions & 1 deletion terminal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

package logrus

import "golang.org/x/sys/unix"
import (
"io"

"golang.org/x/sys/unix"
)

const ioctlReadTermios = unix.TCGETS

type Termios unix.Termios

func initTerminal(w io.Writer) {
}
18 changes: 18 additions & 0 deletions terminal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build !appengine,!gopherjs,windows

package logrus

import (
"io"
"os"
"syscall"

sequences "github.com/konsorten/go-windows-terminal-sequences"
)

func initTerminal(w io.Writer) {
switch v := w.(type) {
case *os.File:
sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
}
}
5 changes: 4 additions & 1 deletion text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type TextFormatter struct {
// be desired.
DisableSorting bool


// Disables the truncation of the level text to 4 characters.
DisableLevelTruncation bool

Expand All @@ -67,6 +66,10 @@ type TextFormatter struct {
func (f *TextFormatter) init(entry *Entry) {
if entry.Logger != nil {
f.isTerminal = checkIfTerminal(entry.Logger.Out)

if f.isTerminal {
initTerminal(entry.Logger.Out)
}
}
}

Expand Down