mlog-util 0.1.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.
Potentially problematic release.
This version of mlog-util might be problematic. Click here for more details.
mlog/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from rich.logging import RichHandler
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_logger(name=None, log_file=None, add_console=True, level=logging.INFO):
|
|
6
|
+
logger = logging.getLogger(name=name)
|
|
7
|
+
logger.setLevel(level) # 日志级别
|
|
8
|
+
|
|
9
|
+
logger.propagate = False # 不向 root logger 冒泡
|
|
10
|
+
|
|
11
|
+
has_console = any(isinstance(h, RichHandler) for h in logger.handlers)
|
|
12
|
+
has_file = any(isinstance(h, logging.FileHandler) for h in logger.handlers)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if add_console and not has_console:
|
|
16
|
+
# 控制台 Rich 日志
|
|
17
|
+
console_handler = RichHandler(rich_tracebacks=True)
|
|
18
|
+
console_formatter = logging.Formatter(
|
|
19
|
+
"%(message)s [%(name)s - %(asctime)s]",
|
|
20
|
+
datefmt="%Y-%m-%d %H:%M:%S"
|
|
21
|
+
)
|
|
22
|
+
console_handler.setFormatter(console_formatter)
|
|
23
|
+
logger.addHandler(console_handler)
|
|
24
|
+
|
|
25
|
+
# 文件日志
|
|
26
|
+
if log_file and not has_file:
|
|
27
|
+
file_handler = logging.FileHandler(log_file, encoding="utf-8")
|
|
28
|
+
file_formatter = logging.Formatter(
|
|
29
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
30
|
+
datefmt="%Y-%m-%d %H:%M:%S"
|
|
31
|
+
)
|
|
32
|
+
file_handler.setFormatter(file_formatter)
|
|
33
|
+
logger.addHandler(file_handler)
|
|
34
|
+
|
|
35
|
+
return logger
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
logger = get_logger()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlog-util
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 自用日志库
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Requires-Python: >=3.6
|
|
9
|
+
Dynamic: classifier
|
|
10
|
+
Dynamic: requires-python
|
|
11
|
+
Dynamic: summary
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
mlog/__init__.py,sha256=sEGvZvRJ8V4T9bN6DWbnIh8ajfFFyVgK-g81NwRYopo,1242
|
|
2
|
+
mlog_util-0.1.0.dist-info/METADATA,sha256=CahqeCeuLuCC4NI7XLDW8csdLHSDZN9a03hQPxxD07o,309
|
|
3
|
+
mlog_util-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
mlog_util-0.1.0.dist-info/top_level.txt,sha256=eywWczr0fGOSqRvRGQwBBTeunUvdU1Wy2odMkvMdAUg,5
|
|
5
|
+
mlog_util-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mlog
|