Skip to content

Commit

Permalink
pre commit, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbowen committed Nov 18, 2024
1 parent 11e90bc commit 382c18a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,20 +599,31 @@ This config includes:
`setup_logging` is called during the initialization of the Flask app.
### Usage
We use two loggers in this application:
We can utilise the Flask logger by accessing Flask's `app.logger`. Since we define our routes with blueprints rather than the app directly, we can call access app through
- app_logger for application-related logs
- audit_logger for audit-specific logs
Both are attached to the Flask app instance for easy access across the app. Since we define routes using blueprints instead of directly on the app, we access these loggers through Flask’s current_app.
To use these loggers in your code, import current_app from Flask:
```python
from flask import current_app
```
for example:
Then, call the appropriate logger as follows:
```python
current_app.logger.info('Some info message')
current_app.logger.debug('Some debug message')
current_app.logger.warning('Some warning message')
current_app.logger.error('Some error message')
current_app.app_logger.info('Some info message')
current_app.app_logger.debug('Some debug message')
current_app.app_logger.warning('Some warning message')
current_app.app_logger.error('Some error message')
current_app.audit_logger.info('Some info message')
current_app.audit_logger.debug('Some debug message')
current_app.audit_logger.warning('Some warning message')
current_app.audit_logger.error('Some error message')
```
### Output
Expand Down
8 changes: 2 additions & 6 deletions app/logger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ def setup_logging(app):

# APP LOGGER
app_logger = logging.getLogger("app_logger")
app_handler = (
logging.StreamHandler()
)
app_handler = logging.StreamHandler()
app_handler.setFormatter(formatter)
app_logger.setLevel(logging.INFO)
app_logger.addHandler(app_handler)

# AUDIT LOGGER
audit_logger = logging.getLogger("audit_logger")
audit_handler = (
logging.StreamHandler()
)
audit_handler = logging.StreamHandler()
audit_handler.setFormatter(formatter)
audit_logger.setLevel(logging.INFO)
audit_logger.addHandler(audit_handler)
Expand Down

0 comments on commit 382c18a

Please sign in to comment.