Skip to content

Commit a253cee

Browse files
committed
switch back to log4go 4.0.2
1 parent 708d09e commit a253cee

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

log4go_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestConsoleLogWriter(t *testing.T) {
100100
console.format = "[%T %z %D] [%L] [%S] %M"
101101

102102
r, w := io.Pipe()
103-
console.iow = w
103+
console.out = w
104104

105105
defer console.Close()
106106

@@ -529,13 +529,14 @@ func BenchmarkFileUtilNotLog(b *testing.B) {
529529
os.Remove("benchlog.log")
530530
}
531531

532-
// Benchmark results (darwin amd64 6g)
533-
//elog.BenchmarkConsoleLog 100000 22819 ns/op
534-
//elog.BenchmarkConsoleNotLogged 2000000 879 ns/op
535-
//elog.BenchmarkConsoleUtilLog 50000 34380 ns/op
536-
//elog.BenchmarkConsoleUtilNotLog 1000000 1339 ns/op
537-
//elog.BenchmarkFileLog 100000 26497 ns/op
538-
//elog.BenchmarkFileNotLogged 2000000 821 ns/op
539-
//elog.BenchmarkFileUtilLog 50000 33945 ns/op
540-
//elog.BenchmarkFileUtilNotLog 1000000 1258 ns/op
532+
// Benchmark results (windows amd64 10g)
533+
// BenchmarkFormatLogRecord-4 300000 4433 ns/op
534+
// BenchmarkConsoleLog-4 1000000 1746 ns/op
535+
// BenchmarkConsoleNotLogged-4 20000000 97.3 ns/op
536+
// BenchmarkConsoleUtilLog-4 300000 3783 ns/op
537+
// BenchmarkConsoleUtilNotLog-4 20000000 102 ns/op
538+
// BenchmarkFileLog-4 200000 9910 ns/op
539+
// BenchmarkFileNotLogged-4 20000000 94.9 ns/op
540+
// BenchmarkFileUtilLog-4 200000 9610 ns/op
541+
// BenchmarkFileUtilNotLog-4 20000000 103 ns/op
541542

termlog.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,37 @@ import (
66
"fmt"
77
"io"
88
"os"
9-
"github.com/daviddengcn/go-colortext"
109
)
1110

1211
var stdout io.Writer = os.Stdout
1312

13+
var isColorful = (os.Getenv("TERM") != "" && os.Getenv("TERM") != "dumb") ||
14+
os.Getenv("ConEmuANSI") == "ON"
15+
16+
// 0, Black; 1, Red; 2, Green; 3, Yellow; 4, Blue; 5, Purple; 6, Cyan; 7, White
17+
var ColorBytes = [...][]byte{
18+
[]byte("\x1b[0;34m"), // FINEST, Blue
19+
[]byte("\x1b[0;36m"), // FINE, Cyan
20+
[]byte("\x1b[0;32m"), // DEBUG, Green
21+
[]byte("\x1b[0;35m"), // TRACE, Purple
22+
nil, // INFO, Default
23+
[]byte("\x1b[1;33m"), // WARNING, Yellow
24+
[]byte("\x1b[0;31m"), // ERROR, Red
25+
[]byte("\x1b[0;31m;47m"), // CRITICAL, Red - White
26+
}
27+
var ColorReset = []byte("\x1b[0m")
28+
1429
// This is the standard writer that prints to standard output.
1530
type ConsoleLogWriter struct {
16-
iow io.Writer
31+
out io.Writer
1732
color bool
1833
format string
1934
}
2035

2136
// This creates a new ConsoleLogWriter
2237
func NewConsoleLogWriter() *ConsoleLogWriter {
2338
c := &ConsoleLogWriter{
24-
iow: stdout,
39+
out: stdout,
2540
color: false,
2641
format: "[%T %D %Z] [%L] (%S) %M",
2742
}
@@ -46,22 +61,8 @@ func (c *ConsoleLogWriter) Close() {
4661

4762
func (c *ConsoleLogWriter) LogWrite(rec *LogRecord) {
4863
if c.color {
49-
switch rec.Level {
50-
case CRITICAL:
51-
ct.ChangeColor(ct.Red, true, ct.White, false)
52-
case ERROR:
53-
ct.ChangeColor(ct.Red, false, 0, false)
54-
case WARNING:
55-
ct.ChangeColor(ct.Yellow, false, 0, false)
56-
case INFO:
57-
ct.ChangeColor(ct.Green, false, 0, false)
58-
case DEBUG:
59-
ct.ChangeColor(ct.Magenta, false, 0, false)
60-
case TRACE:
61-
ct.ChangeColor(ct.Cyan, false, 0, false)
62-
default:
63-
}
64-
defer ct.ResetColor()
64+
c.out.Write(ColorBytes[rec.Level])
65+
defer c.out.Write(ColorReset)
6566
}
66-
fmt.Fprint(c.iow, FormatLogRecord(c.format, rec))
67+
fmt.Fprint(c.out, FormatLogRecord(c.format, rec))
6768
}

0 commit comments

Comments
 (0)