beans-logging 6.0.1__py3-none-any.whl → 6.0.2__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.
beans_logging/__init__.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  from ._base import Logger, logger, LoggerLoader
4
2
  from .schemas import LoggerConfigPM
5
3
  from ._consts import WarnEnum
@@ -1 +1 @@
1
- __version__ = "6.0.1"
1
+ __version__ = "6.0.2"
beans_logging/_base.py CHANGED
@@ -1,13 +1,11 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ## Standard libraries
1
+ # Standard libraries
4
2
  import os
5
3
  import copy
6
4
  import json
7
5
  import logging
8
- from typing import Union, Dict, Any
6
+ from typing import Any
9
7
 
10
- ## Third-party libraries
8
+ # Third-party libraries
11
9
  import yaml
12
10
  from loguru import logger
13
11
  from loguru._logger import Logger
@@ -18,7 +16,7 @@ if "2.0.0" <= pydantic.__version__:
18
16
  else:
19
17
  from pydantic import validate_arguments as validate_call
20
18
 
21
- ## Internal modules
19
+ # Internal modules
22
20
  from ._utils import create_dir, deep_merge
23
21
  from ._handlers import InterceptHandler
24
22
  from .rotation import RotationChecker
@@ -67,7 +65,7 @@ class LoggerLoader:
67
65
  @validate_call
68
66
  def __init__(
69
67
  self,
70
- config: Union[LoggerConfigPM, Dict[str, Any], None] = None,
68
+ config: LoggerConfigPM | dict[str, Any] | None = None,
71
69
  config_file_path: str = _CONFIG_FILE_PATH,
72
70
  auto_config_file: bool = True,
73
71
  auto_load: bool = False,
@@ -75,12 +73,14 @@ class LoggerLoader:
75
73
  """LoggerLoader constructor method.
76
74
 
77
75
  Args:
78
- config (Union[LoggerConfigPM,
79
- dict,
80
- None ], optional): New logger config to update loaded config. Defaults to None.
81
- config_file_path (str , optional): Logger config file path. Defaults to `LoggerLoader._CONFIG_FILE_PATH`.
82
- auto_config_file (bool , optional): Indicates whether to load logger config file or not. Defaults to True.
83
- auto_load (bool , optional): Indicates whether to load logger handlers or not. Defaults to False.
76
+ config (LoggerConfigPM | dict | None], optional): New logger config to update loaded config.
77
+ Defaults to None.
78
+ config_file_path (str , optional): Logger config file path. Defaults to
79
+ `LoggerLoader._CONFIG_FILE_PATH`.
80
+ auto_config_file (bool , optional): Indicates whether to load logger config
81
+ file or not. Defaults to True.
82
+ auto_load (bool , optional): Indicates whether to load logger
83
+ handlers or not. Defaults to False.
84
84
  """
85
85
 
86
86
  self.handlers_map = {"default": 0}
@@ -125,9 +125,7 @@ class LoggerLoader:
125
125
  return logger
126
126
 
127
127
  @validate_call
128
- def remove_handler(
129
- self, handler: Union[str, None] = None, handler_type: str = "NAME"
130
- ):
128
+ def remove_handler(self, handler: str | None = None, handler_type: str = "NAME"):
131
129
  """Remove all handlers or specific handler by name or id from logger.
132
130
 
133
131
  Raises:
@@ -162,7 +160,7 @@ class LoggerLoader:
162
160
  self.handlers_map.clear()
163
161
 
164
162
  @validate_call
165
- def update_config(self, config: Union[LoggerConfigPM, Dict[str, Any]]):
163
+ def update_config(self, config: LoggerConfigPM | dict[str, Any]):
166
164
  """Update logger config with new config.
167
165
 
168
166
  Args:
@@ -213,13 +211,11 @@ class LoggerLoader:
213
211
  # elif self.config_file_path.lower().endswith(".toml"):
214
212
  # _file_format = "TOML"
215
213
 
216
- ## Loading config from file, if it's exits:
214
+ # Loading config from file, if it's exits:
217
215
  if os.path.isfile(self.config_file_path):
218
216
  if _file_format == "YAML":
219
217
  try:
220
- with open(
221
- self.config_file_path, "r", encoding="utf-8"
222
- ) as _config_file:
218
+ with open(self.config_file_path, encoding="utf-8") as _config_file:
223
219
  _new_config_dict = yaml.safe_load(_config_file) or {}
224
220
  if "logger" not in _new_config_dict:
225
221
  logger.warning(
@@ -242,9 +238,7 @@ class LoggerLoader:
242
238
  raise
243
239
  elif _file_format == "JSON":
244
240
  try:
245
- with open(
246
- self.config_file_path, "r", encoding="utf-8"
247
- ) as _config_file:
241
+ with open(self.config_file_path, encoding="utf-8") as _config_file:
248
242
  _new_config_dict = json.load(_config_file) or {}
249
243
  if "logger" not in _new_config_dict:
250
244
  logger.warning(
@@ -296,7 +290,7 @@ class LoggerLoader:
296
290
  def _check_env(self):
297
291
  """Check environment variables for logger config."""
298
292
 
299
- ## Checking environment for DEBUG option:
293
+ # Checking environment for DEBUG option:
300
294
  _is_debug = False
301
295
  _ENV = str(os.getenv("ENV")).strip().lower()
302
296
  _DEBUG = str(os.getenv("DEBUG")).strip().lower()
@@ -314,7 +308,7 @@ class LoggerLoader:
314
308
  self.config.file.logs_dir = os.getenv("BEANS_LOGGING_LOGS_DIR")
315
309
 
316
310
  # if self.config.stream.use_color:
317
- # ## Checking terminal could support xterm colors:
311
+ # # Checking terminal could support xterm colors:
318
312
  # _TERM = str(os.getenv("TERM")).strip()
319
313
  # if not "xterm" in _TERM:
320
314
  # self.config.stream.use_color = False
@@ -536,7 +530,7 @@ class LoggerLoader:
536
530
 
537
531
  _intercept_handler = InterceptHandler()
538
532
 
539
- ## Intercepting all logs from standard (root logger) logging:
533
+ # Intercepting all logs from standard (root logger) logging:
540
534
  logging.basicConfig(handlers=[_intercept_handler], level=0, force=True)
541
535
 
542
536
  _intercepted_modules = set()
@@ -579,10 +573,10 @@ class LoggerLoader:
579
573
  f"Intercepted modules: {list(_intercepted_modules)}; Muted modules: {list(_muted_modules)};"
580
574
  )
581
575
 
582
- ### ATTRIBUTES ###
583
- ## handlers_map ##
576
+ # ATTRIBUTES #
577
+ # handlers_map
584
578
  @property
585
- def handlers_map(self) -> Dict[str, int]:
579
+ def handlers_map(self) -> dict[str, int]:
586
580
  try:
587
581
  return self.__handlers_map
588
582
  except AttributeError:
@@ -591,7 +585,7 @@ class LoggerLoader:
591
585
  return self.__handlers_map
592
586
 
593
587
  @handlers_map.setter
594
- def handlers_map(self, handlers_map: Dict[str, int]):
588
+ def handlers_map(self, handlers_map: dict[str, int]):
595
589
  if not isinstance(handlers_map, dict):
596
590
  raise TypeError(
597
591
  f"`handlers_map` attribute type {type(handlers_map)} is invalid, must be <dict>!."
@@ -599,9 +593,9 @@ class LoggerLoader:
599
593
 
600
594
  self.__handlers_map = copy.deepcopy(handlers_map)
601
595
 
602
- ## handlers_map ##
596
+ # handlers_map
603
597
 
604
- ## config ##
598
+ # config
605
599
  @property
606
600
  def config(self) -> LoggerConfigPM:
607
601
  try:
@@ -620,9 +614,9 @@ class LoggerLoader:
620
614
 
621
615
  self.__config = copy.deepcopy(config)
622
616
 
623
- ## config ##
617
+ # config
624
618
 
625
- ## config_file_path ##
619
+ # config_file_path
626
620
  @property
627
621
  def config_file_path(self) -> str:
628
622
  try:
@@ -648,11 +642,13 @@ class LoggerLoader:
648
642
  ):
649
643
  if not config_file_path.lower().endswith(".toml"):
650
644
  raise NotImplementedError(
651
- f"`config_file_path` attribute value '{config_file_path}' is invalid, TOML file format is not supported yet!"
645
+ f"`config_file_path` attribute value '{config_file_path}' is invalid, "
646
+ f"TOML file format is not supported yet!"
652
647
  )
653
648
 
654
649
  raise ValueError(
655
- f"`config_file_path` attribute value '{config_file_path}' is invalid, file must be '.yml', '.yaml' or '.json' format!"
650
+ f"`config_file_path` attribute value '{config_file_path}' is invalid, "
651
+ f"file must be '.yml', '.yaml' or '.json' format!"
656
652
  )
657
653
 
658
654
  if not os.path.isabs(config_file_path):
@@ -660,5 +656,5 @@ class LoggerLoader:
660
656
 
661
657
  self.__config_file_path = config_file_path
662
658
 
663
- ## config_file_path ##
664
- ### ATTRIBUTES ###
659
+ # config_file_path
660
+ # ATTRIBUTES #
beans_logging/_consts.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  from enum import Enum
4
2
 
5
3
 
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import sys
4
2
  import logging
5
3
  from logging import LogRecord
@@ -25,13 +23,13 @@ class InterceptHandler(logging.Handler):
25
23
  record (LogRecord, required): Log needs to be handled.
26
24
  """
27
25
 
28
- ## Get corresponding Loguru level if it exists
26
+ # Get corresponding Loguru level if it exists
29
27
  try:
30
28
  _level = logger.level(record.levelname).name
31
29
  except ValueError:
32
30
  _level = record.levelno
33
31
 
34
- ## Find caller from where originated the logged message
32
+ # Find caller from where originated the logged message
35
33
  _frame, _depth = sys._getframe(6), 6
36
34
  while _frame and _frame.f_code.co_filename == logging.__file__:
37
35
  _frame = _frame.f_back
beans_logging/_utils.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import os
4
2
  import sys
5
3
  import copy
@@ -22,7 +20,8 @@ def create_dir(create_dir: str, warn_mode: WarnEnum = WarnEnum.DEBUG):
22
20
 
23
21
  Args:
24
22
  create_dir (str, required): Create directory path.
25
- warn_mode (str, optional): Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to "DEBUG".
23
+ warn_mode (str, optional): Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'.
24
+ Defaults to "DEBUG".
26
25
  """
27
26
 
28
27
  if not os.path.isdir(create_dir):
beans_logging/auto.py CHANGED
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
1
+ # flake8: noqa
2
2
 
3
3
  import os
4
- from typing import Union
5
4
 
6
5
  from . import *
7
6
 
8
- logger_loader: Union[LoggerLoader, None] = None
7
+ logger_loader: LoggerLoader | None = None
9
8
  _DISABLE_DEFAULT_LOGGER = (
10
9
  str(os.getenv("BEANS_LOGGING_DISABLE_DEFAULT")).strip().lower()
11
10
  )
beans_logging/filters.py CHANGED
@@ -1,6 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
1
  def add_level_short(record: dict) -> dict:
5
2
  """Filter for adding short level name to log record.
6
3
 
beans_logging/formats.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import json
4
2
  import traceback
5
3
 
beans_logging/rotation.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import datetime
4
2
  from typing import TextIO
5
3
 
@@ -35,8 +33,8 @@ class RotationChecker:
35
33
  )
36
34
 
37
35
  if _current_dtime >= self._dtime_limit:
38
- ## The current time is already past the target time so it would rotate already.
39
- ## Add one day to prevent an immediate rotation.
36
+ # The current time is already past the target time so it would rotate already.
37
+ # Add one day to prevent an immediate rotation.
40
38
  self._dtime_limit += datetime.timedelta(days=1)
41
39
 
42
40
  def should_rotate(self, message: Message, file: TextIO) -> bool:
beans_logging/schemas.py CHANGED
@@ -1,7 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import datetime
4
- from typing import List
5
2
 
6
3
 
7
4
  import pydantic
@@ -34,7 +31,10 @@ class StreamPM(ExtraBaseModel):
34
31
  use_color: bool = Field(default=True)
35
32
  use_icon: bool = Field(default=False)
36
33
  format_str: constr(strip_whitespace=True) = Field(
37
- default="[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>",
34
+ default=(
35
+ "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: "
36
+ "<level>{message}</level>"
37
+ ),
38
38
  min_length=3,
39
39
  max_length=511,
40
40
  )
@@ -145,13 +145,13 @@ class FilePM(ExtraBaseModel):
145
145
  class AutoLoadPM(ExtraBaseModel):
146
146
  enabled: bool = Field(default=True)
147
147
  only_base: bool = Field(default=False)
148
- ignore_modules: List[str] = Field(default=[])
148
+ ignore_modules: list[str] = Field(default=[])
149
149
 
150
150
 
151
151
  class InterceptPM(ExtraBaseModel):
152
152
  auto_load: AutoLoadPM = Field(default_factory=AutoLoadPM)
153
- include_modules: List[str] = Field(default=[])
154
- mute_modules: List[str] = Field(default=[])
153
+ include_modules: list[str] = Field(default=[])
154
+ mute_modules: list[str] = Field(default=[])
155
155
 
156
156
 
157
157
  class ExtraPM(ExtraBaseModel):
beans_logging/sinks.py CHANGED
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  import sys
4
2
 
5
3
  from loguru._handler import Message
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beans_logging
3
- Version: 6.0.1
4
- Summary: 'beans-logging' is a python package for simple logger and easily managing logging.
3
+ Version: 6.0.2
4
+ Summary: 'beans-logging' is a python package for simple logger and easily managing logs.
5
5
  Author-email: Batkhuu Byambajav <batkhuu10@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/bybatkhuu/module-python-logging
7
7
  Project-URL: Documentation, https://pylogging-docs.bybatkhuu.dev
@@ -100,7 +100,7 @@ It is a `Loguru` based custom logging package for python projects.
100
100
  [OPTIONAL] For **DEVELOPMENT** environment:
101
101
 
102
102
  - Install [**git**](https://git-scm.com/downloads)
103
- - Setup an [**SSH key**](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh) ([video tutorial](https://www.youtube.com/watch?v=snCP3c7wXw0))
103
+ - Setup an [**SSH key**](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh)
104
104
 
105
105
  ### 2. 📥 Download or clone the repository
106
106
 
@@ -213,7 +213,7 @@ logger.info("Logging info.")
213
213
 
214
214
  ### **Simple**
215
215
 
216
- [**`configs/logger.yml`**](https://github.com/bybatkhuu/module-python-logging/blob/main/examples/simple/configs/logger.yml):
216
+ [**`configs/logger.yml`**](./examples/simple/configs/logger.yml):
217
217
 
218
218
  ```yml
219
219
  logger:
@@ -226,9 +226,11 @@ logger:
226
226
  enabled: true
227
227
  ```
228
228
 
229
- [**`main.py`**](https://github.com/bybatkhuu/module-python-logging/blob/main/examples/simple/main.py):
229
+ [**`main.py`**](./examples/simple/main.py):
230
230
 
231
231
  ```python
232
+ #!/usr/bin/env python
233
+
232
234
  from beans_logging.auto import logger
233
235
 
234
236
 
@@ -240,10 +242,12 @@ logger.warning("Warning something.")
240
242
  logger.error("Error occured.")
241
243
  logger.critical("CRITICAL ERROR.")
242
244
 
245
+
243
246
  def divide(a, b):
244
247
  _result = a / b
245
248
  return _result
246
249
 
250
+
247
251
  def nested(c):
248
252
  try:
249
253
  divide(5, c)
@@ -251,13 +255,14 @@ def nested(c):
251
255
  logger.error(err)
252
256
  raise
253
257
 
258
+
254
259
  try:
255
260
  nested(0)
256
- except Exception as err:
261
+ except Exception:
257
262
  logger.exception("Show me, what value is wrong:")
258
263
  ```
259
264
 
260
- Run the [**`examples/simple`**](https://github.com/bybatkhuu/module-python-logging/tree/main/examples/simple):
265
+ Run the [**`examples/simple`**](./examples/simple):
261
266
 
262
267
  ```sh
263
268
  cd ./examples/simple
@@ -303,7 +308,7 @@ ZeroDivisionError: division by zero
303
308
 
304
309
  ## ⚙️ Configuration
305
310
 
306
- [**`templates/configs/config.yml`**](./templates/configs/config.yml):
311
+ [**`templates/configs/logger.yml`**](./templates/configs/logger.yml):
307
312
 
308
313
  ```yaml
309
314
  logger:
@@ -0,0 +1,17 @@
1
+ beans_logging/__init__.py,sha256=Ax1f3I26MSEorCBnkPVcuzEWN7IoJZuzPdVjCukvUv0,272
2
+ beans_logging/__version__.py,sha256=lze97Y7ToUnpENKGAhOoSKx1zlZQe6ZfCSr8M50_K1g,22
3
+ beans_logging/_base.py,sha256=fKwGgtkbUzg2Wtfb5XwIGF5UU56iPOT-R6OD3wqIBws,24645
4
+ beans_logging/_consts.py,sha256=OqSvH2IvsUSbvIgthHeiv92i9CHXKYvO-PCb_DsMANI,320
5
+ beans_logging/_handlers.py,sha256=cz2jcJR0MuVHWWNRAFT617njC_18Q56lNcgKIxLmFys,1106
6
+ beans_logging/_utils.py,sha256=Vk8UT2mPTanP4KuLnxKk6Pv-Nr8iWDom0TwCxHb5EhA,2757
7
+ beans_logging/auto.py,sha256=YQMfmWK6mFEwqabhimj8ZA_yStKZCDQEvteKv2UIbEA,494
8
+ beans_logging/filters.py,sha256=iikVBMIhAF_DP1F0X0GJ7GUOvP-JdcH_CxAsYuz0UxM,3343
9
+ beans_logging/formats.py,sha256=WTIDP0uJL9J9bcFZ2_Qe8zlw_l4SrE2k2agPLvrjfMM,1324
10
+ beans_logging/rotation.py,sha256=t-ORXq7x4tDbvz8XMjCCuDZ6cUApcu3SBQzfgTwHQU8,2110
11
+ beans_logging/schemas.py,sha256=CBaztXAnoqKiL3poLz0ymR8c0EdqKo4rJ_K4kXwDqjo,5631
12
+ beans_logging/sinks.py,sha256=t2U4v95H_tV2ci6YS8aKCnTUKVRxEcsLnB55qn4wyrQ,331
13
+ beans_logging-6.0.2.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
14
+ beans_logging-6.0.2.dist-info/METADATA,sha256=E56H2f4nvUltwTr-k3ZfTrTsdeleUpGcb0FmtvaDInk,12652
15
+ beans_logging-6.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ beans_logging-6.0.2.dist-info/top_level.txt,sha256=lx8JEqYGNha1sYbVrTtMo2Z01A7Shq8hX6bfsuKLTG8,14
17
+ beans_logging-6.0.2.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- beans_logging/__init__.py,sha256=TxuozMCLvGkG7sATP2uFCQws6TRqwp36yc08zUVGcb4,297
2
- beans_logging/__version__.py,sha256=unmO3xtN2S1e9meUbIjG3AZVyKxUe4HSZNXDOcpZRJg,22
3
- beans_logging/_base.py,sha256=_4mllOq9hr65Aq7OUkQU3OPTtPvmpv-4x47J6oWN9TI,24573
4
- beans_logging/_consts.py,sha256=b_-uytryZFCxlD2aKXzdS0oQpAsaK6JLi-w5bUeG1yE,345
5
- beans_logging/_handlers.py,sha256=WQjr-dGAnjsegI2LHJl_Fubxb0reSCr8A6IvR7eN8dk,1133
6
- beans_logging/_utils.py,sha256=Smb0cxkTdVxA-IE-oqi3sGhpsQdtNquQSw2bQxN0pDM,2742
7
- beans_logging/auto.py,sha256=Wyi4w4qZ9PNW2dDF19E8qoKuZVfhyAEl_rVPzMscVCM,534
8
- beans_logging/filters.py,sha256=YNUF5_0hE0XoPfLCi5wQFe1Qi7eLV0UaJUtCDwlG5ec,3369
9
- beans_logging/formats.py,sha256=gxyJT9ZUWQvjrL4x6fU5bLKybGsFkCpFDG5OpndqDhc,1349
10
- beans_logging/rotation.py,sha256=GspZX7wff_igZjbGSysCboz8fUgDHofGRL10OaNlZ3I,2137
11
- beans_logging/schemas.py,sha256=syMsmwbDvDE1odnaIX18PEIEpWyItfDDnisZr1AsOPs,5641
12
- beans_logging/sinks.py,sha256=C_y53i_QJuNZs_zBitb87d_tfsLhin2D9DtImPV5OHg,356
13
- beans_logging-6.0.1.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
14
- beans_logging-6.0.1.dist-info/METADATA,sha256=qbUyyqgbutJ9qHsPrFge6pIsXUeomPoQB-qkpgYto74,12877
15
- beans_logging-6.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- beans_logging-6.0.1.dist-info/top_level.txt,sha256=lx8JEqYGNha1sYbVrTtMo2Z01A7Shq8hX6bfsuKLTG8,14
17
- beans_logging-6.0.1.dist-info/RECORD,,