{"id":34024981,"url":"https://github.com/reshinto/loggingsfactory","last_synced_at":"2026-04-08T12:32:32.472Z","repository":{"id":57675991,"uuid":"485290852","full_name":"reshinto/loggingsfactory","owner":"reshinto","description":"Logging wrapper library that uses different logger types","archived":false,"fork":false,"pushed_at":"2025-10-09T17:23:11.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-14T09:04:56.968Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/loggingsfactory/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reshinto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-25T08:46:36.000Z","updated_at":"2025-10-09T17:23:16.000Z","dependencies_parsed_at":"2022-09-03T00:12:02.085Z","dependency_job_id":null,"html_url":"https://github.com/reshinto/loggingsfactory","commit_stats":null,"previous_names":["reshinto/loggerfactory"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/reshinto/loggingsfactory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshinto%2Floggingsfactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshinto%2Floggingsfactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshinto%2Floggingsfactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshinto%2Floggingsfactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reshinto","download_url":"https://codeload.github.com/reshinto/loggingsfactory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshinto%2Floggingsfactory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31556232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-13T16:47:59.111Z","updated_at":"2026-04-08T12:32:32.459Z","avatar_url":"https://github.com/reshinto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loggingsfactory\n\nLoggingsfactory provides a single entry point for writing application logs and issuing queries across Loguru, Elasticsearch, and AsyncElasticsearch. The `Loggers` factory inspects the arguments you provide at construction time and automatically returns the appropriate backend so teams can switch between local debugging and centralized ELK logging without changing call sites. Core behaviours such as log formatting, retry logic, and connection management are implemented once and reused across every logger type to keep logging consistent across services.\n\n## Key features\n\n- **Automatic logger selection** – Instantiating `Loggers` inspects the `debug` and `useasync` flags to decide whether to return the Loguru, synchronous Elasticsearch, or asynchronous Elasticsearch client, keeping your code focused on business logic instead of wiring. [`src/loggingsfactory/logging.py`](src/loggingsfactory/logging.py)\n- **Consistent log formatting** – Helper utilities attach metadata such as app name, logger level, function name, version, and timestamp to every message by default. You can also supply custom payloads or override the function name used in the log entry. [`src/loggingsfactory/helpers/formats.py`](src/loggingsfactory/helpers/formats.py)\n- **Elasticsearch integrations** – Synchronous and asynchronous wrappers share an interface for indexing logs, issuing search queries with optional custom payloads, and executing SQL queries through the Elasticsearch DB API. Connection helpers handle URL formatting, authentication, retry settings, and SSL verification. [`src/loggingsfactory/loggers/elk.py`](src/loggingsfactory/loggers/elk.py), [`src/loggingsfactory/loggers/asyncelk.py`](src/loggingsfactory/loggers/asyncelk.py), [`src/loggingsfactory/helpers/decorators.py`](src/loggingsfactory/helpers/decorators.py)\n- **Loguru enhancements** – When running in debug mode, the Loguru wrapper persists messages to `logs/logfile.log`, enforces supported levels, and keeps a running counter of emitted logs for quick sanity checks. [`src/loggingsfactory/loggers/loguru.py`](src/loggingsfactory/loggers/loguru.py), [`src/loggingsfactory/helpers/singletons.py`](src/loggingsfactory/helpers/singletons.py)\n- **Search-friendly defaults** – Built-in query builders provide a sensible default payload that filters by application name and time range while allowing callers to override any portion of the Elasticsearch request. [`src/loggingsfactory/helpers/formats.py`](src/loggingsfactory/helpers/formats.py)\n\n## Repository structure\n\n```\nsrc/\n└── loggingsfactory/\n    ├── logging.py            # Factory that chooses the correct logger implementation\n    ├── loggers/              # Loguru, Elasticsearch, and AsyncElasticsearch wrappers\n    ├── helpers/              # Formatting utilities, decorators, and singletons\n    └── constants/            # Shared enums and configuration values\n```\n\nAutomated tests covering the factory selection logic, required configuration keys, and backend integrations live under `tests/`. [`tests/test_loggingsfactory`](tests/test_loggingsfactory)\n\n## Getting started\n\n1. **Set up Python** – Loggingsfactory targets Python 3.6 or later. [`setup.cfg`](setup.cfg)\n2. **Create a virtual environment** (optional but recommended):\n   ```bash\n   python -m venv .venv\n   source .venv/bin/activate\n   ```\n3. **Install dependencies**:\n   ```bash\n   pip install -r requirements.txt\n   ```\n   The package itself can also be installed directly with:\n   ```bash\n   pip install .\n   ```\n\n## Usage\n\n### Selecting a backend\n\n```python\nfrom loggingsfactory.logging import Loggers\n\n# Loguru for local development (writes to logs/logfile.log)\nlogger = Loggers(appname=\"myapp\")\n\n# Elasticsearch for production clusters\nelk_logger = Loggers(\n    appname=\"myapp\",\n    debug=False,\n    host=\"https://elasticsearch.example.com:9201\",\n    index=\"appindex\",\n    username=\"user1\",\n    pw=\"password\",\n)\n\n# AsyncElasticsearch for asyncio applications\nasync_elk_logger = Loggers(\n    appname=\"myapp\",\n    debug=False,\n    useasync=True,\n    host=\"https://elasticsearch.example.com:9201\",\n    index=\"appindex\",\n    username=\"user1\",\n    pw=\"password\",\n)\n```\n\n### Writing logs\n\n```python\n# Default structure with inferred function name and ISO timestamp\nlogger.log(\"info\", \"log data\")\n\n# Override the function name used in the log entry\nlogger.log(\"info\", \"log data\", custom_func_name=\"worker.process\")\n\n# Send a custom payload (will be JSON-encoded for Elasticsearch)\ncustom_payload = {\"custom_log\": \"this is a custom log\"}\nlogger.log(\"info\", custom_payload, use_custom_logdata=True)\n\n# Provide a specific timestamp\nlogger.log(\"info\", \"log data\", date=\"2022-04-27T00:00:00Z\")\n```\n\nFor asynchronous contexts:\n\n```python\nawait async_elk_logger.async_log(\"info\", \"async log data\")\n```\n\n### Querying logs\n\n```python\n# Default query payload filters by app name and recent timestamps\nelk_logger.query(custompayload=None, size=1000, cache=True)\n\n# Custom payload example\npayload = {\n    \"query\": {\n        \"bool\": {\n            \"filter\": [\n                {\"match_phrase\": {\"app_name.keyword\": \"myapp\"}},\n                {\"range\": {\"timestamp\": {\"gte\": \"2021-09-24T02:58:43.647Z\"}}},\n            ]\n        }\n    }\n}\nelk_logger.query(custompayload=payload)\n\n# Async search\nawait async_elk_logger.async_query(custompayload=payload)\n\n# SQL query via Elasticsearch DB API (synchronous only)\nrows = elk_logger.sql_query(\"SELECT * FROM appindex\")\n```\n\n### Configuration helpers\n\n- Supported log levels are defined in `constants.config.LogLevels` and validated before dispatching. [`src/loggingsfactory/constants/config.py`](src/loggingsfactory/constants/config.py)\n- Host, index, username, password, and other keys are enumerated in `constants.keys.LoggerKeys`, making it clear which parameters are required. [`src/loggingsfactory/constants/keys.py`](src/loggingsfactory/constants/keys.py)\n- Connection decorators automatically configure retries, SSL settings, and URL formatting when contacting Elasticsearch clusters. [`src/loggingsfactory/helpers/decorators.py`](src/loggingsfactory/helpers/decorators.py)\n\n## Running tests\n\nRun the automated test suite with pytest:\n\n```bash\npytest\n```\n\nTests cover factory selection, validation of required parameters, and logging behaviour for each backend. [`tests/test_loggingsfactory/test_logging.py`](tests/test_loggingsfactory/test_logging.py)\n\n## Support and contributions\n\nIssues and feature requests are tracked on GitHub at [https://github.com/reshinto/loggingsfactory](https://github.com/reshinto/loggingsfactory). Contributions are welcome—feel free to open a pull request after discussing substantial changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshinto%2Floggingsfactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freshinto%2Floggingsfactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshinto%2Floggingsfactory/lists"}