mirror of
https://github.com/rclone/rclone.git
synced 2025-08-17 17:11:37 +02:00
fs: deglobalise the config #4685
This is done by making fs.Config private and attaching it to the context instead. The Config should be obtained with fs.GetConfig and fs.AddConfig should be used to get a new mutable config that can be changed.
This commit is contained in:
15
fs/log.go
15
fs/log.go
@@ -1,6 +1,7 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
@@ -72,7 +73,7 @@ func (l *LogLevel) Type() string {
|
||||
// LogPrint sends the text to the logger of level
|
||||
var LogPrint = func(level LogLevel, text string) {
|
||||
var prefix string
|
||||
if Config.LogSystemdSupport {
|
||||
if GetConfig(context.TODO()).LogSystemdSupport {
|
||||
switch level {
|
||||
case LogLevelDebug:
|
||||
prefix = sysdjournald.DebugPrefix
|
||||
@@ -121,7 +122,7 @@ func (j LogValueItem) String() string {
|
||||
func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{}) {
|
||||
out := fmt.Sprintf(text, args...)
|
||||
|
||||
if Config.UseJSONLog {
|
||||
if GetConfig(context.TODO()).UseJSONLog {
|
||||
fields := logrus.Fields{}
|
||||
if o != nil {
|
||||
fields = logrus.Fields{
|
||||
@@ -158,7 +159,7 @@ func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{})
|
||||
|
||||
// LogLevelPrintf writes logs at the given level
|
||||
func LogLevelPrintf(level LogLevel, o interface{}, text string, args ...interface{}) {
|
||||
if Config.LogLevel >= level {
|
||||
if GetConfig(context.TODO()).LogLevel >= level {
|
||||
LogPrintf(level, o, text, args...)
|
||||
}
|
||||
}
|
||||
@@ -166,7 +167,7 @@ func LogLevelPrintf(level LogLevel, o interface{}, text string, args ...interfac
|
||||
// Errorf writes error log output for this Object or Fs. It
|
||||
// should always be seen by the user.
|
||||
func Errorf(o interface{}, text string, args ...interface{}) {
|
||||
if Config.LogLevel >= LogLevelError {
|
||||
if GetConfig(context.TODO()).LogLevel >= LogLevelError {
|
||||
LogPrintf(LogLevelError, o, text, args...)
|
||||
}
|
||||
}
|
||||
@@ -177,7 +178,7 @@ func Errorf(o interface{}, text string, args ...interface{}) {
|
||||
// important things the user should see. The user can filter these
|
||||
// out with the -q flag.
|
||||
func Logf(o interface{}, text string, args ...interface{}) {
|
||||
if Config.LogLevel >= LogLevelNotice {
|
||||
if GetConfig(context.TODO()).LogLevel >= LogLevelNotice {
|
||||
LogPrintf(LogLevelNotice, o, text, args...)
|
||||
}
|
||||
}
|
||||
@@ -186,7 +187,7 @@ func Logf(o interface{}, text string, args ...interface{}) {
|
||||
// level for logging transfers, deletions and things which should
|
||||
// appear with the -v flag.
|
||||
func Infof(o interface{}, text string, args ...interface{}) {
|
||||
if Config.LogLevel >= LogLevelInfo {
|
||||
if GetConfig(context.TODO()).LogLevel >= LogLevelInfo {
|
||||
LogPrintf(LogLevelInfo, o, text, args...)
|
||||
}
|
||||
}
|
||||
@@ -194,7 +195,7 @@ func Infof(o interface{}, text string, args ...interface{}) {
|
||||
// Debugf writes debugging output for this Object or Fs. Use this for
|
||||
// debug only. The user must have to specify -vv to see this.
|
||||
func Debugf(o interface{}, text string, args ...interface{}) {
|
||||
if Config.LogLevel >= LogLevelDebug {
|
||||
if GetConfig(context.TODO()).LogLevel >= LogLevelDebug {
|
||||
LogPrintf(LogLevelDebug, o, text, args...)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user