mlog-util 0.1.0__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.

Potentially problematic release.


This version of mlog-util might be problematic. Click here for more details.

@@ -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,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,6 @@
1
+ setup.py
2
+ mlog/__init__.py
3
+ mlog_util.egg-info/PKG-INFO
4
+ mlog_util.egg-info/SOURCES.txt
5
+ mlog_util.egg-info/dependency_links.txt
6
+ mlog_util.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ mlog
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="mlog-util",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ install_requires=[], # 依赖库
8
+ # author="may",
9
+ # author_email="no",
10
+ description="自用日志库",
11
+ # long_description=open("README.md", encoding="utf-8").read(),
12
+ # long_description_content_type="text/markdown",
13
+
14
+ classifiers=[
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ],
19
+ python_requires='>=3.6',
20
+ )