adjust errors and logger (#10)

This commit is contained in:
Sarv
2025-04-01 19:41:40 +08:00
committed by GitHub
parent f31953c42b
commit 167a9ca873
49 changed files with 553 additions and 981 deletions

View File

@@ -6,7 +6,7 @@ import (
"github.com/sjzar/chatlog/internal/chatlog"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@@ -33,11 +33,11 @@ var decryptCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
m, err := chatlog.New("")
if err != nil {
log.Error(err)
log.Err(err).Msg("failed to create chatlog instance")
return
}
if err := m.CommandDecrypt(dataDir, workDir, key, decryptPlatform, decryptVer); err != nil {
log.Error(err)
log.Err(err).Msg("failed to decrypt")
return
}
fmt.Println("decrypt success")

View File

@@ -5,7 +5,7 @@ import (
"github.com/sjzar/chatlog/internal/chatlog"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@@ -21,12 +21,12 @@ var keyCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
m, err := chatlog.New("")
if err != nil {
log.Error(err)
log.Err(err).Msg("failed to create chatlog instance")
return
}
ret, err := m.CommandKey(pid)
if err != nil {
log.Error(err)
log.Err(err).Msg("failed to get key")
return
}
fmt.Println(ret)

View File

@@ -1,33 +1,26 @@
package chatlog
import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"runtime"
"time"
"github.com/sjzar/chatlog/pkg/util"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var Debug bool
func initLog(cmd *cobra.Command, args []string) {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
_, filename := path.Split(f.File)
return "", fmt.Sprintf("%s:%d", filename, f.Line)
},
})
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if Debug {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
}
@@ -43,8 +36,8 @@ func initTuiLog(cmd *cobra.Command, args []string) {
panic(err)
}
logOutput = logFD
log.SetReportCaller(true)
}
log.SetOutput(logOutput)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: logOutput, NoColor: true, TimeFormat: time.RFC3339})
logrus.SetOutput(logOutput)
}

View File

@@ -3,7 +3,7 @@ package chatlog
import (
"github.com/sjzar/chatlog/internal/chatlog"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
@@ -17,7 +17,7 @@ func init() {
func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Error(err)
log.Err(err).Msg("command execution failed")
}
}
@@ -38,11 +38,11 @@ func Root(cmd *cobra.Command, args []string) {
m, err := chatlog.New("")
if err != nil {
log.Error(err)
log.Err(err).Msg("failed to create chatlog instance")
return
}
if err := m.Run(); err != nil {
log.Error(err)
log.Err(err).Msg("failed to run chatlog instance")
}
}