modifiche di ase python

This commit is contained in:
2025-11-01 18:37:53 +01:00
parent baa10d06e2
commit 648a3af73f
2 changed files with 70 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ managing virtual users and handling CSV file uploads.
import logging
import os
from hashlib import sha256
from logging.handlers import RotatingFileHandler
from pathlib import Path
from pyftpdlib.handlers import FTPHandler
@@ -103,6 +104,39 @@ class ASEHandler(FTPHandler):
return user_admin.ftp_SITE_LSTU(self, line)
def setup_logging(log_filename: str):
"""
Configura il logging per il server FTP con rotation e output su console.
Args:
log_filename (str): Percorso del file di log.
"""
root_logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s")
# Rimuovi eventuali handler esistenti
if root_logger.hasHandlers():
root_logger.handlers.clear()
# Handler per file con rotation (max 10MB per file, mantiene 5 backup)
file_handler = RotatingFileHandler(
log_filename,
maxBytes=10 * 1024 * 1024, # 10 MB
backupCount=5, # Mantiene 5 file di backup
encoding="utf-8"
)
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)
# Handler per console (utile per Docker)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
root_logger.setLevel(logging.INFO)
root_logger.info("Logging FTP configurato con rotation (10MB, 5 backup) e console output")
def main():
"""Main function to start the FTP server."""
# Load the configuration settings
@@ -110,11 +144,7 @@ def main():
try:
# Configure logging first
logging.basicConfig(
format="%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s ",
filename=cfg.logfilename,
level=logging.INFO,
)
setup_logging(cfg.logfilename)
# Initialize the authorizer with database support
# This authorizer checks the database on every login, ensuring

View File

@@ -7,6 +7,7 @@ managing virtual users and handling CSV file uploads.
import logging
import os
from hashlib import sha256
from logging.handlers import RotatingFileHandler
from pathlib import Path
from pyftpdlib.handlers import FTPHandler
@@ -103,6 +104,39 @@ class ASEHandler(FTPHandler):
return user_admin.ftp_SITE_LSTU(self, line)
def setup_logging(log_filename: str):
"""
Configura il logging per il server FTP con rotation e output su console.
Args:
log_filename (str): Percorso del file di log.
"""
root_logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s")
# Rimuovi eventuali handler esistenti
if root_logger.hasHandlers():
root_logger.handlers.clear()
# Handler per file con rotation (max 10MB per file, mantiene 5 backup)
file_handler = RotatingFileHandler(
log_filename,
maxBytes=10 * 1024 * 1024, # 10 MB
backupCount=5, # Mantiene 5 file di backup
encoding="utf-8"
)
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)
# Handler per console (utile per Docker)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
root_logger.setLevel(logging.INFO)
root_logger.info("Logging FTP configurato con rotation (10MB, 5 backup) e console output")
def main():
"""Main function to start the FTP server."""
# Load the configuration settings
@@ -110,11 +144,7 @@ def main():
try:
# Configure logging first
logging.basicConfig(
format="%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s ",
filename=cfg.logfilename,
level=logging.INFO,
)
setup_logging(cfg.logfilename)
# Initialize the authorizer with database support
# This authorizer checks the database on every login, ensuring