fix logging to use the new
This commit is contained in:
@@ -17,7 +17,7 @@ def on_file_received(self: object, file: str) -> None:
|
||||
"""
|
||||
if not os.stat(file).st_size:
|
||||
os.remove(file)
|
||||
logging.info(f'File {file} is empty: removed.')
|
||||
logger.info(f'File {file} is empty: removed.')
|
||||
else:
|
||||
cfg = self.cfg
|
||||
path, filenameExt = os.path.split(file)
|
||||
@@ -35,7 +35,7 @@ def on_file_received(self: object, file: str) -> None:
|
||||
conn = connetti_db(cfg)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error: {e}")
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
|
||||
# Create a cursor
|
||||
cur = conn.cursor()
|
||||
@@ -45,8 +45,8 @@ def on_file_received(self: object, file: str) -> None:
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f'File {file} not loaded. Held in user path.')
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'File {file} not loaded. Held in user path.')
|
||||
logger.error(f'{e}')
|
||||
else:
|
||||
os.remove(file)
|
||||
logging.info(f'File {file} loaded: removed.')
|
||||
logger.info(f'File {file} loaded: removed.')
|
||||
@@ -72,7 +72,7 @@ async def send_elab_csv_to_customer(cfg: dict, id: int, unit: str, tool: str, cs
|
||||
send_ftp_info = await cur.fetchone()
|
||||
logger.info(f"id {id} - {unit} - {tool}: estratti i dati per invio via ftp")
|
||||
except Exception as e:
|
||||
logging.error(f"id {id} - {unit} - {tool} - errore nel query per invio ftp: {e}")
|
||||
logger.error(f"id {id} - {unit} - {tool} - errore nel query per invio ftp: {e}")
|
||||
|
||||
try:
|
||||
# Converti in bytes
|
||||
@@ -95,17 +95,17 @@ async def send_elab_csv_to_customer(cfg: dict, id: int, unit: str, tool: str, cs
|
||||
result = ftp.storbinary(f'STOR {send_ftp_info["ftp_filename"]}', csv_buffer)
|
||||
|
||||
if result.startswith('226'):
|
||||
logging.info(f"File {send_ftp_info["ftp_filename"]} inviato con successo")
|
||||
logger.info(f"File {send_ftp_info["ftp_filename"]} inviato con successo")
|
||||
return True
|
||||
else:
|
||||
logging.error(f"Errore nell'invio: {result}")
|
||||
logger.error(f"Errore nell'invio: {result}")
|
||||
return False
|
||||
|
||||
except all_errors as e:
|
||||
logging.error(f"Errore FTP: {e}")
|
||||
logger.error(f"Errore FTP: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.error(f"Errore generico: {e}")
|
||||
logger.error(f"Errore generico: {e}")
|
||||
return False
|
||||
finally:
|
||||
csv_buffer.close()
|
||||
|
||||
@@ -41,14 +41,14 @@ def ftp_SITE_ADDU(self: object, line: str) -> None:
|
||||
conn = connetti_db(cfg)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error: {e}")
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
|
||||
# Create a cursor
|
||||
cur = conn.cursor()
|
||||
cur.execute(f"INSERT INTO {cfg.dbname}.{cfg.dbusertable} (ftpuser, hash, virtpath, perm) VALUES ('{user}', '{hash}', '{cfg.virtpath + user}', '{cfg.defperm}')")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
logging.info(f"User {user} created.")
|
||||
logger.info(f"User {user} created.")
|
||||
self.respond('200 SITE ADDU successful.')
|
||||
except Exception as e:
|
||||
self.respond(f'501 SITE ADDU failed: {e}.')
|
||||
@@ -72,7 +72,7 @@ def ftp_SITE_DISU(self: object, line: str) -> None:
|
||||
conn = connetti_db(cfg)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error: {e}")
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
|
||||
# Crea un cursore
|
||||
cur = conn.cursor()
|
||||
@@ -80,7 +80,7 @@ def ftp_SITE_DISU(self: object, line: str) -> None:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
logging.info(f"User {user} deleted.")
|
||||
logger.info(f"User {user} deleted.")
|
||||
self.respond('200 SITE DISU successful.')
|
||||
except Exception as e:
|
||||
self.respond('501 SITE DISU failed.')
|
||||
@@ -102,7 +102,7 @@ def ftp_SITE_ENAU(self: object, line: str) -> None:
|
||||
conn = connetti_db(cfg)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error: {e}")
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
|
||||
# Crea un cursore
|
||||
cur = conn.cursor()
|
||||
@@ -110,7 +110,7 @@ def ftp_SITE_ENAU(self: object, line: str) -> None:
|
||||
cur.execute(f"UPDATE {cfg.dbname}.{cfg.dbusertable} SET disabled_at = null WHERE ftpuser = '{user}'")
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
logging.error(f"Update DB failed: {e}")
|
||||
logger.error(f"Update DB failed: {e}")
|
||||
|
||||
cur.execute(f"SELECT ftpuser, hash, virtpath, perm FROM {cfg.dbname}.{cfg.dbusertable} WHERE ftpuser = '{user}'")
|
||||
|
||||
@@ -123,7 +123,7 @@ def ftp_SITE_ENAU(self: object, line: str) -> None:
|
||||
|
||||
conn.close()
|
||||
|
||||
logging.info(f"User {user} restored.")
|
||||
logger.info(f"User {user} restored.")
|
||||
self.respond('200 SITE ENAU successful.')
|
||||
|
||||
except Exception as e:
|
||||
@@ -145,7 +145,7 @@ def ftp_SITE_LSTU(self: object, line: str) -> None:
|
||||
conn = connetti_db(cfg)
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error: {e}")
|
||||
logging.error(f'{e}')
|
||||
logger.error(f'{e}')
|
||||
|
||||
# Crea un cursore
|
||||
cur = conn.cursor()
|
||||
|
||||
Reference in New Issue
Block a user