Skip to content

Commit cfa0016

Browse files
committed
modified the logger setup
1 parent bf54473 commit cfa0016

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

app/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@
88

99
def create_app(config_class=None):
1010
app = Flask(__name__)
11-
12-
# Configure the app
11+
1312
if config_class:
1413
app.config.from_object(config_class)
1514
else:
1615
app.config.from_object('app.config.Config')
16+
17+
# Set up the dedicated student logger
18+
student_logger = setup_logger()
19+
20+
# Attach handlers and level to Flask's native logger to ensure all logs write to the same file
21+
app.logger.handlers = student_logger.handlers[:]
22+
app.logger.setLevel(student_logger.level)
23+
app.logger.propagate = False # Prevent double logging
1724

18-
19-
# Initialize logger
20-
logger = setup_logger('student_logger', log_file='app.log')
2125
app.logger.info("Student Management API started successfully.")
2226

23-
# Initialize database and migration
27+
# init db & migrations
2428
db.init_app(app)
2529
migrate.init_app(app, db)
2630

27-
# Import models inside app context
2831
with app.app_context():
2932
from . import models
30-
31-
# Import and register blueprints here (after db/models are ready)
33+
3234
from .routes import student_bp
3335
app.register_blueprint(student_bp, url_prefix='/students')
34-
35-
# Home route
36+
3637
@app.route('/')
3738
def home():
3839
app.logger.info("Home page accessed")
3940
return "Welcome to the Student Management API!"
40-
41-
# Health check route
41+
4242
@app.route('/health')
4343
def health():
4444
app.logger.info("Health check accessed")
4545
return jsonify({"status": "ok"}), 200
46-
47-
return app
46+
47+
return app

0 commit comments

Comments
 (0)