The utils repository of the amplec organisation houses all the utilities, shared functions and logging mechanisms that are used all across the AMPLEC project.
The Logger class provides a custom logging implementation tailored for the AMPLEC project. It shares functional similarities with Python's built-in logging.Logger but offers a simplified design with added custom behavior, such as tracking the call hierarchy. This class is subject to change as the AMPLEC project evolves.
-
Logging Modes
- Supports three modes:
console,elastic, anddual(both console and ElasticSearch). - If the mode is
elasticordual, an ElasticSearch URL and API key must be provided. - This differs from
logging.Logger, which uses configurable handlers (e.g., file handlers, stream handlers) to manage outputs.
- Supports three modes:
-
Call Hierarchy Tracking
- Includes a
_get_call_treemethod that appends the call hierarchy to log messages, providing insights into the execution path. - This feature is not present in
logging.Logger.
- Includes a
-
Simplified Log Levels
- Supports
info,warning,error, anddebug. - No built-in configurability for additional levels, handlers, or formatting options.
- Supports
-
Output Behavior
- Directly prints to the console, indexes into an ElasticSearch instance, or does both, depending on the selected mode.
- This differs from
logging.Logger, which relies on handlers for more granular control over outputs.
- Does not support advanced features like log rotation, custom formatters, or third-party integrations available in
logging.Logger. - Log levels and output formats are statically implemented.
The SimplePersistence class provides a straightforward mechanism for managing submission data. It supports storing, loading, and cleaning up submission files while maintaining metadata.
-
Initialization:
- Creates a base directory and metadata file (
metadata.json) for submissions if they do not exist. - Logs operations via a provided
Loggerinstance.
- Creates a base directory and metadata file (
-
Storing Submissions:
- Saves submission data to a
.txtfile. - Updates the
metadata.jsonwith submission details, including the indexing date. - Performs automatic cleanup of old submissions.
- Saves submission data to a
-
Loading Submissions:
- Retrieves submission data and metadata by ID.
- Provides an option to load only the payload (content).
-
Automatic Cleanup:
- Deletes submissions older than a specified number of days (default: 28 days).
- Updates the metadata file accordingly.
store_submission(submission_id: str, payload: list[str]): Stores a submission and updates metadata.load_submission(submission_id: str): Loads both payload and metadata for a submission.load_only_payload(submission_id: str): Retrieves only the payload for a submission.cleanup_submissions(older_than_days: int = 28): Removes submissions older than the specified duration._load_metadata(): Loads metadata frommetadata.json._save_metadata(metadata: dict): Saves the metadata dictionary tometadata.json.
More will be added as the project progresses