cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
243
Views
1
Helpful
5
Replies

PyATS: Cannot disable pyats log file from being created

assadniang
Level 1
Level 1

Hello,
Everytime the pyats connection gets executed, it creates a log file ([device]-cli-[timestamp].log in the script directory.

I cannot seem to disable it

I am running 25.7 version

    # Attempt to connect to the device
    try:
        LOGGER.info(f">>> Connecting to {device_name}...")
        device.connect(log_stdout=False)
        assert device.connected, f"Failed to connect to device {device_name}"
        LOGGER.info(f"Successfully connected to {device_name}\n")
        return device
    
    except (TimeoutError, StateMachineError, ConnectionError) as e:
        LOGGER.error(f"Failed to connect to {device_name}: {e}\n")
        return None
5 Replies 5

The log_stdout=False only disables stdout logging, not the CLI log files. You can disable this a few ways, via the connection params in yiour script, in your yaml test bed. You can also disable this globally with somethiong like 

import os
os.environ['PYATS_LOGS_DIR'] = '/dev/null'

Maybe look at the first two options in the params or yaml.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

@bigevilbeard 
There should be a better way of doing it rather than:

os.environ['PYATS_LOGS_DIR'] = '/dev/null'

I read the following documentation and could not find out where in the parameters or yaml file we can disable it
Connection Basics — Unicon Documentation
There is a LOGGING section, but it only shows how to redirect the log file

Thanks

Yes that is brute force method. So maybe the other options are no longer supported? Can you try adjusting the logging level of the pyats connections handler, try, something like ..

from pyats.connections import log

for handler in log.handlers:
    if isinstance(handler, logging.FileHandler):
        handler.setLevel(logging.CRITICAL)

#Your code below

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

assadniang
Level 1
Level 1

@bigevilbeard 
That did not work, as I got an error message
There were no specific about the error, just failed

BTW, this started happening after upgrading to the latest code 25.7
So they must have changed something in the code

Odd. I don’t see anything in the change log https://pubhub.devnetcloud.com/media/unicon/docs/changelog/2025/july.html

I would open an issue on the repo for this version. It would be odd to have an undocumented change.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io