diff --git a/CHANGES b/CHANGES index 127185910..4177e0386 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ Upcoming Release * GUI change: Remove Exit button from the toolbar (#172) * GUI change: Define accelerator keys for menu bar and tabs, as well as toolbar shortcuts (#1104) * Desktop integration: Update .desktop file to mark Back In Time as a single main window program (#1258) +* Improvement: Write all log output to stderr; do not pollute stdout with INFO and WARNING messages anymore (#1337) * Bugfix: AttributeError in "Diff Options" dialog (#898) * Bugfix: Settings GUI: "Save password to Keyring" was disabled due to "no appropriate keyring found" (#1321) * Bugfix: Back in Time did not start with D-Bus error diff --git a/common/logger.py b/common/logger.py index 55e7e1dc1..0be94c388 100644 --- a/common/logger.py +++ b/common/logger.py @@ -23,8 +23,8 @@ import tools import bcolors -DEBUG = False -APP_NAME = 'backintime' +DEBUG = False # Set to "True" when passing "--debug" as cmd arg +APP_NAME = 'backintime' # TODO Duplicated code (see Config.APP_NAME) def openlog(): name = os.getenv('LOGNAME', 'unknown') @@ -55,14 +55,16 @@ def warning(msg , parent = None, traceDepth = 0): def info(msg , parent = None, traceDepth = 0): if DEBUG: msg = '%s %s' %(_debugHeader(parent, traceDepth), msg) - print('%sINFO%s: %s' %(bcolors.OKGREEN, bcolors.ENDC, msg), file=sys.stdout) + print('%sINFO%s: %s' %(bcolors.OKGREEN, bcolors.ENDC, msg), file=sys.stderr) for line in tools.wrapLine(msg): syslog.syslog(syslog.LOG_INFO, 'INFO: ' + line) def debug(msg, parent = None, traceDepth = 0): if DEBUG: msg = '%s %s' %(_debugHeader(parent, traceDepth), msg) - print('%sDEBUG%s: %s' %(bcolors.OKBLUE, bcolors.ENDC, msg), file = sys.stdout) + # Why does this code differ from eg. "error()" + # (where the following lines are NOT part of the "if")? + print('%sDEBUG%s: %s' %(bcolors.OKBLUE, bcolors.ENDC, msg), file=sys.stderr) for line in tools.wrapLine(msg): syslog.syslog(syslog.LOG_DEBUG, 'DEBUG: %s' %line) diff --git a/common/test/test_backintime.py b/common/test/test_backintime.py index 94f8a5d75..7145ee29a 100644 --- a/common/test/test_backintime.py +++ b/common/test/test_backintime.py @@ -127,14 +127,17 @@ def test_local_snapshot_is_successful(self): Back In Time comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; type `backintime --license' for details. +''', re.MULTILINE)) -INFO: Lock + # The log output completely goes to stderr + self.assertRegex(error.decode(), re.compile(r'''INFO: Lock INFO: Take a new snapshot. Profile: 1 Main profile INFO: Call rsync to take the snapshot INFO: Save config file INFO: Save permissions INFO: Create info file -INFO: Unlock''', re.MULTILINE)) +INFO: Unlock +''', re.MULTILINE)) # get snapshot id subprocess.check_output(["./backintime", @@ -167,8 +170,11 @@ def test_local_snapshot_is_successful(self): This is free software, and you are welcome to redistribute it under certain conditions; type `backintime --license' for details. +''', re.MULTILINE)) -INFO: Restore: /tmp/test/testfile to: /tmp/restored.*''', re.MULTILINE)) + # The log output completely goes to stderr + self.assertRegex(error.decode(), re.compile(r'''INFO: Restore: /tmp/test/testfile to: /tmp/restored.*''', + re.MULTILINE)) # verify that files restored are the same as those backed up subprocess.check_output(["diff",