I have the following class:
import cfg
import sqlite3
import logging
# logger = logging ......
class Connection:
def __init__(self):
try:
self.connection = sqlite3.connect(cfg.pathToDatabase)
self.connection.row_factory = sqlite3.Row
self.cursor = self.connection.cursor()
logger.info("Connection to database at " + cfg.pathToDatabase + " successful")
except Exception, e:
logger.critical("Error connecting to database")
logger.exception(e)
This class will be instantiated from multiple classes. In the following line:
logger.info("Connection to database at " + cfg.pathToDatabase + " successful")
I would like to log the class that called the __ init __ method in the Connection class. Is this possible ?
for example, based on the following:
class Child:
def __init__(self):
self.connection = Connection()
I would like to see this logged:
"Connection to database at data.sqlite successful from class: Child"
Something like this?
Output: