Teradata / PyTd

A Python Module to make it easy to script powerful interactions with Teradata Database in a DevOps friendly way.
MIT License
108 stars 43 forks source link

No handlers could be found for logger "teradata.tdodbc" #23

Closed padhia closed 8 years ago

padhia commented 8 years ago

My setup is Windows 7, Python 2.7.10, and the latest (version 15.10.0.11) teradata package installed using pip.

Consider following simple code

#! /usr/bin/env python

from __future__ import (absolute_import, division, print_function, unicode_literals)
from teradata.tdodbc import *

cnx = connect(system='mytd', username='xxxx', password='xxxx', transactionMode='Teradata')
csr = cnx.cursor()

csr.execute('select * from dbc.dbcinfov')

print([list(r) for r in csr.fetchall()])

csr.close()
cnx.close()

Above code produces output as follows:

[[u'LANGUAGE SUPPORT MODE', u'Standard'], [u'RELEASE', u'15.00.01.01'], [u'VERSION', u'15.00.01.01']]
No handlers could be found for logger "teradata.tdodbc"

Is it normal and expected to have no-handler-for-logger message be displayed?

escheie commented 8 years ago

This message is encountered when using the tdodbc module directly instead of using UdaExec, which is responsible for configuring the logging context.

The logging modules documentation states the following:

When developing a library which uses logging, some consideration needs to be given to its configuration. If the using application does not use logging, and library code makes logging calls, then a one-off message “No handlers could be found for logger X.Y.Z” is printed to the console. This message is intended to catch mistakes in logging configuration, but will confuse an application developer who is not aware of logging by the library.

In addition to documenting how a library uses logging, a good way to configure library logging so that it does not cause a spurious message is to add a handler which does nothing. This avoids the message being printed, since a handler will be found: it just doesn’t produce any output. If the library user configures logging for application use, presumably that configuration will add some handlers, and if levels are suitably configured then logging calls made in library code will send output to those handlers, as normal.

I will add a do-nothing handler so that this message is not displayed when using modules directly instead of using UdaExec.

padhia commented 8 years ago

Thank you.