Skip to content

Commit 87ff08f

Browse files
committed
Merge pull request #40 from iotdog/master
fix a bug of terminal log printing
2 parents d5cb050 + 2c81d49 commit 87ff08f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

log/color.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525
"path/filepath"
2626
"runtime"
2727
"time"
28+
)
2829

30+
import (
2931
"github.com/mattn/go-isatty"
3032
)
3133

@@ -85,7 +87,7 @@ func CPrintfln(color []byte, format string, args ...interface{}) {
8587
func CEPrintf(color []byte, format string, args ...interface{}) {
8688
logStr := fmt.Sprintf(format, args...)
8789
if isatty.IsTerminal(os.Stdout.Fd()) {
88-
fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr)
90+
fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr)
8991
} else {
9092
fmt.Fprintf(os.Stderr, "%s", logStr)
9193
}
@@ -94,7 +96,7 @@ func CEPrintf(color []byte, format string, args ...interface{}) {
9496
func CEPrintfln(color []byte, format string, args ...interface{}) {
9597
logStr := fmt.Sprintf(format, args...)
9698
if isatty.IsTerminal(os.Stdout.Fd()) {
97-
fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr)
99+
fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr)
98100
} else {
99101
fmt.Fprintf(os.Stderr, "%s\n", logStr)
100102
}

log/color_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ func TestColorLog(t *testing.T) {
2929
CWarn("%s", "/test/group%3Dbjtelecom%26protocol%3Dpb%26role%3DSRT_Provider%26service%3Dshopping%26version%3D1.0.1")
3030
CError("Error")
3131
}
32+
33+
func TestCPrintfln(t *testing.T) {
34+
CPrintfln(NRed, "%s", "/test/group%3Dbjtelecom%26protocol%3Dpb%26role%3DSRT_Provider%26service%3Dshopping%26version%3D1.0.1")
35+
}

0 commit comments

Comments
 (0)