cdot65 / pan-os-upgrade

An efficient tool to execute configuration backups, network state snapshots, system readiness checks, and operating system upgrades of Palo Alto Networks firewalls and Panorama appliances.
https://cdot65.github.io/pan-os-upgrade/
Apache License 2.0
39 stars 7 forks source link

Duplicate Log Entries in Script Execution Due to Logger Propagation #46

Closed cdot65 closed 7 months ago

cdot65 commented 7 months ago

Issue Summary

In our script upgrade.py, we've observed that each log message appears twice in the console output. This issue seems to be related to Python's logging configuration, particularly the propagation of log messages to the root logger in addition to our script's custom logger.

Steps to Reproduce

Execute the upgrade.py script with any standard set of arguments. Observe the console output where each log message is duplicated.

Expected Behavior

Each log message should appear only once in the console output.

Actual Behavior

Each log message is duplicated, appearing twice consecutively in the console output.

Possible Cause

This duplication likely results from the logger's propagate attribute being set to True (default behavior), causing log messages to be handled by both the script's logger and the root logger.

Suggested Solution

Adjust the logger configuration in the configure_logging function by setting logger.propagate = False. This change should stop the log messages from being propagated to the root logger.

Additional Context

The issue was identified during routine script execution. Python's logging module is used for logging in the script. Example log output demonstrating the issue is attached for reference.

❯ docker run -v $(pwd)/assurance:/app/assurance -v $(pwd)/logs:/app/logs -it ghcr.io/cdot65/pan-os-upgrade:latest      
Hostname or IP: 192.168.255.41
Username: cdot
Password: 
Target PAN-OS version: 10.2.2
INFO:root:βœ… Connection to firewall established
INFO - βœ… Connection to firewall established
INFO:root:πŸ“ 007054000242051 Katy-fw1 192.168.255.41
INFO - πŸ“ 007054000242051 Katy-fw1 192.168.255.41
INFO:root:πŸ“ Firewall HA mode: active
INFO - πŸ“ Firewall HA mode: active
INFO:root:πŸ“ Current PAN-OS version: 11.0.0
INFO - πŸ“ Current PAN-OS version: 11.0.0
INFO:root:πŸ“ Target PAN-OS version: 10.2.2
INFO - πŸ“ Target PAN-OS version: 10.2.2
ERROR:root:❌ Upgrade is not required or a downgrade was attempted.
ERROR - ❌ Upgrade is not required or a downgrade was attempted.
ERROR:root:πŸ›‘ Halting script.
ERROR - πŸ›‘ Halting script.