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 (
|
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
|
||||||
|
@ -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"))
|
||||||
|
Loading…
Reference in New Issue
Block a user