aggiunto logratating pythone e su stdout per docker

This commit is contained in:
2025-11-01 18:26:29 +01:00
parent 76094f7641
commit 37db980c10

View File

@@ -7,6 +7,7 @@ managing virtual users and handling CSV file uploads.
import logging import logging
import os import os
from hashlib import sha256 from hashlib import sha256
from logging.handlers import RotatingFileHandler
from pathlib import Path from pathlib import Path
from pyftpdlib.handlers import FTPHandler from pyftpdlib.handlers import FTPHandler
@@ -103,6 +104,39 @@ class ASEHandler(FTPHandler):
return user_admin.ftp_SITE_LSTU(self, line) 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(): def main():
"""Main function to start the FTP server.""" """Main function to start the FTP server."""
# Load the configuration settings # Load the configuration settings
@@ -110,11 +144,7 @@ def main():
try: try:
# Configure logging first # Configure logging first
logging.basicConfig( setup_logging(cfg.logfilename)
format="%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s ",
filename=cfg.logfilename,
level=logging.INFO,
)
# Initialize the authorizer with database support # Initialize the authorizer with database support
# This authorizer checks the database on every login, ensuring # This authorizer checks the database on every login, ensuring