pyATS Log: Logging Format and Utilities
pyATS Log is a sub-component of the Cisco pyATS (Python Automated Test System) ecosystem, providing logging format and utilities. It configures the standard Python logging module to output in a Cisco log format, integral for network automation and testing workflows. The library is currently at version 26.3 and follows a frequent, often monthly or bi-monthly, release cadence as part of the broader pyATS framework.
Common errors
-
PyATS: Cannot disable pyats log file from being created
cause pyATS automatically generates log files for device interactions as part of its core functionality, which is not easily configurable to be disabled.fixThis is a known behavior of the pyATS framework. There is no direct configuration to completely disable these files. Implement post-execution cleanup scripts to remove unwanted log files or configure your `pyats run job` command to output to a specific, temporary directory that can be cleared. -
ModuleNotFoundError: No module named 'pyats.log.utils'
cause The `pyats-log` package or the broader `pyats` framework is either not installed, or the Python environment where the script is run does not have access to the installed package.fixEnsure `pyats` is installed in your active Python environment using `pip install pyats` (recommended for full functionality) or `pip install pyats-log` if you only need the logging component. Activate the correct virtual environment if one is being used. -
pyats logs view /path/to/my/syslog.log -> (empty browser window or parsing errors)
cause The `pyats logs view` command is intended for viewing logs generated by pyATS's internal execution engine, not for general syslog files or arbitrary text logs.fixOnly use `pyats logs view` for log archives created by `pyats run job`. For parsing network device syslog or debug outputs, leverage `Genie` parsers, which are part of the pyATS ecosystem, or write custom Python parsing logic.
Warnings
- gotcha pyATS and its sub-components, including `pyats-log`, officially support Python 3.8+ on Linux and Mac systems. Windows platforms are explicitly not supported, which can lead to unexpected behavior or installation failures.
- gotcha When running pyATS scripts, particularly those involving device connections, the framework automatically generates log files (e.g., `[device]-cli-[timestamp].log`) in the script directory. This behavior cannot always be easily disabled and might be unexpected, leading to numerous log files accumulating.
- breaking pyATS has ceased official support for Python 3.9. Projects still running on Python 3.9 will not receive updates or fixes and may encounter compatibility issues with newer pyATS versions.
- gotcha The `pyats logs view` CLI command is designed to view logs *generated by pyATS runs*, not for parsing arbitrary syslog files or general text log files. Attempting to use it on non-pyATS logs will often result in an empty display or parsing errors.
Install
-
pip install pyats-log -
pip install pyats
Imports
- logging
import logging
- banner
import pyats.log.utils.banner
from pyats.log.utils import banner
Quickstart
import logging
from pyats.log.utils import banner
# Get a logger instance; pyATS configures it to Cisco log format automatically
logger = logging.getLogger(__name__)
# Log some messages
logger.info('Starting a pyATS-driven task.')
logger.debug('Detailed debug information for troubleshooting.')
logger.warning('This is a warning that something might be off.')
logger.error('An error occurred during processing!')
# Use a pyATS log utility for visual separation
logger.info(banner('Task Completed'))