canonical / juju-verify

https://launchpad.net/juju-verify
GNU General Public License v3.0
2 stars 7 forks source link

[logging] The DEBUG logging level setting does not work #141

Closed esunar closed 1 year ago

esunar commented 1 year ago

Option to set DEBUG mode, does not work properly.

$ juju-verify reboot --unit ceph-osd/0 -s -l debug
Connecting to currently active model.
Inferred charm for unit ceph-osd/0: ceph-osd
Initiating verifier instance of class: CephOsd
Running check reboot on units: ceph-osd/0
Checks:
[OK] check_affected_machines check passed
[WARN] ceph-osd/0 has units running on child machines: ceph-mon/0*
[FAIL] ceph-mon/1: Ceph cluster is unhealthy

There should be also this INFO message: Unit (ceph-mon/0): Ceph cluster health 'HEALTH_WARN too few PGs per OSD (8 < min 30)

I believed that problem is in this 1 part of code, where we set up logging level only for local logger.



Imported from Launchpad using lp2gh.

esunar commented 1 year ago

(by rgildein) What I expected is something like this.

$ juju-verify reboot --unit ceph-osd/0 -s -l debug
Connecting to currently active model.
Inferred charm for unit ceph-osd/0: ceph-osd
Initiating verifier instance of class: CephOsd
Running check reboot on units: ceph-osd/0
Unit (ceph-mon/0): Ceph cluster health 'HEALTH_WARN too few PGs per OSD (8 < min 30)
'
Checks:
[OK] check_affected_machines check passed
[WARN] ceph-osd/0 has units running on child machines: ceph-mon/0*
[FAIL] ceph-mon/0: Ceph cluster is unhealthy

Overall result: Failed

I also think that if I run juju-verify with -l DEBUG, then the log messages should contain time and level.

esunar commented 1 year ago

(by martin-kalcok) Root problem of this issue is that some modules in the juju_verify package do not initialise their loggers properly. Expected way is to create module-level object logger initialised with name of the module.

logger = logging.get_logger(__name__)

That way, this logger inherits configuration from the "top-level" logger [1] that is configured in juju_verify.config_logger() method [2]. However some modules initialise their logger like this:

logger = logging.get_logger()

And this approach creates loggers that hierarchically do not belong under the main "juju_verify" logger and do not inherit its configuration.

Note: as part of this issue resolution, a regression test should be created that checks modules in juju_verify package, collects "logger" objects from them (if present) and verifies that they inherit configuration from top-level logger.


[1] https://github.com/canonical/juju-verify/blob/18d5804ecde0ffbe02f4b4c60493c36ede84ad22/juju_verify/juju_verify.py#L36 [2] https://github.com/canonical/juju-verify/blob/18d5804ecde0ffbe02f4b4c60493c36ede84ad22/juju_verify/juju_verify.py#L158