I'm coding up a Python file that inserts rows into a MySQL table from a dataframe using mysql.connector
. I'm trying to log each successful request and also the exceptions- I'm using Jupyter Notebook to execute the program. However, I'm not able to see any logging on the notebook- I have manually to go into the MySql database and check what has gone in, and I have no idea which entries haven't been successfully entered. Here is my code:
import os
import pandas as pd
import mysql.connector
import logging
import math
def upload_to_db(host, database, user, password,
tbl_name, col_str, dataframe):
try:
conn = mysql.connector.connect(
host=host, database=database, user=user, password=password)
cursor = conn.cursor()
cursor.execute("drop table if exists %s;" % (tbl_name))
cursor.execute("create table %s (%s);" % (
tbl_name, col_str))
data_list = dataframe.to_numpy().tolist()
for i in range(0, len(data_list)-1):
row_values = convert_list(data_list[i])
sql_statement = 'INSERT INTO %s VALUES (%s);' % (
tbl_name, row_values)
cursor.execute(sql_statement)
logging.info("SQL statement [" + sql_statement + "] successful")
conn.commit()
cursor.close()
except mysql.connector.Error as err:
logging.info("Exception: {}".format(err))
Why doesn't the python logging
class show the exceptions or successes on the Notebook?