1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00
This commit is contained in:
Darien Raymond 2017-12-22 10:41:10 +01:00
parent 3938c65f7d
commit 7fdaa02bf6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -10,11 +10,13 @@ import (
"v2ray.com/core/common/signal"
)
// LogWriter is the interface for writing logs.
type LogWriter interface {
Write(string) error
io.Closer
}
// LogWriterCreator is a function to create LogWriters.
type LogWriterCreator func() LogWriter
type generalLogger struct {
@ -99,6 +101,7 @@ func (w *fileLogWriter) Close() error {
return w.file.Close()
}
// CreateStdoutLogWriter returns a LogWriterCreator that creates LogWriter for stdout.
func CreateStdoutLogWriter() LogWriterCreator {
return func() LogWriter {
return &consoleLogWriter{
@ -107,6 +110,7 @@ func CreateStdoutLogWriter() LogWriterCreator {
}
}
// CreateFileLogWriter returns a LogWriterCreator that creates LogWriter for the given file.
func CreateFileLogWriter(path string) (LogWriterCreator, error) {
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {