[generic_config_updater] Logging#1864
Conversation
|
This pull request introduces 5 alerts when merging b56fbde0b7b5bac8e7056ceb1ee80260c823bd3d into d13955a - view on LGTM.com new alerts:
|
b56fbde to
82b53eb
Compare
82b53eb to
a35081b
Compare
| from enum import Enum | ||
|
|
||
| YANG_DIR = "/usr/local/yang-models" | ||
| SYSLOG_IDENTIFIER = "GenericConfigUpdater" |
There was a problem hiding this comment.
Here is how it look like:
Oct 11 18:15:50.604939 vlab-01 INFO GenericConfigUpdater: Patch Applier: Getting current config db.
Oct 11 18:15:51.494117 vlab-01 INFO GenericConfigUpdater: Patch Applier: Simulating the target full config after applying the patch.
Oct 11 18:15:51.502449 vlab-01 INFO GenericConfigUpdater: Patch Applier: Validating target config according to YANG models.
I think it is OK, this way I can grep all syslogs associated with GenericConfigUpdater i.e. cat /var/log/syslog | grep GenericConfigUpdater
I think we will add more logs to other parts such config replace, rollback checkpoint and the applier.
There was a problem hiding this comment.
Also I don't think we should use config since this library might be used with REST APIs like was requested in some of the earlier meetings with SONiC Community
| self.changeapplier = changeapplier if changeapplier is not None else ChangeApplier() | ||
|
|
||
| def apply(self, patch): | ||
| logger.log_info(self.LOGTITLE, "Patch application starting.") |
There was a problem hiding this comment.
This way makes it easier to add new log msgs, I don't have to create a new instance of logger for each class.
There was a problem hiding this comment.
nvm, created a logger instance for the PatchApplier class
generic_config_updater/gu_common.py
Outdated
|
|
||
| return None | ||
|
|
||
| class GenericUpdaterLogger: |
There was a problem hiding this comment.
This class seems have general value, like https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-py-common/sonic_py_common/logger.py.
Is it better to enhance existing Logger class? If something is impossible, we can inherit the class. #Closed
There was a problem hiding this comment.
used sonic-py-common logger
generic_config_updater/gu_common.py
Outdated
| Console settings: log levels [error, warning, info] always printed, [debug] only printed if verbose logging | ||
| Syslog settings: log all levels [error, warning, info, debug] | ||
| """ | ||
| def init_verbose_logging(self, verbose): |
There was a problem hiding this comment.
if I use __init__ it means when creating the logger I initialize verbose, but this is not the case as we modify verbosity later.
There was a problem hiding this comment.
used loggingSettings instead and the logger is created from loggingSettings.getlogger
generic_config_updater/gu_common.py
Outdated
| def _log_to_console(self, msg, logLevel): | ||
| # Always log [warning, error, info] i.e. not debug, but if verbose logging print debug as well | ||
| if logLevel < syslog.LOG_DEBUG or self.enable_verbose_logging: | ||
| print(msg) |
There was a problem hiding this comment.
used common logger logic
generic_config_updater/gu_common.py
Outdated
| syslog.syslog(logLevel, msg) | ||
| syslog.closelog() | ||
|
|
||
| logger = GenericUpdaterLogger() |
There was a problem hiding this comment.
The idea is to have a single global logger in gu_common for which verbosity can be modified.
Another idea is to create an init_env(...) method in gu_common and this function takes care of creating the logger.
There was a problem hiding this comment.
global loggingSettings and then each logger instance is created per class, there is no global logger
There was a problem hiding this comment.
init_env(...) will solve the user confusing issue I mentioned.
There was a problem hiding this comment.
@qiluo-msft I have used loggingSettings instead, there the verbose flag can change, but then once a logger is created its verbosity can not change. Do you think this is confusing?
10fd12d to
0789414
Compare
0789414 to
ad29105
Compare
generic_config_updater/gu_common.py
Outdated
| def getLogger(self, title): | ||
| return GenericUpdaterLogger(title, self._verbose) | ||
|
|
||
| loggingSettings = LoggingSettings() |
generic_config_updater/gu_common.py
Outdated
| return None | ||
|
|
||
| class GenericUpdaterLogger(logger.Logger): | ||
| def __init__(self, title, verbose): |
generic_config_updater/gu_common.py
Outdated
|
|
||
| return None | ||
|
|
||
| class GenericUpdaterLogger(logger.Logger): |
generic_config_updater/gu_common.py
Outdated
| combined_msg = f"{self._title}: {msg}" | ||
| super().log(priority, combined_msg, also_print_to_console) | ||
|
|
||
| class LoggingSettings: |
ab35ee6 to
4539f6b
Compare
What I did
Add some logs to generic_updater
How I did it
How to verify it
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)
Empty patch
Single change patch
Multi change patch: