This commit is contained in:
zman 2025-04-08 10:33:46 -04:00
parent 6b900ef16d
commit 8c552af606

10
app.py
View File

@ -16,12 +16,19 @@ app = Flask(__name__)
# Set up logging # Set up logging
log_file = 'log.txt' log_file = 'log.txt'
# Create a rotating file handler for logging
log_handler = RotatingFileHandler(log_file, maxBytes=10*1024*1024, backupCount=5) # 10MB per log file, keep 5 backups log_handler = RotatingFileHandler(log_file, maxBytes=10*1024*1024, backupCount=5) # 10MB per log file, keep 5 backups
log_handler.setLevel(logging.DEBUG) log_handler.setLevel(logging.DEBUG)
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
log_handler.setFormatter(log_formatter) log_handler.setFormatter(log_formatter)
# Add the log handler to the Flask app's logger
app.logger.addHandler(log_handler) app.logger.addHandler(log_handler)
# Ensure Flask app uses our logger, not its default one
app.logger.setLevel(logging.DEBUG)
# Create a queue to hold the files for processing # Create a queue to hold the files for processing
file_queue = queue.Queue() file_queue = queue.Queue()
@ -91,7 +98,6 @@ def print_address_label(pdf_path):
backend_identifier=backend, backend_identifier=backend,
blocking=True blocking=True
) )
app.logger.info(f"Printer status: {status}")
app.logger.info("Print job sent successfully") app.logger.info("Print job sent successfully")
except Exception as e: except Exception as e:
@ -144,4 +150,4 @@ def upload_file():
return jsonify({'message': f'File {file.filename} uploaded and queued for processing'}), 200 return jsonify({'message': f'File {file.filename} uploaded and queued for processing'}), 200
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run(debug=True)