未验证 提交 3490de46 编写于 作者: Z zyfjeff 提交者: GitHub

Optimized logging level by default only logging to syslog in daemon mode (#71)

* Optimized logging level by default only logging to syslog in daemon mode

* Fix review comments
上级 55e36dc0
......@@ -31,9 +31,7 @@ import (
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/object"
"github.com/juicedata/juicefs/pkg/redis"
"github.com/juicedata/juicefs/pkg/utils"
obj "github.com/juicedata/juicesync/object"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
......@@ -121,15 +119,7 @@ func test(store object.ObjectStorage) error {
}
func format(c *cli.Context) error {
if c.Bool("trace") {
utils.SetLogLevel(logrus.TraceLevel)
} else if c.Bool("debug") {
utils.SetLogLevel(logrus.DebugLevel)
} else if c.Bool("quiet") {
utils.SetLogLevel(logrus.ErrorLevel)
utils.InitLoggers(!c.Bool("nosyslog"))
}
setLoggerLevel(c)
if c.Args().Len() < 1 {
logger.Fatalf("Redis URL and name are required")
}
......
......@@ -17,6 +17,7 @@ package main
import (
"fmt"
"github.com/sirupsen/logrus"
"log"
_ "net/http/pprof"
"os"
......@@ -166,3 +167,13 @@ func stringContains(s []string, e string) bool {
}
return false
}
func setLoggerLevel(c *cli.Context) {
if c.Bool("trace") {
utils.SetLogLevel(logrus.TraceLevel)
} else if c.Bool("debug") {
utils.SetLogLevel(logrus.DebugLevel)
} else if c.Bool("quiet") {
utils.SetLogLevel(logrus.WarnLevel)
}
}
......@@ -37,7 +37,6 @@ import (
"github.com/juicedata/juicefs/pkg/redis"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
......@@ -80,14 +79,11 @@ func mount(c *cli.Context) error {
_ = agent.Listen(agent.Options{Addr: fmt.Sprintf("127.0.0.1:%d", port)})
}
}()
if c.Bool("trace") {
utils.SetLogLevel(logrus.TraceLevel)
} else if c.Bool("debug") {
utils.SetLogLevel(logrus.DebugLevel)
} else if c.Bool("quiet") {
utils.SetLogLevel(logrus.ErrorLevel)
setLoggerLevel(c)
if !c.Bool("nosyslog") {
// The default log to syslog is only in daemon mode.
utils.InitLoggers(c.Bool("d"))
}
utils.InitLoggers(!c.Bool("nosyslog") && !c.Bool("trace") && (c.Bool("background") || !c.Bool("debug")))
if c.Args().Len() < 1 {
logger.Fatalf("Redis URL and mountpoint are required")
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册