"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
log: Add --log-format flag - fixes #2424
dcpuf4aaec9ce54a
diff --git a/docs/content/docs.md b/docs/content/docs.mdindex 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'slogs, then you should use the `copytruncate` option as rclone doesn'thave 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.goindex 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 levelvar 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 indiff --git a/fs/log/log.go b/fs/log/log.goindex 43814defe..d7219528f 100644--- a/fs/log/log.go+++ b/fs/log/log.go@@ -16,6 +16,7 @@ import (// Flagsvar (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 flagsfunc 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 outputif *logFile != "" {f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)