1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

Log timestamp

This commit is contained in:
V2Ray 2015-11-28 23:13:45 +01:00
parent 10b5f5cc5e
commit cc61e88eca
2 changed files with 6 additions and 7 deletions

View File

@ -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

View File

@ -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"))