1

The following script:

#!/usr/bin/env python
from   fabric.api import env, run
import logging

logging.getLogger().setLevel(logging.INFO)

env.host_string = "%s@%s:%s" % ('myuser', 'myhost', '22')
res = run('date', pty = False)

Produces the following output:

[myuser@myhost:22] run: date
No handlers could be found for logger "ssh.transport"
[myuser@myhost:22] out: Thu Mar 29 16:15:15 CEST 2012

I would like to get rid of this annoying error message: No handlers could be found for logger "ssh.transport" The problem happens when setting the log level (setLevel).

How can I solve this? I need to set the log level, so skipping that won't help.

2 Answers 2

2

You need to initialize the logging system. You can make the error go away by doing so in your app thusly:

import logging
logging.basicConfig( level=logging.INFO )

Note: this uses the default Formatter, which is not terribly useful. You might consider something more like:

import logging
FORMAT="%(name)s %(funcName)s:%(lineno)d %(message)s"
logging.basicConfig(format=FORMAT, level=logging.INFO)
0

My hack is ugly but works:

# This is here to avoid the mysterious messages: 'No handlers could be found for logger "ssh.transport"'

class MyNullHandler(logging.Handler):
    def emit(self, record):
        pass

bugfix_loggers = { }
def bugfix(name):
    global bugfix_loggers
    if not name in bugfix_loggers:
        # print "Setting dummy logger for '%s'" % (name)
        logging.getLogger(name).addHandler(MyNullHandler())
        bugfix_loggers[name] = True

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.