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 1 commit
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
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.

12 changes: 10 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
"fmt"
"log"
"os"
"runtime"
"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,8 +132,13 @@ 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.SetLevel(DEBUG, "")
if runtime.GOOS == "windows" {
b := SetBackend(NewLogBackend(colorable.NewColorableStderr(), "", log.LstdFlags))
b.SetLevel(DEBUG, "")
} else {
b := SetBackend(NewLogBackend(os.Stderr, "", log.LstdFlags))
b.SetLevel(DEBUG, "")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to separate with platforms. On UNIX, colorable.NewColorableStderr() return os.Stderr.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

SetFormatter(DefaultFormatter)
timeNow = time.Now
}
Expand Down