mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-06 10:22:50 +08:00
add log file
This commit is contained in:
@@ -37,7 +37,7 @@ var Log = &_LogConfig{
|
||||
|
||||
func setupGlobal() {
|
||||
global.EventManager = event.NewManger(128, 16)
|
||||
global.Logger = loggerRepo.NewZapColoredLogger()
|
||||
global.Logger = loggerRepo.NewZapColoredLogger(Log.Path, !*dev)
|
||||
global.Logger.SetLogLevel(Log.Level)
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ func registerPlayControllerHandler() {
|
||||
if event.Data.(events.PlayerPlayingUpdateEvent).Removed {
|
||||
PlayController.Progress.Value = 0
|
||||
PlayController.Progress.Max = 0
|
||||
PlayController.TotalTime.SetText("0:00")
|
||||
PlayController.CurrentTime.SetText("0:00")
|
||||
PlayController.Title.SetText("Title")
|
||||
PlayController.Artist.SetText("Artist")
|
||||
PlayController.Username.SetText("Username")
|
||||
|
||||
@@ -180,11 +180,6 @@ func registerCmdHandler() {
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Debugf("mpv command load file %s %s", mediaInfo.Title, mediaUrl.Url)
|
||||
if err := libmpv.Command([]string{"loadfile", mediaUrl.Url}); err != nil {
|
||||
log.Warn("[MPV PlayControl] mpv load media failed", mediaInfo)
|
||||
return
|
||||
}
|
||||
media := evnt.Data.(events.PlayerPlayCmdEvent).Media
|
||||
if m, err := miaosic.GetMediaInfo(media.Info.Meta); err == nil {
|
||||
media.Info = m
|
||||
@@ -193,6 +188,11 @@ func registerCmdHandler() {
|
||||
Media: media,
|
||||
Removed: false,
|
||||
})
|
||||
log.Debugf("mpv command load file %s %s", mediaInfo.Title, mediaUrl.Url)
|
||||
if err := libmpv.Command([]string{"loadfile", mediaUrl.Url}); err != nil {
|
||||
log.Warn("[MPV PlayControl] mpv load media failed", mediaInfo)
|
||||
return
|
||||
}
|
||||
})
|
||||
global.EventManager.RegisterA(events.PlayerToggleCmd, "player.toggle", func(evnt *event.Event) {
|
||||
property, err := libmpv.GetProperty("pause", mpv.FORMAT_FLAG)
|
||||
|
||||
@@ -15,6 +15,51 @@ type LogrusLogger struct {
|
||||
module string
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) DebugW(message string, keysAndValues ...interface{}) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) DebugS(message string, fields logger.LogField) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) InfoW(message string, keysAndValues ...interface{}) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) InfoS(message string, fields logger.LogField) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) WarnW(message string, keysAndValues ...interface{}) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) WarnS(message string, fields logger.LogField) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) ErrorW(message string, keysAndValues ...interface{}) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) ErrorS(message string, fields logger.LogField) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) WithPrefix(prefix string) logger.ILogger {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *LogrusLogger) SetLogLevel(level logger.LogLevel) {
|
||||
switch level {
|
||||
case logger.LogLevelDebug:
|
||||
|
||||
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"AynaLivePlayer/pkg/logger"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/virtuald/go-paniclog"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"time"
|
||||
@@ -98,7 +99,8 @@ func NewZapLogger() logger.ILogger {
|
||||
return &zapLoggerImpl{SugaredLogger: sugar}
|
||||
}
|
||||
|
||||
func NewZapColoredLogger() logger.ILogger {
|
||||
func NewZapColoredLogger(outPath string, redirectPanic bool) logger.ILogger {
|
||||
f, err := getLogOut(outPath, 5)
|
||||
cfg := zap.NewProductionEncoderConfig()
|
||||
level := zap.NewAtomicLevel()
|
||||
level.SetLevel(zapcore.DebugLevel)
|
||||
@@ -106,11 +108,30 @@ func NewZapColoredLogger() logger.ILogger {
|
||||
cfg.EncodeTime = syslogTimeEncoder
|
||||
cfg.EncodeName = customNamedEncoder
|
||||
cfg.ConsoleSeparator = " "
|
||||
zapLog := zap.New(zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(cfg),
|
||||
zapcore.AddSync(colorable.NewColorableStdout()),
|
||||
level,
|
||||
))
|
||||
var zapLog *zap.Logger
|
||||
if err == nil {
|
||||
zapLog = zap.New(
|
||||
zapcore.NewTee(zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(cfg),
|
||||
zapcore.AddSync(colorable.NewColorableStdout()),
|
||||
level),
|
||||
zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(cfg),
|
||||
zapcore.AddSync(f),
|
||||
level),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
zapLog = zap.New(
|
||||
zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(cfg),
|
||||
zapcore.AddSync(colorable.NewColorableStdout()),
|
||||
level),
|
||||
)
|
||||
}
|
||||
if redirectPanic {
|
||||
_, _ = paniclog.RedirectStderr(f)
|
||||
}
|
||||
sugar := zapLog.Sugar()
|
||||
return &zapLoggerImpl{SugaredLogger: sugar, level: level}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user