未验证 提交 029d9cd6 编写于 作者: D Davies Liu 提交者: GitHub

logging into file in background mode (#575)

* logging into file in background mode

* --logfile -> --log

* update docs
上级 26d848e8
......@@ -200,7 +200,7 @@ func mount(c *cli.Context) error {
}
// The default log to syslog is only in daemon mode.
utils.InitLoggers(!c.Bool("no-syslog"))
err := makeDaemon(conf.Format.Name, conf.Mountpoint)
err := makeDaemon(c, conf.Format.Name, conf.Mountpoint)
if err != nil {
logger.Fatalf("Failed to make daemon: %s", err)
}
......
......@@ -48,8 +48,9 @@ func checkMountpoint(name, mp string) {
logger.Fatalf("fail to mount after 10 seconds, please mount in foreground")
}
func makeDaemon(name, mp string) error {
onExit := func(stage int) error {
func makeDaemon(c *cli.Context, name, mp string) error {
var attrs godaemon.DaemonAttr
attrs.OnExit = func(stage int) error {
if stage != 0 {
return nil
}
......@@ -70,8 +71,14 @@ func makeDaemon(name, mp string) error {
}
}
}
var err error
logfile := c.String("logfile")
attrs.Stdout, err = os.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0755)
if err != nil {
logger.Errorf("open log file %s: %s", logfile, err)
}
}
_, _, err := godaemon.MakeDaemon(&godaemon.DaemonAttr{OnExit: onExit})
_, _, err := godaemon.MakeDaemon(&attrs)
return err
}
......@@ -86,6 +93,11 @@ func mount_flags() []cli.Flag {
Name: "no-syslog",
Usage: "disable syslog",
},
&cli.StringFlag{
Name: "log",
Value: "/var/log/juicefs.log",
Usage: "path of log file when running in background",
},
&cli.StringFlag{
Name: "o",
Usage: "other FUSE options",
......
......@@ -48,7 +48,7 @@ func mount_flags() []cli.Flag {
}
}
func makeDaemon(name, mp string) error {
func makeDaemon(c *cli.Context, name, mp string) error {
logger.Warnf("Cannot run in background in Windows.")
return nil
}
......
......@@ -164,6 +164,9 @@ run in background (default: false)
`--no-syslog`\
disable syslog (default: false)
`--log value`\
path of log file when running in background (default: /var/log/juicefs.log)
`-o value`\
other FUSE options (see [this document](fuse_mount_options.md) for more information)
......
......@@ -2,7 +2,7 @@
## Error Log
When JuiceFS run in background (through [`-d` option](command_reference.md#juicefs-mount) when mount volume), logs will output to syslog. Depending on your operating system, you can get the logs through different commands:
When JuiceFS run in background (through [`-d` option](command_reference.md#juicefs-mount) when mount volume), logs will output to syslog and /var/log/juicefs.log (v0.15+). Depending on your operating system, you can get the logs through different commands:
```bash
# macOS
......@@ -13,6 +13,9 @@ $ cat /var/log/syslog | grep 'juicefs'
# CentOS based system
$ cat /var/log/messages | grep 'juicefs'
# v0.15+
$ tail -n 100 /var/log/juicefs.log
```
There are 4 log levels. You can use the `grep` command to filter different levels of logs for performance analysis or troubleshooting:
......
......@@ -164,6 +164,9 @@ juicefs mount [command options] META-URL MOUNTPOINT
`--no-syslog`\
禁用系统日志 (默认: false)
`--log value`\
后台运行时日志文件的位置 (默认: /var/log/juicefs.log)
`-o value`\
其他 FUSE 选项 (参见[此文档](fuse_mount_options.md)来了解更多信息)
......
......@@ -2,7 +2,7 @@
## 错误日志
当 JuiceFS 通过 `-d` 选项在后台运行时,日志会输出到 syslog。取决于你使用的操作系统,你可以通过不同的命令获取日志:
当 JuiceFS 通过 `-d` 选项在后台运行时,日志会输出到系统日志和 /var/log/juicefs.log (v0.15+)。取决于你使用的操作系统,你可以通过不同的命令获取日志:
```bash
# macOS
......@@ -13,6 +13,9 @@ $ cat /var/log/syslog | grep 'juicefs'
# CentOS based system
$ cat /var/log/messages | grep 'juicefs'
# v0.15+
$ tail -n 100 /var/log/juicefs.log
```
日志等级有 4 种。你可以使用 `grep` 命令过滤显示不同等级的日志信息,从而进行性能统计和故障追踪。
......
......@@ -28,7 +28,7 @@ require (
github.com/huaweicloud/huaweicloud-sdk-go-obs v0.0.0-20190127152727-3a9e1f8023d5
github.com/hungys/go-lz4 v0.0.0-20170805124057-19ff7f07f099
github.com/jcmturner/gokrb5/v8 v8.4.2
github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236
github.com/juicedata/godaemon v0.0.0-20210629045518-3da5144a127d
github.com/juju/ratelimit v1.0.1
github.com/kr/fs v0.1.0 // indirect
github.com/ks3sdklib/aws-sdk-go v0.0.0-20180820074416-dafab05ad142
......
......@@ -373,6 +373,8 @@ github.com/juicedata/go-fuse/v2 v2.1.1-0.20210629082323-0ec79f5f0a45 h1:EKaeYSLT
github.com/juicedata/go-fuse/v2 v2.1.1-0.20210629082323-0ec79f5f0a45/go.mod h1:oRyA5eK+pvJyv5otpO/DgccS8y/RvYMaO00GgRLGryc=
github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236 h1:py4S1ZTRfz5hIvrhu83YSw7t0Z621+VrmmZBqSkQn5c=
github.com/juicedata/godaemon v0.0.0-20210118074000-659b6681b236/go.mod h1:dlxKkLh3qAIPtgr2U/RVzsZJDuXA1ffg+Njikfmhvgw=
github.com/juicedata/godaemon v0.0.0-20210629045518-3da5144a127d h1:kpQMvNZJKGY3PTt7OSoahYc4nM0HY67SvK0YyS0GLwA=
github.com/juicedata/godaemon v0.0.0-20210629045518-3da5144a127d/go.mod h1:dlxKkLh3qAIPtgr2U/RVzsZJDuXA1ffg+Njikfmhvgw=
github.com/juicedata/minio v0.0.0-20210222051636-e7cabdf948f4 h1:/Klbj2LgJnqWrVfK2RtsqNQm649uXi2diLc/2X3eis4=
github.com/juicedata/minio v0.0.0-20210222051636-e7cabdf948f4/go.mod h1:pQt7BggRNk3m4ZLGmtZ8ShrWe70RvyeXsHljoapikM0=
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册