denisenkom / pytds

Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation
MIT License
190 stars 52 forks source link

logging module #117

Closed darren-martz closed 1 year ago

darren-martz commented 3 years ago

I have found it difficult to manage the logging output of pytds. A simple line change in pytds.py would help from the following:

logger = logging.getLogger()

changed to

logger = logging.getLogger('tds')

This change would allow the following to work, where today this is ignored and the logs fill with every INFO statement.

logging.getLogger('tds').setLevel(logging.ERROR)

A workaround I used was the following, but its not ideal.

class MyFilter(logging.Filter):
    def filter(self, record):
        if record.module == "tds" and record.levelname == "INFO":
            return False
        return True
logging.getLogger().addFilter(MyFilter())
niconil commented 3 years ago

i can just confirm the same issue here.

in pytds/src/pytds/tds.py#L15 just replace : logger = logging.getLogger() by logger = logging.getLogger(__name__)

this will allow projects that use this module to manage the log messages from pytds

akachroo762 commented 1 year ago

Any update on this?? Can we merge the PR associated with the issue. All the info logs are getting in the root and there is no way to stop them at the moment. This simple change would resolve that