feat: it's configurable whether log caller

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2021-09-27 23:43:04 +08:00
parent cc5e8b7896
commit 21a1a7081b
2 changed files with 16 additions and 3 deletions
+5 -1
View File
@@ -52,7 +52,7 @@ func init() {
}
out := consoleEx.ConsoleWriterEx{Out: colorable.NewColorableStdout()}
logger := zerolog.New(out).With().Caller().Timestamp().Logger()
logger := zerolog.New(out).With().Timestamp().Logger()
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
logger = logger.Hook(logFile)
@@ -65,3 +65,7 @@ func init() {
func SetPath(path string) {
logFile.path = path
}
func Verbose() {
log.Logger = log.Logger.With().Caller().Logger()
}
+11 -2
View File
@@ -6,7 +6,7 @@ import (
"runtime"
"rttys/config"
rlog "rttys/log"
xlog "rttys/log"
"rttys/utils"
"rttys/version"
@@ -40,7 +40,11 @@ func initDb(cfg *config.Config) error {
}
func runRttys(c *cli.Context) {
rlog.SetPath(c.String("log"))
xlog.SetPath(c.String("log"))
if c.Bool("verbose") {
xlog.Verbose()
}
cfg := config.Parse(c)
@@ -157,6 +161,11 @@ func main() {
Name: "local-auth",
Usage: "need auth for local",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Usage: "more detailed output",
},
},
Action: func(c *cli.Context) error {
runRttys(c)