Added support for text coloring on Windows 10

This commit is contained in:
Felix Kollmann 2018-04-03 00:25:30 +02:00
parent 778f2e774c
commit bb487e068c
3 changed files with 27 additions and 0 deletions

View File

@ -67,6 +67,8 @@ 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 = checkIfTerminal(entry.Logger.Out) f.isTerminal = checkIfTerminal(entry.Logger.Out)
f.initTerminal(entry)
} }
} }

6
text_formatter_linux.go Normal file
View File

@ -0,0 +1,6 @@
// +build !appengine,!gopherjs
package logrus
func (f *TextFormatter) initTerminal(entry *Entry) {
}

19
text_formatter_windows.go Normal file
View File

@ -0,0 +1,19 @@
// +build !appengine,!gopherjs
package logrus
import (
"os"
"syscall"
sequences "github.com/konsorten/go-windows-terminal-sequences"
)
func (f *TextFormatter) initTerminal(entry *Entry) {
switch v := entry.Logger.Out.(type) {
case *os.File:
handle := syscall.Handle(v.Fd())
sequences.EnableVirtualTerminalProcessing(handle, true)
}
}