-
Notifications
You must be signed in to change notification settings - Fork 70
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
Unify logger.conf and the fallback code #616
base: main
Are you sure you want to change the base?
Conversation
bocekm
commented
Mar 10, 2020
•
edited
Loading
edited
- use logging.Formatter.converter = time.gmtime for both the file config and fallback config to have the same (UTC) time, in both cases
- unify log levels, using the fallback as the ones to use also in the conf file
Can one of the admins verify this patch? |
- use logging.Formatter.converter = time.gmtime for both the file config and fallback config to have the same (UTC) time, in both cases - unify log levels
Thank you for contributing to the Leapp project!Please note that every PR needs to comply with the Leapp Guidelines, pass tests and linter checks before it can be merged. If you want to re-run tests or request review, you can use following commands as a comment:
|
@@ -151,7 +151,8 @@ def run(args, split=False, callback_raw=_console_logging_handler, callback_lineb | |||
""" | |||
Run a command and return its result as a dict. | |||
|
|||
The execution of the program and it's results are captured by the audit. | |||
The execution of the command and its result is captured by the audit. The CalledProcessError is raised when |
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.
there is a special docstring syntax for the definition of what being raised:
@@ -151,8 +151,7 @@ def run(args, split=False, callback_raw=_console_logging_handler, callback_lineb
"""
Run a command and return its result as a dict.
- The execution of the command and its result is captured by the audit. The CalledProcessError is raised when
- the command exits with non-zero code.
+ The execution of the command and its result is captured by the audit.
:param args: Command to execute
:type args: list or tuple
@@ -168,6 +167,8 @@ def run(args, split=False, callback_raw=_console_logging_handler, callback_lineb
:type stdin: int, str
:return: {'stdout' : stdout, 'stderr': stderr, 'signal': signal, 'exit_code': exit_code, 'pid': pid}
:rtype: dict
+ :raises:
+ CalledProcessError: if the command exits with non-zero status
"""
if not args:
message = 'Command to call is missing.'
datefmt=log_date_format, | ||
stream=sys.stderr, | ||
) | ||
stderr_handler = logging.StreamHandler(sys.stderr) |
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.
No need to put sys.stderr, it is by default
global _logger | ||
if not _logger: | ||
""" | ||
Configure loggers as per the description below. |
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.
Should be on the same line with """ (https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings)
log_format = '%(asctime)s.%(msecs)-3d %(levelname)-8s PID: %(process)d %(name)s: %(message)s' | ||
log_date_format = '%Y-%m-%d %H:%M:%S' | ||
path = os.getenv('LEAPP_LOGGER_CONFIG', '/etc/leapp/logger.conf') | ||
logging.Formatter.converter = time.gmtime |
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.
Please don't do this. This is a global state of all loggers. What about the one from the cookbook? (https://docs.python.org/3/howto/logging-cookbook.html#formatting-times-using-utc-gmt-via-configuration)
this could be solved something similar to:
diff --git a/etc/leapp/logger.conf b/etc/leapp/logger.conf
index ee1cf91..66102c4 100644
--- a/etc/leapp/logger.conf
+++ b/etc/leapp/logger.conf
@@ -10,7 +10,7 @@ keys=leapp_audit,stream
[formatter_leapp]
format=%(asctime)s.%(msecs)-3d %(levelname)-8s PID: %(process)d %(name)s: %(message)s
datefmt=%Y-%m-%d %H:%M:%S
-class=logging.Formatter
+class=leapp.logger.UTCFormatter
[logger_urllib3]
level=WARN
global _leapp_logger | ||
if not _leapp_logger: | ||
_leapp_logger = logging.getLogger('leapp') | ||
|
||
log_format = '%(asctime)s.%(msecs)-3d %(levelname)-8s PID: %(process)d %(name)s: %(message)s' |
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 think fo ruser would be convininent to see that this time is UTC time
log_format = '%(asctime)s.%(msecs)-3d %(levelname)-8s PID: %(process)d %(name)s: %(message)s' | |
log_format = '%(asctime)s.%(msecs)-3d UTC %(levelname)-8s PID: %(process)d %(name)s: %(message)s' |
In case of docstring, quotes should be used always, officialy. Replace apostrophes by quotes in case of docstrings.
@oamg/developers Do we still want this? I'd rather close and reopen on demand. |