Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Logging functions refactoring #315

Open
bocekm opened this issue Sep 13, 2017 · 3 comments
Open

Logging functions refactoring #315

bocekm opened this issue Sep 13, 2017 · 3 comments

Comments

@bocekm
Copy link
Collaborator

bocekm commented Sep 13, 2017

Currently, two functions in preupg/application.py needs to be called in order to make logging to file work: _add_debug_log_file and _add_report_log_file. There's also code changing what level of messages will be printed to STDOUT in preupg.application.py/Application.__init__().

Current logging functions:

  • log_warning .. this function is in module APIs, prints to STDERR, nothing else
  • log_message .. prints message to STDOUT and also to /var/log/preupgrade/preupg.log
  • logger_debug.{log,debug,error,..} .. prints message to STDOUT[*] and to /var/log/preupgrade/preupg.log
  • logger_report.{log,debug,error,..} .. prints message to STDOUT[*] and to /var/log/preupgrade/preupg-report.log

[*] The message is printed to STDOUT if the log level is above DEBUG. However, when --debug option is used, every message is printed to STDOUT.

This needs some refactoring:

  1. the functions should be smarter about where to be printing the output. For example printing ERROR level message to STDOUT is not appropriate, it should be printing to STDERR. However INFO level can be printed to STDOUT.
  2. create a function that prints the message only to a log file
@bocekm
Copy link
Collaborator Author

bocekm commented Sep 18, 2017

If needed 'log to file only' function without any changes to the current code, addition of this code to preupg/logger.py/LoggerHelper would do it:

@staticmethod
def log_to_file(logger, msg, level_str="debug"):		
    """Log message to file only."""		
    orig_handlers = logger.handlers		
    logger.handlers = []		
    for handler in orig_handlers:		
        if isinstance(handler, logging.FileHandler):		
            logger.handlers.append(handler)		
    level_num = getattr(logging, level_str.upper())		
    logger.log(level_num, msg)		
    logger.handlers = orig_handlers

@bocekm
Copy link
Collaborator Author

bocekm commented Sep 18, 2017

Also, add logging of exception messages to preupg/exception.py.

@AloisMahdal
Copy link
Collaborator

A good rule of thumb is, that if the purpose the command is to print something, then that something should go to stdout and everything else (anciliary output, or meta output) to stderr.

In this context, this means that log_message() should simply always log to stderr.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants