-
Notifications
You must be signed in to change notification settings - Fork 664
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
[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
import subprocess | ||
import yang as ly | ||
import copy | ||
import re | ||
from enum import Enum | ||
|
||
YANG_DIR = "/usr/local/yang-models" | ||
SYSLOG_IDENTIFIER = "GenericConfigUpdater" |
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 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.config_wrapper = config_wrapper if config_wrapper is not None else ConfigWrapper() | ||
self.patch_wrapper = patch_wrapper if patch_wrapper is not None else PatchWrapper() | ||
self.patchsorter = patchsorter if patchsorter is not None else PatchSorter(self.config_wrapper, self.patch_wrapper) | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, created a logger instance for the PatchApplier class
generic_config_updater/gu_common.py
Outdated
@@ -691,3 +693,44 @@ def _get_model(self, model, name): | |||
return submodel | |||
|
|||
return None | |||
|
|||
class GenericUpdaterLogger: |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global loggingSettings and then each logger instance is created per class, there is no global logger
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.
init_env(...)
will solve the user confusing issue I mentioned.
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.
@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() |
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.
generic_config_updater/gu_common.py
Outdated
@@ -691,3 +693,26 @@ def _get_model(self, model, name): | |||
return submodel | |||
|
|||
return None | |||
|
|||
class GenericUpdaterLogger(logger.Logger): | |||
def __init__(self, title, verbose): |
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.
generic_config_updater/gu_common.py
Outdated
@@ -691,3 +693,26 @@ def _get_model(self, model, name): | |||
return submodel | |||
|
|||
return None | |||
|
|||
class GenericUpdaterLogger(logger.Logger): |
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.
generic_config_updater/gu_common.py
Outdated
combined_msg = f"{self._title}: {msg}" | ||
super().log(priority, combined_msg, also_print_to_console) | ||
|
||
class LoggingSettings: |
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.
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: