From 099550fa34c82d85f95abffab23c244917ab32d8 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Fri, 9 Nov 2018 22:55:34 -0800 Subject: [PATCH] Improve logging by adding sensitive feature --- onionr/logger.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/onionr/logger.py b/onionr/logger.py index 1c299054..5adc0f3c 100644 --- a/onionr/logger.py +++ b/onionr/logger.py @@ -123,18 +123,18 @@ def get_file(): return _outputfile -def raw(data, fd = sys.stdout): +def raw(data, fd = sys.stdout, sensitive = False): ''' Outputs raw data to console without formatting ''' if get_settings() & OUTPUT_TO_CONSOLE: ts = fd.write('%s\n' % data) - if get_settings() & OUTPUT_TO_FILE: + if get_settings() & OUTPUT_TO_FILE and not sensitive: with open(_outputfile, "a+") as f: f.write(colors.filter(data) + '\n') -def log(prefix, data, color = '', timestamp=True, fd = sys.stdout, prompt = True): +def log(prefix, data, color = '', timestamp=True, fd = sys.stdout, prompt = True, sensitive = False): ''' Logs the data prefix : The prefix to the output @@ -149,7 +149,7 @@ def log(prefix, data, color = '', timestamp=True, fd = sys.stdout, prompt = True if not get_settings() & USE_ANSI: output = colors.filter(output) - raw(output, fd = fd) + raw(output, fd = fd, sensitive = sensitive) def readline(message = ''): ''' @@ -201,37 +201,37 @@ def confirm(default = 'y', message = 'Are you sure %s? '): return default == 'y' # debug: when there is info that could be useful for debugging purposes only -def debug(data, error = None, timestamp = True, prompt = True): +def debug(data, error = None, timestamp = True, prompt = True, sensitive = False): if get_level() <= LEVEL_DEBUG: - log('/', data, timestamp=timestamp, prompt = prompt) + log('/', data, timestamp=timestamp, prompt = prompt, sensitive = sensitive) if not error is None: debug('Error: ' + str(error) + parse_error()) # info: when there is something to notify the user of, such as the success of a process -def info(data, timestamp = False, prompt = True): +def info(data, timestamp = False, prompt = True, sensitive = False): if get_level() <= LEVEL_INFO: - log('+', data, colors.fg.green, timestamp = timestamp, prompt = prompt) + log('+', data, colors.fg.green, timestamp = timestamp, prompt = prompt, sensitive = sensitive) # warn: when there is a potential for something bad to happen -def warn(data, error = None, timestamp = True, prompt = True): +def warn(data, error = None, timestamp = True, prompt = True, sensitive = False): if not error is None: debug('Error: ' + str(error) + parse_error()) if get_level() <= LEVEL_WARN: - log('!', data, colors.fg.orange, timestamp = timestamp, prompt = prompt) + log('!', data, colors.fg.orange, timestamp = timestamp, prompt = prompt, sensitive = sensitive) # error: when only one function, module, or process of the program encountered a problem and must stop -def error(data, error = None, timestamp = True, prompt = True): +def error(data, error = None, timestamp = True, prompt = True, sensitive = False): if get_level() <= LEVEL_ERROR: - log('-', data, colors.fg.red, timestamp = timestamp, fd = sys.stderr, prompt = prompt) + log('-', data, colors.fg.red, timestamp = timestamp, fd = sys.stderr, prompt = prompt, sensitive = sensitive) if not error is None: debug('Error: ' + str(error) + parse_error()) # fatal: when the something so bad has happened that the program must stop -def fatal(data, error = None, timestamp=True, prompt = True): +def fatal(data, error = None, timestamp=True, prompt = True, sensitive = False): if not error is None: - debug('Error: ' + str(error) + parse_error()) + debug('Error: ' + str(error) + parse_error(), sensitive = sensitive) if get_level() <= LEVEL_FATAL: - log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp, fd = sys.stderr, prompt = prompt) + log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp = timestamp, fd = sys.stderr, prompt = prompt, sensitive = sensitive) # returns a formatted error message def parse_error():