From 752809309da9526858d3ea6469191c92e9076862 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:32:01 +0200 Subject: [PATCH] fs: add log Printf, Fatalf and Panicf --- fs/log.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/log.go b/fs/log.go index 0b6512b2f..5b591b4c1 100644 --- a/fs/log.go +++ b/fs/log.go @@ -154,12 +154,35 @@ func LogLevelPrintf(level LogLevel, o interface{}, text string, args ...interfac } } +// Panicf writes alert log output for this Object or Fs and calls panic(). +// It should always be seen by the user. +func Panicf(o interface{}, text string, args ...interface{}) { + if GetConfig(context.TODO()).LogLevel >= LogLevelAlert { + LogPrintf(LogLevelAlert, o, text, args...) + } + panic(fmt.Sprintf(text, args...)) +} + +// Fatalf writes critical log output for this Object or Fs and calls os.Exit(1). +// It should always be seen by the user. +func Fatalf(o interface{}, text string, args ...interface{}) { + if GetConfig(context.TODO()).LogLevel >= LogLevelCritical { + LogPrintf(LogLevelCritical, o, text, args...) + } + os.Exit(1) +} + // 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{}) { LogLevelPrintf(LogLevelError, o, text, args...) } +// Printf writes log output for this Object or Fs, same as Logf. +func Printf(o interface{}, text string, args ...interface{}) { + LogLevelPrintf(LogLevelNotice, o, text, args...) +} + // Logf writes log output for this Object or Fs. This should be // considered to be Notice level logging. It is the default level. // By default rclone should not log very much so only use this for