2025, Oct 27 01:00
How to hide PyVISA DEBUG logs: disable all logging or silence only the 'pyvisa' logger in Python
Seeing DEBUG:pyvisa flood your console? Learn to suppress PyVISA DEBUG output via Python logging: disable all logs or raise the pyvisa logger level easily
When automating instruments over USB with PyVISA, the console can suddenly fill with lines like “DEBUG:pyvisa:…”. The application still works, but your own diagnostics get buried. The good news is that this is not PyVISA “printing”; it’s Python’s standard logging at work. Once you control logging, the noise disappears.
Example that triggers the noisy output
The following function drives a detector, selects gain and offset, sets a low-pass frequency, toggles a measurement function on and off, and then closes the session. The logic is intact, but names are changed for clarity.
def pmt_switch_test(gain_idx=0, offset_v=-0.009, lp_hz=80000000):
    gain_v = PMT1_gain_map['voltage'].iloc[int(gain_idx)]
    import pyvisa
    import time
    mgr = pyvisa.ResourceManager()
    dev = mgr.open_resource(pmt1_addr)
    dev.write("INST:SEL GAIN")
    dev.write("SOUR:VOLT %f" % gain_v)
    dev.write("INST:SEL OFFSET")
    dev.write("SOUR:VOLT %f" % offset_v)
    dev.write("SENS:FILT:LPAS:FREQ %f" % lp_hz)
    dev.write("SENS:FUNC:ON %s" % pmt_model)
    time.sleep(5)
    dev.write("SENS:FUNC:OFF %s" % pmt_model)
    mgr.close()
On systems where logging is configured at DEBUG level, creating the ResourceManager and issuing SCPI commands produces many lines prefixed with “DEBUG:pyvisa”.
What’s actually happening
The lines that look like “DEBUG:pyvisa:…” come from the standard Python logging module. PyVISA emits DEBUG-level logs; if your process configures logging at DEBUG, you’ll see them. If logging is not configured at DEBUG, you won’t. This is why toggling the logging level changes whether those lines appear.
Two practical ways to silence the flood
If you just need the console quiet, you can disable logging entirely. If you prefer to keep your own logs while hiding only PyVISA’s internals, target the logger named “pyvisa”. Both approaches are shown below.
Option 1: shut off all logging
import pyvisa
import logging
# Any prior logging setup can remain; this call mutes everything
logging.disable()
rm = pyvisa.ResourceManager()       # No PyVISA DEBUG lines appear
print(rm.list_resources())          # Still quiet
Option 2: keep your logs, hide PyVISA’s
This setup keeps your own DEBUG and INFO messages while suppressing PyVISA’s DEBUG chatter by raising the “pyvisa” logger’s level.
import pyvisa
import logging
# Enable application-level logging
logging.basicConfig(level=logging.DEBUG)
# Target only PyVISA's logger
pyvisa_logger = logging.getLogger('pyvisa')
pyvisa_logger.level = logging.INFO
logging.debug('app debug visible')   # You will see this
logging.info('app info visible')     # You will see this
rm = pyvisa.ResourceManager()        # PyVISA DEBUG lines are hidden
print(rm.list_resources())           # PyVISA DEBUG remains hidden
Applying it to the device control code
Here is the detector routine again with the targeted logging configuration in place, so your application logs remain readable while PyVISA’s DEBUG output is suppressed.
import logging
import pyvisa
import time
# Keep your own logs; hide PyVISA's DEBUG
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('pyvisa').level = logging.INFO
def pmt_switch_test(gain_idx=0, offset_v=-0.009, lp_hz=80000000):
    gain_v = PMT1_gain_map['voltage'].iloc[int(gain_idx)]
    mgr = pyvisa.ResourceManager()
    dev = mgr.open_resource(pmt1_addr)
    dev.write("INST:SEL GAIN")
    dev.write("SOUR:VOLT %f" % gain_v)
    dev.write("INST:SEL OFFSET")
    dev.write("SOUR:VOLT %f" % offset_v)
    dev.write("SENS:FILT:LPAS:FREQ %f" % lp_hz)
    dev.write("SENS:FUNC:ON %s" % pmt_model)
    time.sleep(5)
    dev.write("SENS:FUNC:OFF %s" % pmt_model)
    mgr.close()
Why this is worth knowing
Understanding that these lines are standard logging output, not arbitrary prints, gives you precise control. You can silence third-party libraries without losing your own diagnostics, and you can re-enable deep traces only when you need them. It’s a simple lever that restores signal-to-noise in console-driven workflows.
Takeaways
If your console shows “DEBUG:pyvisa:…” lines, it’s Python logging at DEBUG level. If you want everything quiet, call logging.disable(). If you want only PyVISA quiet, set logging.getLogger('pyvisa').level to INFO or higher. Keep your device code unchanged; just configure logging appropriately before creating the ResourceManager or talking to the instrument.