cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
939
Views
10
Helpful
5
Replies
Highlighted
Enthusiast

Suppress Genie output when using in a script

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
Highlighted

Re: Suppress Genie output when using in a script

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

5 REPLIES 5
Highlighted

Re: Suppress Genie output when using in a script

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)

 

Highlighted

Re: Suppress Genie output when using in a script

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

Highlighted
Enthusiast

Re: Suppress Genie output when using in a script

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?
Highlighted

Re: Suppress Genie output when using in a script

Hi @Mike Assel,

 

re: connect(log_stdout=False) I learned via a response on Twitter from one of the DevNet genie developers.  After I learned this, I did a scan of the sourcecode and I could not find any reference to this Device() argument either.  Seem like an opportunity for the DevNet team to add more documentation.

 

re: logging - even though the console logging is disabled, there is still a logfile.  You can find it using the Device.logfile attribute, for example:

 

In [11]: dev.logfile
Out[11]: '/tmp/atlrs21-cli-20191021T024126194.log'

I have not experimented with changing the logfile value.

 

Hope this helps!

Highlighted
Enthusiast

Re: Suppress Genie output when using in a script

My bad. I had checked and thought I did not see a log file, but I checked again and indeed it was there. Thanks for the help.

This widget could not be displayed.