diff --git a/log/color.go b/log/color.go index 01f3fbc..b40a81c 100644 --- a/log/color.go +++ b/log/color.go @@ -25,7 +25,9 @@ import ( "path/filepath" "runtime" "time" +) +import ( "github.com/mattn/go-isatty" ) @@ -85,7 +87,7 @@ func CPrintfln(color []byte, format string, args ...interface{}) { func CEPrintf(color []byte, format string, args ...interface{}) { logStr := fmt.Sprintf(format, args...) if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr) + fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset), logStr) } else { fmt.Fprintf(os.Stderr, "%s", logStr) } @@ -94,7 +96,7 @@ func CEPrintf(color []byte, format string, args ...interface{}) { func CEPrintfln(color []byte, format string, args ...interface{}) { logStr := fmt.Sprintf(format, args...) if isatty.IsTerminal(os.Stdout.Fd()) { - fmt.Fprint(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) + fmt.Fprintf(os.Stderr, string(color)+funcFileLine()+"%s"+string(reset)+"\n", logStr) } else { fmt.Fprintf(os.Stderr, "%s\n", logStr) } diff --git a/log/color_test.go b/log/color_test.go index 5cc6f61..dc0c2b9 100644 --- a/log/color_test.go +++ b/log/color_test.go @@ -29,3 +29,7 @@ func TestColorLog(t *testing.T) { CWarn("%s", "/test/group%3Dbjtelecom%26protocol%3Dpb%26role%3DSRT_Provider%26service%3Dshopping%26version%3D1.0.1") CError("Error") } + +func TestCPrintfln(t *testing.T) { + CPrintfln(NRed, "%s", "/test/group%3Dbjtelecom%26protocol%3Dpb%26role%3DSRT_Provider%26service%3Dshopping%26version%3D1.0.1") +}