Skip to content

Commit

Permalink
Merge pull request #11 from farhaan444/logging-enhancements
Browse files Browse the repository at this point in the history
logging Enhancements
  • Loading branch information
farhaan444 authored May 6, 2024
2 parents 8908b2d + 6c06721 commit 182ba84
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ KIWI_API_KEY_MULTICITY = 'Your secret kiwi api key used for searching Multi-city
DATABASE_PATH = 'database\database.db'

# USER TYPES - LIST TYPE - INSERT CHAT_ID USERS INTO LIST
ADMINISTRATOR = []
ADMINISTRATORS = []

# JOB SCHEDULING INTERVALS - SECONDS
FIRST_RUN_FS = 10800
Expand Down
27 changes: 27 additions & 0 deletions Logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs Folder

This folder contains logs generated by the application. The logs are categorized into two main files:

1. **global.log**: This file contains all logs generated by the application, including informational messages, warnings, errors, and any other relevant events.

2. **exceptions.log**: This file specifically captures exceptions and errors encountered during the execution of the application. It serves as a focused record for debugging and error analysis purposes.

## File Descriptions

- **global.log**:
- **Purpose**: To provide a comprehensive record of all events occurring within the application.
- **Contents**: Includes informational messages, warnings, errors, and other relevant events.
- **exceptions.log**:
- **Purpose**: To specifically log exceptions and errors encountered during the execution of the application.
- **Contents**: Contains detailed information about exceptions, stack traces, and associated error messages.

## Usage

- **Reading Logs**: Use a text editor or log viewer tool to access and analyze the logs.
- **Debugging**: When debugging the application, refer to the `exceptions.log` file to identify and address any encountered errors or exceptions.

## Maintenance

- **Log Rotation**: Regularly monitor and manage the size of the log files to prevent them from becoming too large. Consider implementing log rotation strategies to archive or truncate older logs.

- **Log Analysis**: Periodically analyze the logs to identify patterns, performance issues, or recurring errors that may require attention.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DATABASE_PATH: str = os.getenv('DATABASE_PATH')

# USER TYPES
ADMINISTRATOR: list = os.getenv('ADMINISTRATOR')
ADMINISTRATORS: list = os.getenv('ADMINISTRATORS')

# JOB SCHEDULING INTERVALS - SECONDS
FIRST_RUN_FS = int(os.getenv('FIRST_RUN_FS'))
Expand Down
7 changes: 7 additions & 0 deletions handlers/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

from telegram import Update
from telegram.ext import ContextTypes
from telegram.constants import ParseMode
import logging
import datetime
import config

logger = logging.getLogger(__name__)


async def errors(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Error handler that handles bot errors and prints out errors to console """
logger.exception(context.error)
curr_datetime = datetime.datetime.now()
reply = f"{curr_datetime} <b>A bot exception/error has occured. Please see logs.</b>"
for i in config.ADMINISTRATORS:
await context.bot.send_message(chat_id=i, text=reply, parse_mode=ParseMode.HTML)
2 changes: 1 addition & 1 deletion utils/flight_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def get_airports(location):
response.raise_for_status()
data = await response.json()
except Exception as error:
print(error)
logger.error(msg="Get Airports Error", exc_info=error)
return 'Connection Error'
else:
results = data['results_retrieved']
Expand Down

0 comments on commit 182ba84

Please sign in to comment.