mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
Log timestamp
This commit is contained in:
parent
10b5f5cc5e
commit
cc61e88eca
@ -2,10 +2,8 @@ package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/platform"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -27,7 +25,7 @@ func (this *noOpLogger) WriteLog(prefix, format string, v ...interface{}) {
|
||||
}
|
||||
|
||||
type streamLogger struct {
|
||||
writer io.Writer
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func (this *streamLogger) WriteLog(prefix, format string, v ...interface{}) {
|
||||
@ -37,13 +35,13 @@ func (this *streamLogger) WriteLog(prefix, format string, v ...interface{}) {
|
||||
} else {
|
||||
data = fmt.Sprintf(format, v...)
|
||||
}
|
||||
this.writer.Write([]byte(prefix + data + platform.LineSeparator()))
|
||||
this.logger.Println(prefix + data)
|
||||
}
|
||||
|
||||
var (
|
||||
noOpLoggerInstance logger = &noOpLogger{}
|
||||
streamLoggerInstance logger = &streamLogger{
|
||||
writer: os.Stdout,
|
||||
logger: log.New(os.Stdout, "", log.Ldate|log.Ltime),
|
||||
}
|
||||
|
||||
debugLogger = noOpLoggerInstance
|
||||
|
@ -2,6 +2,7 @@ package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/v2ray/v2ray-core/testing/unit"
|
||||
@ -24,7 +25,7 @@ func TestStreamLogger(t *testing.T) {
|
||||
|
||||
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
logger := &streamLogger{
|
||||
writer: buffer,
|
||||
logger: log.New(buffer, "", 0),
|
||||
}
|
||||
logger.WriteLog("TestPrefix: ", "Test %s Format", "Stream Logger")
|
||||
assert.Bytes(buffer.Bytes()).Equals([]byte("TestPrefix: Test Stream Logger Format\n"))
|
||||
|
Loading…
Reference in New Issue
Block a user