Commit 14875a2a authored by Martin Matějek's avatar Martin Matějek

fixup! Remove logging to file, use stderr/out instead

parent f85f0f2e
......@@ -25,10 +25,8 @@ COLORS = {
'default': '\033[39m',
}
# TODO: get these levels programatically somehow?
LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
LOGLEVEL = 'INFO'
root_logger = logging.getLogger()
logger = logging.getLogger('cliapp')
......@@ -36,7 +34,7 @@ def create_argparser():
"""Create new argument parser"""
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", help="Specify config file")
parser.add_argument("--log-level", help="Specify log level", nargs="?", choices=LOG_LEVELS, default="INFO")
parser.add_argument("--debug", help="More verbose output", action="store_true")
subparsers = parser.add_subparsers(help="sub-command help", dest='command')
subparsers.required = True
......@@ -100,35 +98,17 @@ def print_notification(notification):
# work-in-progress!
def setup_logging(loglevel):
root_logger.setLevel(loglevel)
formatter = logging.Formatter('%(message)s')
handler_lib_stderr = logging.StreamHandler(sys.stderr)
handler_lib_stderr.setFormatter(formatter)
# TODO: use loglevel here?
handler_lib_stderr.setLevel(logging.WARNING)
root_logger.addHandler(handler_lib_stderr)
# CLI app logger
# Level Info and below go to stdout, others go to stderr
handler_stdout = logging.StreamHandler(sys.stdout)
handler_stdout.setFormatter(formatter)
handler_stdout.setLevel(logging.INFO)
handler_stdout.addFilter(lambda record: record.levelno <= logging.INFO)
logger.addHandler(handler_stdout)
handler_stderr = logging.StreamHandler(sys.stderr)
handler_stderr.setFormatter(formatter)
handler_stderr.setLevel(logging.WARNING)
logger.addHandler(handler_stderr)
def setup_logging(loglevel=logging.INFO):
logging.basicConfig(level=loglevel, format='%(message)s')
logger.setLevel(loglevel)
def process_args(parser, args):
"""Call module interface based on args"""
setup_logging(args.log_level)
if args.debug:
setup_logging(logging.DEBUG)
else:
setup_logging()
if args.config:
api = Api(os.path.abspath(args.config))
......
......@@ -144,8 +144,6 @@ class NotificationStorage:
filepath = os.path.join(storage_dir, "{}.json".format(msgid))
tmp_filepath = "{}.tmp".format(filepath)
# TODO: figure out how to pass what exactly failed to user
try:
os.rename(filepath, tmp_filepath)
except FileNotFoundError as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment