I am in a situation where I have a package that is calling logging.debug(xxx). I want to disable all logging statements by this package. Is there a way to do that via config?
For example, every query I run is printing out in the console of the dev server:
DEBUG:root:SELECT Entities.path, Entities.entity FROM "dev~xxxx!!Entities" AS Entities INNER JOIN "dev~xxxx!!EntitiesByProperty" AS ebp_0 ON Entities.path = ebp_0.path INNER JOIN "dev~xxxx!!EntitiesByProperty" AS ebp_1 ON Entities.path = ebp_1.path INNER JOIN "dev~xxxx!!EntitiesByProperty" AS ebp_2 ON Entities.path = ebp_2.path WHERE ebp_0.kind = :1 AND ebp_0.name = :2 AND ebp_0.value = :3 AND ebp_1.kind = :4 AND ebp_1.name = :5 AND ebp_1.value = :6 AND ebp_2.kind = :7 AND ebp_2.name = :8 AND ebp_2.value = :9 ORDER BY Entities.path ASC
So I know how to disable it by modifying the sdk source, basically comment out the logging statement in __StarSchemaQueryPlan
logging.debug(query)
Is there a way to disable the logging without touching SDK code? We currently do not define any loggingConfigurations, and are using the basicConfiguror.
Final solution thank you @lucemia:
class Filter(object):
def filter(self, record):
if record.funcName=='__StarSchemaQueryPlan' and record.module=='datastore_sqlite_stub':
return 0
else:
return 1
You can try to modify the log level.
Since the module used default logger. The following code will disable all log which's level smaller than critical.
import logging
logger = logging.getLogger() # get the default logger
logger.setLevel(50) # set the skip all log which is smaller than critical (50)
import logging
def main():
logging.error("test")
logging.critical('c')
import a_lib
import logging
logger = logging.getLogger()
logger.setLevel(50)
a_lib.main()
> python a_test.py
CRITICAL:root:c
Another way to do so is using filter
import logging
# define a new filter
class Filter():
def filter(self, record):
# extract property of record such as record.funcName, record.module
# http://docs.python.org/2/library/logging.html#logrecord-attributes
if record.module == "a_lib":
# if the record is from a module you don't want to log
return 0
else:
# for record you want to log
return 1
# apply this filter
filter = Filter()
logger= logging.getLogger()
logger.addFilter(filter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With