Skip to content
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

[sonic-yang-mgmt] Adding flag to disable/enable log printing #9659

Merged
merged 7 commits into from
Jan 5, 2022

Conversation

ghooo
Copy link
Contributor

@ghooo ghooo commented Dec 29, 2021

Why I did it

Fixes sonic-net/sonic-utilities#1871

From generic-config-updater we call sonic-yang-mgmt multiple times in order to check a certain change to ConfigDb is valid or not. It is expected for some changes to be invalid, so always printing errors from sonic-yang-mgmt makes the output hard to read.

In this PR, we are adding a way to control if logs should be printed or not.

How I did it

  • Added print_log_enabled flag to sonic_yang ctor
  • Converted all print statements to sysLog(..., doPrint=True)

How to verify it

unit-test passing means the change did not break logs.

Info about libyang logging

libyang provides an extensive logging logic which can support a lot of scenarios:

  • ly_log_level: setting logging level
    • LY_LLERR
    • LY_LLWRN
    • ...
  • ly_set_log_clb: setting log callback to customize the default behavior which is printing the msgs
  • ly_log_options: setting logging options
    • LY_LOLOG: If callback is set use it, otherwise just print. If flag is not set, do nothing.
    • ...

For more info refer to:

What's next?

Consume the new flag print_log_enabled in generic-config-updater to reduce the logging clutter.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

@ghooo ghooo requested a review from lguohan as a code owner December 29, 2021 19:54
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding disable/enable logging methods [sonic-yang-mgmt] Adding logging_disabled flag to sonic_yang ctor Dec 29, 2021
@ghooo ghooo force-pushed the dev/mghoneim/sy_loging branch from 8f520ae to 42ad27c Compare December 29, 2021 21:54
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding logging_disabled flag to sonic_yang ctor [sonic-yang-mgmt] Adding enable/disable logging methods to sonic_yang Dec 29, 2021
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding enable/disable logging methods to sonic_yang [sonic-yang-mgmt] Adding logging_disabled flag to sonic_yang ctor Dec 29, 2021
@ghooo ghooo force-pushed the dev/mghoneim/sy_loging branch from 33043df to 42ad27c Compare December 29, 2021 22:01
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding logging_disabled flag to sonic_yang ctor [sonic-yang-mgmt] Adding enable_logging disable_logging methods to sonic_yang Dec 29, 2021
def sysLog(self, debug=syslog.LOG_INFO, msg=None, doPrint=False):
if self.syslogging_disabled:
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syslogging_disabled

The name is confusing, it actually disabled syslog and print. Your intention is to only disable print? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my intention is to disable logging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be hard to read the logs as well if we keep printing errors during a change validation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why it might be confusing, the name of the property syslogging_disabled but it is disabling it for both syslog and print. I got the name of the property from the name of the method sysLog.

Copy link
Contributor Author

@ghooo ghooo Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to print_log_enabled, and it only controls log printing

@ghooo ghooo changed the title [sonic-yang-mgmt] Adding enable_logging disable_logging methods to sonic_yang [sonic-yang-mgmt] Adding flag logging_disabled Dec 31, 2021
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding flag logging_disabled [sonic-yang-mgmt] Adding flag to control log printing Dec 31, 2021
@ghooo ghooo changed the title [sonic-yang-mgmt] Adding flag to control log printing [sonic-yang-mgmt] Adding flag to disable/enable log printing Dec 31, 2021
Copy link
Member

@praveen-li praveen-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, BTW I cannot recall why the name of argument is 'debug' in sysLog function. We can change it to 'level' or 'logLevel', if needed.
def sysLog(self, debug=syslog.LOG_INFO, msg=None, doPrint=False):

Approved, even if above is not addressed. Thx

@ghooo ghooo merged commit 98da6eb into sonic-net:master Jan 5, 2022
@ghooo
Copy link
Contributor Author

ghooo commented Jan 5, 2022

@praveen-li let me rename the flag in a separate PR, the build takes a very long time to finish and I have an ask I need to finish soon.

@qiluo-msft qiluo-msft added Request for 202111 Branch For PRs being requested for 202111 branch YANG YANG model related changes labels Jan 5, 2022
judyjoseph pushed a commit that referenced this pull request Jan 9, 2022
#### Why I did it
Fixes sonic-net/sonic-utilities#1871

From [generic-config-updater](https://github.com/Azure/sonic-utilities/tree/master/generic_config_updater) we call `sonic-yang-mgmt` multiple times in order to check a certain change to ConfigDb is valid or not. It is expected for some changes to be invalid, so always printing errors from `sonic-yang-mgmt` makes the output hard to read.

In this PR, we are adding a way to control if logs should be printed or not.

#### How I did it
- Added `print_log_enabled` flag to sonic_yang ctor
- Converted all `print` statements to `sysLog(..., doPrint=True)`

#### How to verify it
unit-test passing means the change did not break logs.

#### Info about libyang logging
libyang provides an extensive logging logic which can support a lot of scenarios:
- ly_log_level: setting logging level
  - LY_LLERR
  - LY_LLWRN
  - ... 
- ly_set_log_clb: setting log callback to customize the default behavior which is printing the msgs
- ly_log_options: setting logging options 
  - LY_LOLOG: If callback is set use it, otherwise just print. If flag is not set, do nothing.
  - ...

For more info refer to:
- https://netopeer.liberouter.org/doc/libyang/devel/html/group__logopts.html#gaff80501597ed76344a679be2b90a1d0a
- https://netopeer.liberouter.org/doc/libyang/devel/html/group__log.html#gac88b78694dfe9efe0450a69603f7eceb


#### What's next?
Consume the new flag `print_log_enabled` in [generic-config-updater](https://github.com/Azure/sonic-utilities/tree/master/generic_config_updater) to reduce the logging clutter. 

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 201811
- [ ] 201911
- [ ] 202006
- [ ] 202012
- [ ] 202106

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->


#### A picture of a cute animal (not mandatory but encouraged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Included in 202111 Branch Request for 202111 Branch For PRs being requested for 202111 branch YANG YANG model related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[generic-config-updater] Suppress sonic-yang-mgmt errors when sorting patch
4 participants