Coverage for afasi/__init__.py: 100.00%
37 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-21 13:35:37 +00:00
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-21 13:35:37 +00:00
1"""Fuzz a language by mixing up only few words."""
3import datetime as dti
4import logging
5import os
6import pathlib
7from typing import List, no_type_check
9# [[[fill git_describe()]]]
10__version__ = '2022.11.28+parent.63423cd2'
11# [[[end]]] (checksum: d6cbb972a54f39fd72aca87bc1189801)
12__version_info__ = tuple(
13 e if '-' not in e else e.split('-')[0] for part in __version__.split('+') for e in part.split('.') if e != 'parent'
14)
16APP_ALIAS = str(pathlib.Path(__file__).parent.name)
17APP_ENV = APP_ALIAS.upper()
18APP_NAME = locals()['__doc__']
19DEBUG = bool(os.getenv(f'{APP_ENV}_DEBUG', ''))
20VERBOSE = bool(os.getenv(f'{APP_ENV}_VERBOSE', ''))
21QUIET = False
22STRICT = bool(os.getenv(f'{APP_ENV}_STRICT', ''))
23ENCODING = 'utf-8'
24ENCODING_ERRORS_POLICY = 'ignore'
25DEFAULT_CONFIG_NAME = f'.{APP_ALIAS}.json'
27COMMA = ','
28DEFAULT_LF_ONLY = 'YES'
29log = logging.getLogger() # Module level logger is sufficient
30LOG_FOLDER = pathlib.Path('logs')
31LOG_FILE = f'{APP_ALIAS}.log'
32LOG_PATH = pathlib.Path(LOG_FOLDER, LOG_FILE) if LOG_FOLDER.is_dir() else pathlib.Path(LOG_FILE)
33LOG_LEVEL = logging.INFO
35TS_FORMAT_LOG = '%Y-%m-%dT%H:%M:%S'
36TS_FORMAT_PAYLOADS = '%Y-%m-%d %H:%M:%S.%f UTC'
38__all__: List[str] = [
39 'APP_ALIAS',
40 'APP_NAME',
41 'COMMA',
42 'DEBUG',
43 'ENCODING',
44 'log',
45]
48@no_type_check
49def formatTime_RFC3339(self, record, datefmt=None): # noqa
50 """HACK A DID ACK we could inject .astimezone() to localize ..."""
51 return dti.datetime.fromtimestamp(record.created, dti.timezone.utc).isoformat() # pragma: no cover
54@no_type_check
55def init_logger(name=None, level=None):
56 """Initialize module level logger"""
57 global log # pylint: disable=global-statement
59 log_format = {
60 'format': '%(asctime)s %(levelname)s [%(name)s]: %(message)s',
61 'datefmt': TS_FORMAT_LOG,
62 # 'filename': LOG_PATH,
63 'level': LOG_LEVEL if level is None else level,
64 }
65 logging.Formatter.formatTime = formatTime_RFC3339
66 logging.basicConfig(**log_format)
67 log = logging.getLogger(APP_ENV if name is None else name)
68 log.propagate = True
71init_logger(name=APP_ENV, level=logging.DEBUG if DEBUG else None)