Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

log: Add --log-format flag - fixes #2424

dcpuf4aaec9ce54a
diff --git a/docs/content/docs.md b/docs/content/docs.md
index c7e9df186..ebf9e2b1a 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -549,6 +549,10 @@ Note that if you are using the `logrotate` program to manage rclone's
logs, then you should use the `copytruncate` option as rclone doesn't
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`".
+
### --log-level LEVEL ###
This sets the log level for rclone. The default log level is `NOTICE`.
diff --git a/fs/log.go b/fs/log.go
index 94f61b9a0..83d6a6f5a 100644
--- a/fs/log.go
+++ b/fs/log.go
@@ -70,7 +70,7 @@ func (l *LogLevel) Type() string {
// LogPrint sends the text to the logger of level
var LogPrint = func(level LogLevel, text string) {
text = fmt.Sprintf("%-6s: %s", level, text)
- log.Print(text)
+ _ = log.Output(4, text)
}
// LogPrintf produces a log string from the arguments passed in
diff --git a/fs/log/log.go b/fs/log/log.go
index 43814defe..d7219528f 100644
--- a/fs/log/log.go
+++ b/fs/log/log.go
@@ -16,6 +16,7 @@ import (
// Flags
var (
logFile = flags.StringP("log-file", "", "", "Log everything to this file")
+ logFormat = flags.StringP("log-format", "", "date,time", "Comma separated list of log format options")
useSyslog = flags.BoolP("syslog", "", false, "Use Syslog for logging")
syslogFacility = flags.StringP("syslog-facility", "", "DAEMON", "Facility for syslog, eg KERN,USER,...")
)
@@ -66,6 +67,28 @@ func Trace(o interface{}, format string, a ...interface{}) func(string, ...inter
// InitLogging start the logging as per the command line flags
func InitLogging() {
+ flagsStr := "," + *logFormat + ","
+ var flags int
+ if strings.Contains(flagsStr, ",date,") {
+ flags |= log.Ldate
+ }
+ if strings.Contains(flagsStr, ",time,") {
+ flags |= log.Ltime
+ }
+ if strings.Contains(flagsStr, ",microseconds,") {
+ flags |= log.Lmicroseconds
+ }
+ if strings.Contains(flagsStr, ",longfile,") {
+ flags |= log.Llongfile
+ }
+ if strings.Contains(flagsStr, ",shortfile,") {
+ flags |= log.Lshortfile
+ }
+ if strings.Contains(flagsStr, ",UTC,") {
+ flags |= log.LUTC
+ }
+ log.SetFlags(flags)
+
// Log file output
if *logFile != "" {
f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)