ecl-logging-utility 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ from .logging_utility import configure_logging, logger
2
+
3
+ __all__ = ['configure_logging', 'logger']
4
+ __version__ = '1.0.0'
@@ -0,0 +1,82 @@
1
+ import os
2
+ import sys
3
+ import logging
4
+ import structlog
5
+ from structlog.contextvars import bind_contextvars, clear_contextvars
6
+ from structlog.processors import CallsiteParameter
7
+
8
+ # Map string log levels to logging constants
9
+ LOG_LEVEL_MAP = {
10
+ 'DEBUG': logging.DEBUG,
11
+ 'INFO': logging.INFO,
12
+ 'WARNING': logging.WARNING,
13
+ 'ERROR': logging.ERROR,
14
+ 'CRITICAL': logging.CRITICAL
15
+ }
16
+
17
+ # Default log level if not specified
18
+ DEFAULT_LOG_LEVEL = logging.INFO
19
+
20
+
21
+ def get_log_level():
22
+ """Get log level from environment variable"""
23
+ level_str = os.environ.get('LOG_LEVEL', 'INFO').upper()
24
+ return LOG_LEVEL_MAP.get(level_str, DEFAULT_LOG_LEVEL)
25
+
26
+
27
+ # Custom processor to rename fields
28
+ def rename_fields(_, __, event_dict):
29
+ field_mappings = {
30
+ 'pathname': 'file_path',
31
+ 'lineno': 'line_number',
32
+ 'func_name': 'function_name'
33
+ }
34
+ for old_key, new_key in field_mappings.items():
35
+ if old_key in event_dict:
36
+ event_dict[new_key] = event_dict.pop(old_key)
37
+ return event_dict
38
+
39
+
40
+ def configure_logging():
41
+ # Get environment variables
42
+ app_version = os.environ.get('APP_VERSION', 'unknown')
43
+ service_name = os.environ.get('SERVICE_NAME', 'unknown')
44
+ log_level = get_log_level()
45
+
46
+ processors = [
47
+ structlog.contextvars.merge_contextvars,
48
+ structlog.stdlib.add_log_level,
49
+ structlog.stdlib.PositionalArgumentsFormatter(),
50
+ structlog.processors.TimeStamper(fmt="iso", utc=True),
51
+ structlog.processors.CallsiteParameterAdder(
52
+ [
53
+ CallsiteParameter.PATHNAME, # Full absolute path
54
+ CallsiteParameter.LINENO,
55
+ CallsiteParameter.MODULE,
56
+ CallsiteParameter.FUNC_NAME,
57
+ ]
58
+ ),
59
+ rename_fields,
60
+ structlog.processors.EventRenamer(to='message'),
61
+ structlog.processors.StackInfoRenderer(),
62
+ structlog.processors.format_exc_info,
63
+ structlog.processors.JSONRenderer()
64
+ ]
65
+
66
+ structlog.configure(
67
+ processors=processors,
68
+ context_class=structlog.threadlocal.wrap_dict(dict),
69
+ logger_factory=structlog.PrintLoggerFactory(file=sys.stdout),
70
+ wrapper_class=structlog.make_filtering_bound_logger(log_level),
71
+ cache_logger_on_first_use=False,
72
+ )
73
+
74
+ # Create logger with static context
75
+ return structlog.get_logger(service_name).bind(
76
+ app_version=app_version,
77
+ service_name=service_name
78
+ )
79
+
80
+
81
+ # Initialize logger with static context
82
+ logger = configure_logging()
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: ecl-logging-utility
3
+ Version: 1.0.0
4
+ Summary: Internal structured logging utility for ECL microservices
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: License :: Other/Proprietary License
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: structlog>=23.1.0
11
+ Requires-Dist: python-json-logger>=2.0.2
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # Structured Logging Utilities for ECL microservices
20
+
21
+ ![Python Version](https://img.shields.io/badge/python-3.8%2B-blue)
22
+ ![License](https://img.shields.io/badge/license-Proprietary-lightgrey)
23
+
24
+ Internal package for consistent structured logging across ECL microservices. Features JSON formatting, automatic metadata capture, and environment-based configuration.
25
+
26
+ ## Features
27
+
28
+ - 📝 **Structured JSON logs** with consistent schema
29
+ - 🕒 **Automatic timestamping** in ISO 8601 format
30
+ - 📍 **Complete source location** (file path, line number, module, function)
31
+ - 🔍 **Query-ready fields** (transaction_id, request_ip, service_name)
32
+ - ⚙️ **Environment-controlled** log levels
33
+ - 🔗 **Request context propagation** across services
34
+ - 🛡 **Private package** for internal use only
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install ecl-logging-utility
40
+ ```
41
+
42
+ ## Version History
43
+ See [CHANGELOG.md](CHANGELOG.md) for release notes.
@@ -0,0 +1,6 @@
1
+ ecl_logging_utility/__init__.py,sha256=Un9t9Ky5-EzzzMdSUQvAd8S0BeUI6C4ZfS0983PoRFc,119
2
+ ecl_logging_utility/logging_utility.py,sha256=eWnEPNEzJ6UyByWCYcWDujTDnd-m6LB39gI_vg5b59I,2520
3
+ ecl_logging_utility-1.0.0.dist-info/METADATA,sha256=13Igx_bXhMcX4ddVH3zmiUsiVIta0xpB9KXhysqjqJs,1476
4
+ ecl_logging_utility-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ ecl_logging_utility-1.0.0.dist-info/top_level.txt,sha256=UREkEqY0o1NTCuWgS2kXHXv34M_7rKqA9h_oH_gVchU,20
6
+ ecl_logging_utility-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ ecl_logging_utility