Convert into MVC and optimize the code
This commit is contained in:
17
app/service/logger.py
Normal file
17
app/service/logger.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
from flask import current_app
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def log_activity(user, action, details=""):
|
||||
try:
|
||||
log_file = os.path.join(current_app.root_path, "activity.log")
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
with open(log_file, "a") as f:
|
||||
f.write(
|
||||
f"Timestamp: {timestamp} | User: {user} | "
|
||||
f"Action: {action} | Details: {details}\n"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Logging failed: {e}")
|
||||
Reference in New Issue
Block a user