1
0
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:
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 ( import (
"fmt" "fmt"
"io" "log"
"os" "os"
"github.com/v2ray/v2ray-core/common/platform"
) )
const ( const (
@ -27,7 +25,7 @@ func (this *noOpLogger) WriteLog(prefix, format string, v ...interface{}) {
} }
type streamLogger struct { type streamLogger struct {
writer io.Writer logger *log.Logger
} }
func (this *streamLogger) WriteLog(prefix, format string, v ...interface{}) { func (this *streamLogger) WriteLog(prefix, format string, v ...interface{}) {
@ -37,13 +35,13 @@ func (this *streamLogger) WriteLog(prefix, format string, v ...interface{}) {
} else { } else {
data = fmt.Sprintf(format, v...) data = fmt.Sprintf(format, v...)
} }
this.writer.Write([]byte(prefix + data + platform.LineSeparator())) this.logger.Println(prefix + data)
} }
var ( var (
noOpLoggerInstance logger = &noOpLogger{} noOpLoggerInstance logger = &noOpLogger{}
streamLoggerInstance logger = &streamLogger{ streamLoggerInstance logger = &streamLogger{
writer: os.Stdout, logger: log.New(os.Stdout, "", log.Ldate|log.Ltime),
} }
debugLogger = noOpLoggerInstance debugLogger = noOpLoggerInstance

View File

@ -2,6 +2,7 @@ package log
import ( import (
"bytes" "bytes"
"log"
"testing" "testing"
"github.com/v2ray/v2ray-core/testing/unit" "github.com/v2ray/v2ray-core/testing/unit"
@ -24,7 +25,7 @@ func TestStreamLogger(t *testing.T) {
buffer := bytes.NewBuffer(make([]byte, 0, 1024)) buffer := bytes.NewBuffer(make([]byte, 0, 1024))
logger := &streamLogger{ logger := &streamLogger{
writer: buffer, logger: log.New(buffer, "", 0),
} }
logger.WriteLog("TestPrefix: ", "Test %s Format", "Stream Logger") logger.WriteLog("TestPrefix: ", "Test %s Format", "Stream Logger")
assert.Bytes(buffer.Bytes()).Equals([]byte("TestPrefix: Test Stream Logger Format\n")) assert.Bytes(buffer.Bytes()).Equals([]byte("TestPrefix: Test Stream Logger Format\n"))