-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write all log output to stderr (do not pollute stdout) #1337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is irritating to me is that DEBUG is not a severity threshold for logging but a flag to inject additional call stack information ("_debugHeader") but for a single severity level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we misunderstand here each other? e.g. in Python's own |
||
# (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) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would revert that if.
In that case you can save the indention of the following lines.
Clearer code IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Yes, would be possible, but why change existing code that works ;-)