cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

Suppress Genie output when using in a script

Mike Assel
Enthusiast
Enthusiast

I'm playing around with using Genie in a python script. Whenever I do anything with Genie, like device.connect(), it prints the output to the console. How do I suppress that?  Thanks, Mike

1 ACCEPTED SOLUTION

Accepted Solutions

After further research, there are two other methods:

1) When you initially connect to a device, you can pass the argument dev.connect(log_stdout=False) to disable logging; this disable will be in-effect for the entire session until you re-enable it.

2) The device instance, after connection, provide a dev.log_user() method, which can be enabled/disabled passing True/False.

View solution in original post

8 REPLIES 8

Jeremy Schulman
Beginner
Beginner

Given a device instance, you can change the log settings via the connectionmgr instance. 

 

For example:

import logging

# dev is a Device instance from a testbed

dev.connectionmgr.log.setLevel(logging.ERROR)

# now execute a command and you will not see the output on the console
resp = dev.execute('show version')

# you can print the response
print(resp)

 

After further research, there are two other methods:

1) When you initially connect to a device, you can pass the argument dev.connect(log_stdout=False) to disable logging; this disable will be in-effect for the entire session until you re-enable it.

2) The device instance, after connection, provide a dev.log_user() method, which can be enabled/disabled passing True/False.

Thanks Jeremy! That did the trick. However when I use dev.connect(log_stdout=False) then the output is not logged to a file. A few follow up questions:

  1. How did you find dev.connect(log_stdout=False) ???? I did a lot of googling and NOTHING comes up (other than your blog post :)
  2. Assuming I can disable logging to the console but enable logging to a file, how would I specify the path?