mirror of
https://github.com/rclone/rclone
synced 2024-09-06 00:08:57 +02:00
log: optionally print pid in logs - #5593
This option is useful to troubleshoot `rclone mount --daemon`
This commit is contained in:
parent
fbc7f2e61b
commit
68be24c88d
@ -1024,7 +1024,7 @@ have a signal to rotate logs.
|
||||
|
||||
### --log-format LIST ###
|
||||
|
||||
Comma separated list of log format options. `date`, `time`, `microseconds`, `longfile`, `shortfile`, `UTC`. The default is "`date`,`time`".
|
||||
Comma separated list of log format options. Accepted options are `date`, `time`, `microseconds`, `pid`, `longfile`, `shortfile`, `UTC`. Any other keywords will be silently ignored. `pid` will tag log messages with process identifier which useful with `rclone mount --daemon`. Other accepted options are explained in the [go documentation](https://pkg.go.dev/log#pkg-constants). The default log format is "`date`,`time`".
|
||||
|
||||
### --log-level LEVEL ###
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -80,9 +81,15 @@ func (l *LogLevel) UnmarshalJSON(in []byte) error {
|
||||
})
|
||||
}
|
||||
|
||||
// LogPrintPid enables process pid in log
|
||||
var LogPrintPid = false
|
||||
|
||||
// LogPrint sends the text to the logger of level
|
||||
var LogPrint = func(level LogLevel, text string) {
|
||||
text = fmt.Sprintf("%-6s: %s", level, text)
|
||||
if LogPrintPid {
|
||||
text = fmt.Sprintf("[%d] %s", os.Getpid(), text)
|
||||
}
|
||||
_ = log.Output(4, text)
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,8 @@ func InitLogging() {
|
||||
}
|
||||
log.SetFlags(flags)
|
||||
|
||||
fs.LogPrintPid = strings.Contains(flagsStr, ",pid,")
|
||||
|
||||
// Log file output
|
||||
if Opt.File != "" {
|
||||
f, err := os.OpenFile(Opt.File, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
|
||||
|
Loading…
Reference in New Issue
Block a user