adjust errors and logger (#10)
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user