beans-logging 6.0.2__tar.gz → 6.0.3__tar.gz

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.
Files changed (33) hide show
  1. {beans_logging-6.0.2/src/beans_logging.egg-info → beans_logging-6.0.3}/PKG-INFO +1 -1
  2. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/__init__.py +2 -2
  3. beans_logging-6.0.3/src/beans_logging/__version__.py +1 -0
  4. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/_base.py +10 -28
  5. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/_utils.py +23 -21
  6. beans_logging-6.0.3/src/beans_logging/config.py +138 -0
  7. {beans_logging-6.0.2 → beans_logging-6.0.3/src/beans_logging.egg-info}/PKG-INFO +1 -1
  8. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging.egg-info/SOURCES.txt +2 -3
  9. beans_logging-6.0.2/auto.py +0 -6
  10. beans_logging-6.0.2/src/beans_logging/__version__.py +0 -1
  11. beans_logging-6.0.2/src/beans_logging/schemas.py +0 -173
  12. {beans_logging-6.0.2 → beans_logging-6.0.3}/.python-version +0 -0
  13. {beans_logging-6.0.2 → beans_logging-6.0.3}/LICENSE.txt +0 -0
  14. {beans_logging-6.0.2 → beans_logging-6.0.3}/README.md +0 -0
  15. {beans_logging-6.0.2 → beans_logging-6.0.3}/pyproject.toml +0 -0
  16. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements/requirements.build.txt +0 -0
  17. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements/requirements.dev.txt +0 -0
  18. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements/requirements.docs.txt +0 -0
  19. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements/requirements.fastapi.txt +0 -0
  20. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements/requirements.test.txt +0 -0
  21. {beans_logging-6.0.2 → beans_logging-6.0.3}/requirements.txt +0 -0
  22. {beans_logging-6.0.2 → beans_logging-6.0.3}/setup.cfg +0 -0
  23. {beans_logging-6.0.2 → beans_logging-6.0.3}/setup.py +0 -0
  24. /beans_logging-6.0.2/src/beans_logging/_consts.py → /beans_logging-6.0.3/src/beans_logging/_constants.py +0 -0
  25. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/_handlers.py +0 -0
  26. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/auto.py +0 -0
  27. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/filters.py +0 -0
  28. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/formats.py +0 -0
  29. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/rotation.py +0 -0
  30. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging/sinks.py +0 -0
  31. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging.egg-info/dependency_links.txt +0 -0
  32. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging.egg-info/requires.txt +0 -0
  33. {beans_logging-6.0.2 → beans_logging-6.0.3}/src/beans_logging.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beans_logging
3
- Version: 6.0.2
3
+ Version: 6.0.3
4
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
@@ -1,6 +1,6 @@
1
1
  from ._base import Logger, logger, LoggerLoader
2
- from .schemas import LoggerConfigPM
3
- from ._consts import WarnEnum
2
+ from .config import LoggerConfigPM
3
+ from ._constants import WarnEnum
4
4
  from .__version__ import __version__
5
5
 
6
6
 
@@ -0,0 +1 @@
1
+ __version__ = "6.0.3"
@@ -9,18 +9,13 @@ from typing import Any
9
9
  import yaml
10
10
  from loguru import logger
11
11
  from loguru._logger import Logger
12
- import pydantic
13
-
14
- if "2.0.0" <= pydantic.__version__:
15
- from pydantic import validate_call
16
- else:
17
- from pydantic import validate_arguments as validate_call
12
+ from pydantic import validate_call
18
13
 
19
14
  # Internal modules
20
15
  from ._utils import create_dir, deep_merge
21
16
  from ._handlers import InterceptHandler
22
17
  from .rotation import RotationChecker
23
- from .schemas import LoggerConfigPM
18
+ from .config import LoggerConfigPM
24
19
  from .sinks import std_sink
25
20
  from .formats import json_format
26
21
  from .filters import (
@@ -73,13 +68,13 @@ class LoggerLoader:
73
68
  """LoggerLoader constructor method.
74
69
 
75
70
  Args:
76
- config (LoggerConfigPM | dict | None], optional): New logger config to update loaded config.
71
+ config (LoggerConfigPM | dict | None, optional): New logger config to update loaded config.
77
72
  Defaults to None.
78
- config_file_path (str , optional): Logger config file path. Defaults to
73
+ config_file_path (str , optional): Logger config file path. Defaults to
79
74
  `LoggerLoader._CONFIG_FILE_PATH`.
80
- auto_config_file (bool , optional): Indicates whether to load logger config
75
+ auto_config_file (bool , optional): Indicates whether to load logger config
81
76
  file or not. Defaults to True.
82
- auto_load (bool , optional): Indicates whether to load logger
77
+ auto_load (bool , optional): Indicates whether to load logger
83
78
  handlers or not. Defaults to False.
84
79
  """
85
80
 
@@ -171,11 +166,7 @@ class LoggerLoader:
171
166
  """
172
167
 
173
168
  if isinstance(config, dict):
174
- if "2.0.0" <= pydantic.__version__:
175
- _config_dict = self.config.model_dump()
176
- else:
177
- _config_dict = self.config.dict()
178
-
169
+ _config_dict = self.config.model_dump()
179
170
  _merged_dict = deep_merge(_config_dict, config)
180
171
  try:
181
172
  self.config = LoggerConfigPM(**_merged_dict)
@@ -224,10 +215,7 @@ class LoggerLoader:
224
215
  return
225
216
 
226
217
  _new_config_dict = _new_config_dict["logger"]
227
- if "2.0.0" <= pydantic.__version__:
228
- _config_dict = self.config.model_dump()
229
- else:
230
- _config_dict = self.config.dict()
218
+ _config_dict = self.config.model_dump()
231
219
 
232
220
  _merged_dict = deep_merge(_config_dict, _new_config_dict)
233
221
  self.config = LoggerConfigPM(**_merged_dict)
@@ -247,10 +235,7 @@ class LoggerLoader:
247
235
  return
248
236
 
249
237
  _new_config_dict = _new_config_dict["logger"]
250
- if "2.0.0" <= pydantic.__version__:
251
- _config_dict = self.config.model_dump()
252
- else:
253
- _config_dict = self.config.dict()
238
+ _config_dict = self.config.model_dump()
254
239
 
255
240
  _merged_dict = deep_merge(_config_dict, _new_config_dict)
256
241
  self.config = LoggerConfigPM(**_merged_dict)
@@ -274,10 +259,7 @@ class LoggerLoader:
274
259
  # return
275
260
 
276
261
  # _new_config_dict = _new_config_dict["logger"]
277
- # if "2.0.0" <= pydantic.__version__:
278
- # _config_dict = self.config.model_dump()
279
- # else:
280
- # _config_dict = self.config.dict()
262
+ # _config_dict = self.config.model_dump()
281
263
 
282
264
  # _merged_dict = deep_merge(_config_dict, _new_config_dict)
283
265
  # self.config = LoggerConfigPM(**_merged_dict)
@@ -4,14 +4,9 @@ import copy
4
4
  import errno
5
5
 
6
6
  from loguru import logger
7
- import pydantic
7
+ from pydantic import validate_call
8
8
 
9
- if "2.0.0" <= pydantic.__version__:
10
- from pydantic import validate_call
11
- else:
12
- from pydantic import validate_arguments as validate_call
13
-
14
- from ._consts import WarnEnum
9
+ from ._constants import WarnEnum
15
10
 
16
11
 
17
12
  @validate_call
@@ -74,26 +69,33 @@ def deep_merge(dict1: dict, dict2: dict) -> dict:
74
69
  return _merged
75
70
 
76
71
 
77
- def get_default_logs_dir() -> str:
78
- """Return default logs directory path (current working directory + 'logs').
79
-
80
- Returns:
81
- str: Default logs directory path.
82
- """
83
-
84
- return os.path.join(os.getcwd(), "logs")
85
-
72
+ @validate_call
73
+ def get_slug_name(file_path: str | None = None) -> str:
74
+ """Slugify the file name from the given file path or the current script's file path.
86
75
 
87
- def get_app_name() -> str:
88
- """Return application name (sys.argv[0]).
76
+ Args:
77
+ file_path (str | None, optional): The file path to slugify. If None, uses the current script's file path.
78
+ Defaults to None.
89
79
 
90
80
  Returns:
91
- str: Application name.
81
+ str: The slugified file name.
92
82
  """
93
83
 
94
- return (
95
- os.path.splitext(os.path.basename(sys.argv[0]))[0]
84
+ if not file_path:
85
+ file_path = sys.argv[0]
86
+
87
+ _slug_name = (
88
+ os.path.splitext(os.path.basename(file_path))[0]
96
89
  .strip()
97
90
  .replace(" ", "-")
91
+ .replace("_", "-")
98
92
  .lower()
99
93
  )
94
+ return _slug_name
95
+
96
+
97
+ __all__ = [
98
+ "create_dir",
99
+ "deep_merge",
100
+ "get_slug_name",
101
+ ]
@@ -0,0 +1,138 @@
1
+ import os
2
+ import datetime
3
+ from typing import Any
4
+ from typing_extensions import Self
5
+
6
+ from pydantic import BaseModel, Field, field_validator, model_validator, ConfigDict
7
+
8
+ from ._constants import LogLevelEnum
9
+ from ._utils import get_slug_name
10
+
11
+
12
+ class ExtraBaseModel(BaseModel):
13
+ model_config = ConfigDict(extra="allow")
14
+
15
+
16
+ class StdHandlerConfigPM(ExtraBaseModel):
17
+ enabled: bool = Field(default=True)
18
+
19
+
20
+ class StreamConfigPM(ExtraBaseModel):
21
+ use_color: bool = Field(default=True)
22
+ use_icon: bool = Field(default=False)
23
+ format_str: str = Field(
24
+ default=(
25
+ "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: "
26
+ "<level>{message}</level>"
27
+ ),
28
+ min_length=8,
29
+ max_length=512,
30
+ )
31
+ std_handler: StdHandlerConfigPM = Field(default_factory=StdHandlerConfigPM)
32
+
33
+
34
+ class LogHandlersConfigPM(ExtraBaseModel):
35
+ enabled: bool = Field(default=False)
36
+ format_str: str = Field(
37
+ default="[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}",
38
+ min_length=8,
39
+ max_length=512,
40
+ )
41
+ log_path: str = Field(
42
+ default="{app_name}.std.all.log", min_length=4, max_length=1024
43
+ )
44
+ err_path: str = Field(
45
+ default="{app_name}.std.err.log", min_length=4, max_length=1024
46
+ )
47
+
48
+ @model_validator(mode="after")
49
+ def _check_log_path(self) -> Self:
50
+ if self.log_path == self.err_path:
51
+ raise ValueError(
52
+ f"`log_path` and `err_path` attributes have same value: '{self.log_path}', must be different!"
53
+ )
54
+
55
+ return self
56
+
57
+
58
+ class JsonHandlersConfigPM(ExtraBaseModel):
59
+ enabled: bool = Field(default=False)
60
+ use_custom: bool = Field(default=False)
61
+ log_path: str = Field(
62
+ default="{app_name}.json.all.log", min_length=4, max_length=1024
63
+ )
64
+ err_path: str = Field(
65
+ default="{app_name}.json.err.log", min_length=4, max_length=1024
66
+ )
67
+
68
+ @model_validator(mode="after")
69
+ def _check_log_path(self) -> Self:
70
+ if self.log_path == self.err_path:
71
+ raise ValueError(
72
+ f"`log_path` and `err_path` attributes have same value: '{self.log_path}', must be different!"
73
+ )
74
+
75
+ return self
76
+
77
+
78
+ class FileConfigPM(ExtraBaseModel):
79
+ logs_dir: str = Field(
80
+ default_factory=lambda: os.path.join(os.getcwd(), "logs"),
81
+ min_length=2,
82
+ max_length=1024,
83
+ )
84
+ rotate_size: int = Field(
85
+ default=10_000_000, ge=1_000, lt=1_000_000_000 # 10MB = 10 * 1000 * 1000
86
+ )
87
+ rotate_time: datetime.time = Field(default_factory=lambda: datetime.time(0, 0, 0))
88
+ backup_count: int = Field(default=90, ge=1)
89
+ encoding: str = Field(default="utf8", min_length=2, max_length=31)
90
+ log_handlers: LogHandlersConfigPM = Field(default_factory=LogHandlersConfigPM)
91
+ json_handlers: JsonHandlersConfigPM = Field(default_factory=JsonHandlersConfigPM)
92
+
93
+ @field_validator("rotate_time", mode="before")
94
+ @classmethod
95
+ def _check_rotate_time(cls, val: Any) -> Any:
96
+ if isinstance(val, str):
97
+ val = datetime.time.fromisoformat(val)
98
+
99
+ return val
100
+
101
+
102
+ class AutoLoadConfigPM(ExtraBaseModel):
103
+ enabled: bool = Field(default=True)
104
+ only_base: bool = Field(default=False)
105
+ ignore_modules: list[str] = Field(default=[])
106
+
107
+
108
+ class InterceptConfigPM(ExtraBaseModel):
109
+ auto_load: AutoLoadConfigPM = Field(default_factory=AutoLoadConfigPM)
110
+ include_modules: list[str] = Field(default=[])
111
+ mute_modules: list[str] = Field(default=[])
112
+
113
+
114
+ class ExtraConfigPM(ExtraBaseModel):
115
+ pass
116
+
117
+
118
+ class LoggerConfigPM(ExtraBaseModel):
119
+ app_name: str = Field(default_factory=get_slug_name, min_length=1, max_length=128)
120
+ level: LogLevelEnum = Field(default=LogLevelEnum.INFO)
121
+ use_backtrace: bool = Field(default=True)
122
+ use_diagnose: bool = Field(default=False)
123
+ stream: StreamConfigPM = Field(default_factory=StreamConfigPM)
124
+ file: FileConfigPM = Field(default_factory=FileConfigPM)
125
+ intercept: InterceptConfigPM = Field(default_factory=InterceptConfigPM)
126
+ extra: ExtraConfigPM | None = Field(default_factory=ExtraConfigPM)
127
+
128
+
129
+ __all__ = [
130
+ "StdHandlerConfigPM",
131
+ "StreamConfigPM",
132
+ "LogHandlersConfigPM",
133
+ "JsonHandlersConfigPM",
134
+ "FileConfigPM",
135
+ "AutoLoadConfigPM",
136
+ "InterceptConfigPM",
137
+ "LoggerConfigPM",
138
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beans_logging
3
- Version: 6.0.2
3
+ Version: 6.0.3
4
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
@@ -1,7 +1,6 @@
1
1
  .python-version
2
2
  LICENSE.txt
3
3
  README.md
4
- auto.py
5
4
  pyproject.toml
6
5
  requirements.txt
7
6
  setup.cfg
@@ -20,14 +19,14 @@ requirements/requirements.test.txt
20
19
  src/beans_logging/__init__.py
21
20
  src/beans_logging/__version__.py
22
21
  src/beans_logging/_base.py
23
- src/beans_logging/_consts.py
22
+ src/beans_logging/_constants.py
24
23
  src/beans_logging/_handlers.py
25
24
  src/beans_logging/_utils.py
26
25
  src/beans_logging/auto.py
26
+ src/beans_logging/config.py
27
27
  src/beans_logging/filters.py
28
28
  src/beans_logging/formats.py
29
29
  src/beans_logging/rotation.py
30
- src/beans_logging/schemas.py
31
30
  src/beans_logging/sinks.py
32
31
  src/beans_logging.egg-info/PKG-INFO
33
32
  src/beans_logging.egg-info/SOURCES.txt
@@ -1,6 +0,0 @@
1
- # flake8: noqa
2
-
3
- try:
4
- from .src.beans_logging.auto import *
5
- except ImportError:
6
- from src.beans_logging.auto import *
@@ -1 +0,0 @@
1
- __version__ = "6.0.2"
@@ -1,173 +0,0 @@
1
- import datetime
2
-
3
-
4
- import pydantic
5
- from pydantic import BaseModel, constr, Field
6
-
7
- if "2.0.0" <= pydantic.__version__:
8
- from pydantic import field_validator, model_validator, ConfigDict
9
- else:
10
- from pydantic import validator, root_validator
11
-
12
-
13
- from ._consts import LogLevelEnum
14
- from ._utils import get_default_logs_dir, get_app_name
15
-
16
-
17
- class ExtraBaseModel(BaseModel):
18
- if "2.0.0" <= pydantic.__version__:
19
- model_config = ConfigDict(extra="allow")
20
- else:
21
-
22
- class Config:
23
- extra = "allow"
24
-
25
-
26
- class StdHandlerPM(ExtraBaseModel):
27
- enabled: bool = Field(default=True)
28
-
29
-
30
- class StreamPM(ExtraBaseModel):
31
- use_color: bool = Field(default=True)
32
- use_icon: bool = Field(default=False)
33
- format_str: constr(strip_whitespace=True) = Field(
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
- min_length=3,
39
- max_length=511,
40
- )
41
- std_handler: StdHandlerPM = Field(default_factory=StdHandlerPM)
42
-
43
-
44
- class LogHandlersPM(ExtraBaseModel):
45
- enabled: bool = Field(default=False)
46
- format_str: constr(strip_whitespace=True) = Field(
47
- default="[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}",
48
- min_length=4,
49
- max_length=511,
50
- )
51
- log_path: constr(strip_whitespace=True) = Field(
52
- default="{app_name}.std.all.log", min_length=4, max_length=1023
53
- )
54
- err_path: constr(strip_whitespace=True) = Field(
55
- default="{app_name}.std.err.log", min_length=4, max_length=1023
56
- )
57
-
58
- if "2.0.0" <= pydantic.__version__:
59
-
60
- @model_validator(mode="after")
61
- def _check_log_path(self) -> "LogHandlersPM":
62
- if self.log_path == self.err_path:
63
- raise ValueError(
64
- f"`log_path` and `err_path` attributes are same: '{self.log_path}', must be different!"
65
- )
66
- return self
67
-
68
- else:
69
-
70
- @root_validator
71
- def _check_log_path(cls, values):
72
- _log_path, _err_path = values.get("log_path"), values.get("err_path")
73
- if _log_path == _err_path:
74
- raise ValueError(
75
- f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
76
- )
77
- return values
78
-
79
-
80
- class JsonHandlersPM(ExtraBaseModel):
81
- enabled: bool = Field(default=False)
82
- use_custom: bool = Field(default=False)
83
- log_path: constr(strip_whitespace=True) = Field(
84
- default="{app_name}.json.all.log", min_length=4, max_length=1023
85
- )
86
- err_path: constr(strip_whitespace=True) = Field(
87
- default="{app_name}.json.err.log", min_length=4, max_length=1023
88
- )
89
-
90
- if "2.0.0" <= pydantic.__version__:
91
-
92
- @model_validator(mode="after")
93
- def _check_log_path(self) -> "JsonHandlersPM":
94
- if self.log_path == self.err_path:
95
- raise ValueError(
96
- f"`log_path` and `err_path` attributes are same: '{self.log_path}', must be different!"
97
- )
98
- return self
99
-
100
- else:
101
-
102
- @root_validator
103
- def _check_log_path(cls, values):
104
- _log_path, _err_path = values.get("log_path"), values.get("err_path")
105
- if _log_path == _err_path:
106
- raise ValueError(
107
- f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
108
- )
109
- return values
110
-
111
-
112
- class FilePM(ExtraBaseModel):
113
- logs_dir: constr(strip_whitespace=True) = Field(
114
- default_factory=get_default_logs_dir, min_length=2, max_length=1023
115
- )
116
- rotate_size: int = Field(
117
- default=10_000_000, ge=1_000, lt=1_000_000_000 # 10MB = 10 * 1000 * 1000
118
- )
119
- rotate_time: datetime.time = Field(datetime.time(0, 0, 0))
120
- backup_count: int = Field(default=90, ge=1)
121
- encoding: constr(strip_whitespace=True) = Field(
122
- default="utf8", min_length=2, max_length=31
123
- )
124
- log_handlers: LogHandlersPM = Field(default_factory=LogHandlersPM)
125
- json_handlers: JsonHandlersPM = Field(default_factory=JsonHandlersPM)
126
-
127
- if "2.0.0" <= pydantic.__version__:
128
-
129
- @field_validator("rotate_time", mode="before")
130
- @classmethod
131
- def _check_rotate_time(cls, val):
132
- if isinstance(val, str):
133
- val = datetime.time.fromisoformat(val)
134
- return val
135
-
136
- else:
137
-
138
- @validator("rotate_time", pre=True, always=True)
139
- def _check_rotate_time(cls, val):
140
- if val and isinstance(val, str):
141
- val = datetime.time.fromisoformat(val)
142
- return val
143
-
144
-
145
- class AutoLoadPM(ExtraBaseModel):
146
- enabled: bool = Field(default=True)
147
- only_base: bool = Field(default=False)
148
- ignore_modules: list[str] = Field(default=[])
149
-
150
-
151
- class InterceptPM(ExtraBaseModel):
152
- auto_load: AutoLoadPM = Field(default_factory=AutoLoadPM)
153
- include_modules: list[str] = Field(default=[])
154
- mute_modules: list[str] = Field(default=[])
155
-
156
-
157
- class ExtraPM(ExtraBaseModel):
158
- pass
159
-
160
-
161
- class LoggerConfigPM(ExtraBaseModel):
162
- app_name: constr(strip_whitespace=True) = Field(
163
- default_factory=get_app_name,
164
- min_length=1,
165
- max_length=127,
166
- )
167
- level: LogLevelEnum = Field(default=LogLevelEnum.INFO)
168
- use_backtrace: bool = Field(default=True)
169
- use_diagnose: bool = Field(default=False)
170
- stream: StreamPM = Field(default_factory=StreamPM)
171
- file: FilePM = Field(default_factory=FilePM)
172
- intercept: InterceptPM = Field(default_factory=InterceptPM)
173
- extra: ExtraPM = Field(default_factory=ExtraPM)
File without changes
File without changes
File without changes
File without changes