Browse Source

Revert "use default logger for android and ios"

This reverts commit 9743380e2d.
pull/1463/head
Darien Raymond 6 years ago
parent
commit
b9450d8475
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 17
      app/log/log.go
  2. 16
      common/log/logger.go

17
app/log/log.go

@ -4,7 +4,6 @@ package log
import (
"context"
"runtime"
"sync"
"v2ray.com/core/common"
@ -31,18 +30,6 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
return g, nil
}
func isMobile() bool {
return runtime.GOOS == "android" || (runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64"))
}
func createStdLogWriter() log.WriterCreator {
if isMobile() {
return log.CreateDefaultLogWriter()
}
return log.CreateStdoutLogWriter()
}
func (g *Instance) initAccessLogger() error {
switch g.config.AccessLogType {
case LogType_File:
@ -52,7 +39,7 @@ func (g *Instance) initAccessLogger() error {
}
g.accessLogger = log.NewLogger(creator)
case LogType_Console:
g.accessLogger = log.NewLogger(createStdLogWriter())
g.accessLogger = log.NewLogger(log.CreateStdoutLogWriter())
default:
}
return nil
@ -67,7 +54,7 @@ func (g *Instance) initErrorLogger() error {
}
g.errorLogger = log.NewLogger(creator)
case LogType_Console:
g.errorLogger = log.NewLogger(createStdLogWriter())
g.errorLogger = log.NewLogger(log.CreateStdoutLogWriter())
default:
}
return nil

16
common/log/logger.go

@ -119,22 +119,6 @@ func CreateStdoutLogWriter() WriterCreator {
}
}
type defaultLogWriter struct{}
func (defaultLogWriter) Write(b []byte) (int, error) {
log.Print(string(b))
return len(b), nil
}
// CreateDefaultLogWriter returns a LogWriterCreator that creates LogWriter to write to default Golang logger.
func CreateDefaultLogWriter() WriterCreator {
return func() Writer {
return &consoleLogWriter{
logger: log.New(defaultLogWriter{}, "", log.Ldate|log.Ltime),
}
}
}
// CreateFileLogWriter returns a LogWriterCreator that creates LogWriter for the given file.
func CreateFileLogWriter(path string) (WriterCreator, error) {
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)

Loading…
Cancel
Save