Minor fixes

This commit is contained in:
世界
2022-07-20 09:41:44 +08:00
parent 45643fbed1
commit 6327c4b40c
16 changed files with 79 additions and 84 deletions

View File

@@ -75,7 +75,7 @@ func (f Formatter) Format(ctx context.Context, level Level, tag string, message
default:
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
}
return message
return message + "\n"
}
func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string, message string, timestamp time.Time) (string, string) {
@@ -126,6 +126,8 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
} else {
message = F.ToString("[", id, "] ", message)
}
messageSimple = F.ToString("[", id, "] ", messageSimple)
}
switch {
case f.DisableTimestamp:
@@ -135,7 +137,7 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
default:
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
}
return message, messageSimple
return message + "\n", messageSimple
}
func xd(value int, x int) string {

View File

@@ -1,12 +1,17 @@
package log
import "context"
import (
"context"
"os"
var _ Factory = (*nopFactory)(nil)
"github.com/sagernet/sing/common/observable"
)
var _ ObservableFactory = (*nopFactory)(nil)
type nopFactory struct{}
func NewNOPFactory() Factory {
func NewNOPFactory() ObservableFactory {
return (*nopFactory)(nil)
}
@@ -66,3 +71,10 @@ func (f *nopFactory) FatalContext(ctx context.Context, args ...any) {
func (f *nopFactory) PanicContext(ctx context.Context, args ...any) {
}
func (f *nopFactory) Subscribe() (subscription observable.Subscription[Entry], done <-chan struct{}, err error) {
return nil, nil, os.ErrInvalid
}
func (f *nopFactory) UnSubscribe(subscription observable.Subscription[Entry]) {
}

View File

@@ -71,7 +71,6 @@ func (l *observableLogger) Log(ctx context.Context, level Level, args []any) {
panic(message)
}
l.writer.Write([]byte(message))
l.writer.Write([]byte{'\n'})
if level == LevelFatal {
os.Exit(1)
}