Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support windows color via mattn/go-colorable #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"

"github.com/op/go-logging"
"github.com/mattn/go-colorable"
)

var log = logging.MustGetLogger("example")
Expand All @@ -46,8 +47,14 @@ func (p Password) Redacted() interface{} {

func main() {
// For demo purposes, create two backend for os.Stderr.
backend1 := logging.NewLogBackend(os.Stderr, "", 0)
backend2 := logging.NewLogBackend(os.Stderr, "", 0)
// To support windows, a colorable stderr is needed!
var stderr io.Writer = os.Stderr
if runtime.GOOS == "windows" {
stderr = colorable.NewColorableStderr()
}

backend1 := logging.NewLogBackend(stderr, "", 0)
backend2 := logging.NewLogBackend(stderr, "", 0)

// For messages written to backend2 we want to add some additional
// information to the output, including the used log level and the name of
Expand Down
3 changes: 0 additions & 3 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ type stringFormatter struct {
// For the 'callpath' verb, the output can be adjusted to limit the printing
// the stack depth. i.e. '%{callpath:3}' will print '~.a.b.c'
//
// Colors on Windows is unfortunately not supported right now and is currently
// a no-op.
//
// There's also a couple of experimental 'verbs'. These are exposed to get
// feedback and needs a bit of tinkering. Hence, they might change in the
// future.
Expand Down
2 changes: 0 additions & 2 deletions log_nix.go → log.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !windows

// Copyright 2013, Örjan Persson. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Expand Down
107 changes: 0 additions & 107 deletions log_windows.go

This file was deleted.

4 changes: 3 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"strings"
"sync/atomic"
"time"

colorable "github.com/mattn/go-colorable"
)

// Redactor is an interface for types that may contain sensitive information
Expand Down Expand Up @@ -129,7 +131,7 @@ func Reset() {
// if there's no backends at all configured, we could use some tricks to
// automatically setup backends based if we have a TTY or not.
sequenceNo = 0
b := SetBackend(NewLogBackend(os.Stderr, "", log.LstdFlags))
b := SetBackend(NewLogBackend(colorable.NewColorableStderr(), "", log.LstdFlags))
b.SetLevel(DEBUG, "")
SetFormatter(DefaultFormatter)
timeNow = time.Now
Expand Down