acai-aws 2.2.8__py3-none-any.whl → 2.3.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.
- acai_aws/common/logger/common_logger.py +12 -8
- {acai_aws-2.2.8.dist-info → acai_aws-2.3.0.dist-info}/METADATA +1 -1
- {acai_aws-2.2.8.dist-info → acai_aws-2.3.0.dist-info}/RECORD +7 -7
- tests/acai_aws/common/test_logger.py +26 -1
- {acai_aws-2.2.8.dist-info → acai_aws-2.3.0.dist-info}/WHEEL +0 -0
- {acai_aws-2.2.8.dist-info → acai_aws-2.3.0.dist-info}/licenses/LICENSE +0 -0
- {acai_aws-2.2.8.dist-info → acai_aws-2.3.0.dist-info}/top_level.txt +0 -0
|
@@ -3,14 +3,14 @@ import os
|
|
|
3
3
|
import traceback
|
|
4
4
|
|
|
5
5
|
import jsonpickle
|
|
6
|
-
from icecream import ic
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
class CommonLogger:
|
|
10
9
|
|
|
11
10
|
def __init__(self):
|
|
12
11
|
self.__json = jsonpickle
|
|
13
|
-
|
|
12
|
+
env_format = os.getenv('LOG_FORMAT', 'JSON') or 'JSON'
|
|
13
|
+
self.__format = env_format.strip().upper()
|
|
14
14
|
self.__log_level = os.getenv('LOG_LEVEL', 'INFO')
|
|
15
15
|
self.__json.set_encoder_options('simplejson', use_decimal=True)
|
|
16
16
|
self.__json.set_preferred_backend('simplejson')
|
|
@@ -44,13 +44,17 @@ class CommonLogger:
|
|
|
44
44
|
print(self.__json.encode({
|
|
45
45
|
'level': kwargs['level'],
|
|
46
46
|
'time': datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
47
|
-
'
|
|
47
|
+
'trace': [trace.strip() for trace in self.__get_traceback().split('\n') if trace],
|
|
48
48
|
'log': kwargs['log']
|
|
49
49
|
}, indent=4))
|
|
50
50
|
|
|
51
51
|
def __log_inline(self, **kwargs):
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
53
|
+
trace = self.__get_traceback().strip().replace('\n', ' | ')
|
|
54
|
+
log_value = kwargs['log']
|
|
55
|
+
if not isinstance(log_value, str):
|
|
56
|
+
log_value = str(log_value)
|
|
57
|
+
inline_message = f"{kwargs['level']}|time={timestamp} log={log_value}"
|
|
58
|
+
if trace:
|
|
59
|
+
inline_message = f"{inline_message} trace={trace}"
|
|
60
|
+
print(inline_message)
|
|
@@ -26,7 +26,7 @@ acai_aws/common/json_helper.py,sha256=HoCaF0fO_EXcVbwanZ9Cg66x9oQUQyXbEdLfResFpq
|
|
|
26
26
|
acai_aws/common/schema.py,sha256=mbtD922dsNzZX2uZjJKXFVj9IShpgBRofTVmdNyLGyE,3549
|
|
27
27
|
acai_aws/common/validator.py,sha256=uYFMPGM5dvsiKxuwFGxetwqGcRNm03BZ3YJ6lNedwck,6575
|
|
28
28
|
acai_aws/common/logger/__init__.py,sha256=2ItzGhXLdTwt9tKAOa5dzgQlLouJKQbUhV4qjxBLl1g,241
|
|
29
|
-
acai_aws/common/logger/common_logger.py,sha256=
|
|
29
|
+
acai_aws/common/logger/common_logger.py,sha256=sGtTjDSqqXhVauGR06SuUWdYfxOrgzQcEswdrC5WIu0,2263
|
|
30
30
|
acai_aws/common/logger/decorator.py,sha256=Nf7S--7mWKVkKiRB2fVNM9B4NBFpJeTGv0FYxK0DEvU,749
|
|
31
31
|
acai_aws/common/records/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
acai_aws/common/records/event.py,sha256=F6fqxSRWfAbEH8n_Vw9ZQICcNd__rWRGpMv1T0deQ8o,621
|
|
@@ -72,7 +72,7 @@ acai_aws/sqs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
72
72
|
acai_aws/sqs/event.py,sha256=u5QYrb-XLy2mhzi3v55je6N6vASS3ywzjIBDjm_n32Q,264
|
|
73
73
|
acai_aws/sqs/record.py,sha256=b-9gidW2UvuSZU00sgZV90DuUj7r12zTXYbQLNBSYjk,1909
|
|
74
74
|
acai_aws/sqs/requirements.py,sha256=4QR0LIrDqF1CPSAroscX3EAys-dbqWMFmOhqyILcViw,116
|
|
75
|
-
acai_aws-2.
|
|
75
|
+
acai_aws-2.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
76
76
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
77
77
|
tests/acai_aws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
78
|
tests/acai_aws/apigateway/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -107,7 +107,7 @@ tests/acai_aws/apigateway/router/test_pattern_router.py,sha256=981DrtlSSfaWSiDMQ
|
|
|
107
107
|
tests/acai_aws/apigateway/router/test_timeout.py,sha256=Jv5Bk3s91kL4lBQAxxQ3NzjLnpKbeg845w4GpLwLkZA,2546
|
|
108
108
|
tests/acai_aws/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
109
109
|
tests/acai_aws/common/test_json_helper.py,sha256=P7kw_KIaVQFr9JQAFHd4jdbvg1uVQ5l5pQmx8HmFg88,1389
|
|
110
|
-
tests/acai_aws/common/test_logger.py,sha256=
|
|
110
|
+
tests/acai_aws/common/test_logger.py,sha256=Aq4o43embLWofq9gG-JCY4nH4ohIqjdkwAU9nsrqkDE,5906
|
|
111
111
|
tests/acai_aws/common/test_schema.py,sha256=WbSBwYGrdraF3EtuDB9XWYREKk_W14317jrTXEo90xY,5658
|
|
112
112
|
tests/acai_aws/common/test_validator.py,sha256=9hDpf-UGCrQ1Elx0Th8wezLQ0HkUoKj-UXuLDGT5GJU,5958
|
|
113
113
|
tests/acai_aws/common/records/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -154,7 +154,7 @@ tests/acai_aws/sqs/test_event.py,sha256=d8JBttuLND_qBVdLAoqtp-_qJ5NXxD6Ai2IFmUqK
|
|
|
154
154
|
tests/acai_aws/sqs/test_record.py,sha256=RkWpc24A-f4bw1VyMM5mEp97QCk4i-Weu6CFP0-VlbU,1602
|
|
155
155
|
tests/acai_aws/sqs/test_requirements.py,sha256=wcV99aXQIL8t6gIeUO0EgX9c_hA0IV3rg2Ar1g1SYjg,904
|
|
156
156
|
tests/mocks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
157
|
-
acai_aws-2.
|
|
158
|
-
acai_aws-2.
|
|
159
|
-
acai_aws-2.
|
|
160
|
-
acai_aws-2.
|
|
157
|
+
acai_aws-2.3.0.dist-info/METADATA,sha256=R1dle_WYWbBAOHTz8LcghQL7VgCj5MkIkKFdNtRtlG8,15175
|
|
158
|
+
acai_aws-2.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
159
|
+
acai_aws-2.3.0.dist-info/top_level.txt,sha256=A6vdhfU7MqNqO9rGdH1Z2EEqpnbIIyb4PsHJbRktbbI,15
|
|
160
|
+
acai_aws-2.3.0.dist-info/RECORD,,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
1
3
|
import os
|
|
4
|
+
from contextlib import redirect_stdout
|
|
2
5
|
from unittest import TestCase, mock
|
|
3
6
|
|
|
4
7
|
from acai_aws.common import logger
|
|
@@ -54,6 +57,29 @@ class LoggerTest(TestCase):
|
|
|
54
57
|
except Exception as error:
|
|
55
58
|
logger.log(level='ERROR', log=error)
|
|
56
59
|
|
|
60
|
+
@mock.patch.dict(os.environ, {'RUN_MODE': 'SEE-LOGS', 'LOG_STAGE_VARIABLE': 'STAGE', 'STAGE': 'local', 'LOG_FORMAT': ' inline '})
|
|
61
|
+
def test_logger_logs_error_inline_with_messy_env(self):
|
|
62
|
+
logger.log(level='INFO', log={'message': 'inline-format'})
|
|
63
|
+
|
|
64
|
+
@mock.patch.dict(os.environ, {'RUN_MODE': 'SEE-LOGS', 'LOG_STAGE_VARIABLE': 'STAGE', 'STAGE': 'local', 'LOG_FORMAT': 'JSON'})
|
|
65
|
+
def test_logger_json_output(self):
|
|
66
|
+
buffer = io.StringIO()
|
|
67
|
+
with redirect_stdout(buffer):
|
|
68
|
+
logger.log(level='WARN', log={'json': True})
|
|
69
|
+
log_output = buffer.getvalue().strip()
|
|
70
|
+
parsed = json.loads(log_output)
|
|
71
|
+
self.assertEqual('WARN', parsed['level'])
|
|
72
|
+
self.assertEqual({'json': True}, parsed['log'])
|
|
73
|
+
|
|
74
|
+
@mock.patch.dict(os.environ, {'RUN_MODE': 'SEE-LOGS', 'LOG_STAGE_VARIABLE': 'STAGE', 'STAGE': 'local', 'LOG_FORMAT': 'INLINE'})
|
|
75
|
+
def test_logger_inline_output(self):
|
|
76
|
+
buffer = io.StringIO()
|
|
77
|
+
with redirect_stdout(buffer):
|
|
78
|
+
logger.log(level='INFO', log={'inline': True})
|
|
79
|
+
log_output = buffer.getvalue().strip()
|
|
80
|
+
self.assertTrue(log_output.startswith('INFO|'))
|
|
81
|
+
self.assertIn("inline': True", log_output)
|
|
82
|
+
|
|
57
83
|
@mock.patch.dict(os.environ, {'RUN_MODE': 'SEE-LOGS', 'LOG_STAGE_VARIABLE': 'STAGE', 'STAGE': 'local'})
|
|
58
84
|
def test_logger_logs_error_as_object(self):
|
|
59
85
|
try:
|
|
@@ -96,4 +122,3 @@ class LoggerTest(TestCase):
|
|
|
96
122
|
@mock.patch.dict(os.environ, {'RUN_MODE': 'SEE-LOGS', 'LOG_STAGE_VARIABLE': 'STAGE', 'STAGE': 'local', 'LOG_LEVEL': 'ERROR', 'LOG_FORMAT': 'BAD'})
|
|
97
123
|
def test_logger_handles_bad_format(self):
|
|
98
124
|
logger.log(level='INFO', log={'INFO': 'ignore'})
|
|
99
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|