logger
This commit is contained in:
@@ -3,6 +3,10 @@ from flask_sqlalchemy import SQLAlchemy
|
|||||||
from flask_bcrypt import Bcrypt
|
from flask_bcrypt import Bcrypt
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
|
||||||
@@ -21,4 +25,5 @@ if not os.path.exists('site.db'):
|
|||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
logger.info("Starting application...")
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import os
|
|||||||
import uuid
|
import uuid
|
||||||
import config
|
import config
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
from app import logger
|
||||||
|
|
||||||
UPLOAD_ROOT = os.path.join(os.getcwd(), 'uploads')
|
UPLOAD_ROOT = os.path.join(os.getcwd(), 'uploads')
|
||||||
|
|
||||||
@@ -29,17 +30,19 @@ def send_email(recipient_email, subject, body):
|
|||||||
server.starttls()
|
server.starttls()
|
||||||
server.login(sender_email, sender_password)
|
server.login(sender_email, sender_password)
|
||||||
server.send_message(msg)
|
server.send_message(msg)
|
||||||
|
logger.info(f"Email sent successfully via SMTP to {recipient_email}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to send email via external SMTP: {e}")
|
logger.error(f"Failed to send email via SMTP to {recipient_email}: {e}")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
process = os.popen(f"/usr/sbin/sendmail -t")
|
process = os.popen("/usr/sbin/sendmail -t")
|
||||||
process.write(f"To: {recipient_email}\n")
|
process.write(f"To: {recipient_email}\n")
|
||||||
process.write(f"Subject: {subject}\n")
|
process.write(f"Subject: {subject}\n")
|
||||||
process.write(f"\n{body}")
|
process.write(f"\n{body}")
|
||||||
process.close()
|
process.close()
|
||||||
|
logger.info(f"Email sent successfully via sendmail to {recipient_email}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to send email via local sendmail: {e}")
|
logger.error(f"Failed to send email via local sendmail to {recipient_email}: {e}")
|
||||||
|
|
||||||
def is_file_allowed(file):
|
def is_file_allowed(file):
|
||||||
return '.' in file.filename and file.filename.rsplit('.', 1)[1].lower() in config.ALLOWED_EXTENSIONS
|
return '.' in file.filename and file.filename.rsplit('.', 1)[1].lower() in config.ALLOWED_EXTENSIONS
|
||||||
|
|||||||
Reference in New Issue
Block a user