cplogger 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.
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .venv/
7
+ .eggs/
8
+
9
+ .idea
10
+ .DS_Store
11
+ logs/
cplogger-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Honam Song
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.5
2
+ Name: cplogger
3
+ Version: 0.1.0
4
+ Summary: Color Print and logging
5
+ Project-URL: Homepage, https://github.com/HonamSong/cplogger
6
+ Project-URL: Repository, https://github.com/HonamSong/cplogger
7
+ Author-email: Honam Song <louky0714@gmail.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: color print,logging,print
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: System :: Logging
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.7
27
+ Requires-Dist: termcolor>=1.1.0
28
+ Description-Content-Type: text/markdown
29
+
30
+ # cplogger
31
+
32
+ ![version](https://img.shields.io/badge/version-0.1.0-blue.svg)
33
+ ![python](https://img.shields.io/badge/python-3.7%2B-blue.svg)
34
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
35
+ ![platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey.svg)
36
+ ![PyPI](https://img.shields.io/pypi/v/cplogger.svg)
37
+
38
+ 색상 print 로그와 파일 로그를 함께 지원하는 경량 Python 로거.
39
+
40
+ - 로그 레벨별 컬러 콘솔 출력 (info / warn / error / debug)
41
+ - 파일 기록 (`write`), 콘솔 출력 (`print`), 동시 사용 (`all`) 모드 지원
42
+ - 파일명 / 함수명 / 라인 번호 자동 표시 옵션
43
+ - 사용자 정의 색상 및 커스텀 로그 라인 지원
44
+
45
+ ## 설치
46
+
47
+ PyPI:
48
+
49
+ ```bash
50
+ pip install cplogger
51
+ ```
52
+
53
+ GitHub 최신본:
54
+
55
+ ```bash
56
+ pip install git+https://github.com/HonamSong/cplogger.git
57
+ ```
58
+
59
+ ## Logging class attribute
60
+
61
+ ```python
62
+ class Logging:
63
+ def __init__(self, log_path=None, log_file=None,
64
+ log_color='green', log_level='INFO', log_mode='print',
65
+ log_time_format=None, view_log=True,
66
+ view_line_num=False, view_file_name=False, view_func_name=False):
67
+
68
+ :param log_path: logging path name (default: ./logs)
69
+ :param log_file: logging file name (default: ./script_name_yyyymmdd.log)
70
+ :param log_color: print log color (default: green)
71
+ :param log_level: Default logging level (default: INFO)
72
+ :param log_mode: print or loging mode (default: print) [all|write|print]
73
+ :param log_time_format: logging Time format (default YYYY-MM-DD HH:MM:SS:3F)
74
+ :param view_view: view log by default True (Do Not print boolean is False)
75
+ :param view_line_num: view log in line number
76
+ :param view_func_name: view log in function name + line number
77
+ :param view_file_name: view log in file name + line number
78
+ ```
79
+
80
+ ## 사용
81
+
82
+ ### 기본 컬러 로그
83
+
84
+ ```python
85
+ from cplogger import *
86
+
87
+ logging = Logging()
88
+ # is_view can be skipped
89
+ logging.info("info_text", is_view=True)
90
+ logging.warn("warn_text", is_view=True)
91
+ logging.error("error_text", is_view=True)
92
+ logging.debug("debug_text", is_view=True)
93
+ ```
94
+
95
+ ![alt levelcolor](./img/default_loglevel_color.png)
96
+
97
+ ### 사용자 정의 로그
98
+
99
+ ```python
100
+ from cplogger import *
101
+
102
+ logging = Logging()
103
+ logging.custom("custom logger", "yellow", "warn", is_view=True, log_file='LOG_FILENAME')
104
+ ```
105
+
106
+ ![alt custom_logger](./img/custom_logger.png)
107
+
108
+ ### 지원 색상
109
+
110
+ color|attribute
111
+ ---|---
112
+ ![#008000](https://via.placeholder.com/20/008000?text=+)|***green*** (default info color)
113
+ ![#FF00FF](https://via.placeholder.com/20/FF00FF?text=+)|magenta (default warn color)
114
+ ![#ff0000](https://via.placeholder.com/20/ff0000?text=+)|red (default error color)
115
+ ![#FFEA00](https://via.placeholder.com/20/FFEA00?text=+)|yellow (default debug color)
116
+ ![#B6D0E2](https://via.placeholder.com/20/B6D0E2?text=+)|blue
117
+ ![#808080](https://via.placeholder.com/20/808080?text=+)|grey
118
+ ![#00FFFF](https://via.placeholder.com/20/00FFFF?text=+)|cyan
119
+ ![#FFFFFF](https://via.placeholder.com/20/FFFFFF?text=+)|white
120
+
121
+ ### 파일에만 기록 (`log_mode="write"`)
122
+
123
+ ```python
124
+ from cplogger import *
125
+
126
+ logging = Logging(log_mode="write")
127
+ # When log_mode is write, it is not output even if is_view is True.
128
+ logging.info('info_logging to file', is_view=True)
129
+ logging.warn('warn_logging to file', is_view=True)
130
+ logging.error('error_logging to file', is_view=True)
131
+ logging.debug('debug_logging to file', is_view=True)
132
+ ```
133
+
134
+ ![alt only_write](./img/write_to_file.png)
135
+
136
+ ### 콘솔 + 파일 동시 기록 (`log_mode="all"`)
137
+
138
+ ```python
139
+ from cplogger import *
140
+
141
+ logging = Logging(log_mode="all")
142
+ logging.info('info_logging print and write file', is_view=True)
143
+ logging.warn('warn_logging print and write file', is_view=True)
144
+ logging.error('error_logging print and write file', is_view=True)
145
+ logging.debug('debug_logging print and write file', is_view=True)
146
+ ```
147
+
148
+ ![alt log_mode_all](./img/log_mode_all_default.png)
149
+
150
+ ## License
151
+
152
+ MIT
@@ -0,0 +1,123 @@
1
+ # cplogger
2
+
3
+ ![version](https://img.shields.io/badge/version-0.1.0-blue.svg)
4
+ ![python](https://img.shields.io/badge/python-3.7%2B-blue.svg)
5
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
6
+ ![platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey.svg)
7
+ ![PyPI](https://img.shields.io/pypi/v/cplogger.svg)
8
+
9
+ 색상 print 로그와 파일 로그를 함께 지원하는 경량 Python 로거.
10
+
11
+ - 로그 레벨별 컬러 콘솔 출력 (info / warn / error / debug)
12
+ - 파일 기록 (`write`), 콘솔 출력 (`print`), 동시 사용 (`all`) 모드 지원
13
+ - 파일명 / 함수명 / 라인 번호 자동 표시 옵션
14
+ - 사용자 정의 색상 및 커스텀 로그 라인 지원
15
+
16
+ ## 설치
17
+
18
+ PyPI:
19
+
20
+ ```bash
21
+ pip install cplogger
22
+ ```
23
+
24
+ GitHub 최신본:
25
+
26
+ ```bash
27
+ pip install git+https://github.com/HonamSong/cplogger.git
28
+ ```
29
+
30
+ ## Logging class attribute
31
+
32
+ ```python
33
+ class Logging:
34
+ def __init__(self, log_path=None, log_file=None,
35
+ log_color='green', log_level='INFO', log_mode='print',
36
+ log_time_format=None, view_log=True,
37
+ view_line_num=False, view_file_name=False, view_func_name=False):
38
+
39
+ :param log_path: logging path name (default: ./logs)
40
+ :param log_file: logging file name (default: ./script_name_yyyymmdd.log)
41
+ :param log_color: print log color (default: green)
42
+ :param log_level: Default logging level (default: INFO)
43
+ :param log_mode: print or loging mode (default: print) [all|write|print]
44
+ :param log_time_format: logging Time format (default YYYY-MM-DD HH:MM:SS:3F)
45
+ :param view_view: view log by default True (Do Not print boolean is False)
46
+ :param view_line_num: view log in line number
47
+ :param view_func_name: view log in function name + line number
48
+ :param view_file_name: view log in file name + line number
49
+ ```
50
+
51
+ ## 사용
52
+
53
+ ### 기본 컬러 로그
54
+
55
+ ```python
56
+ from cplogger import *
57
+
58
+ logging = Logging()
59
+ # is_view can be skipped
60
+ logging.info("info_text", is_view=True)
61
+ logging.warn("warn_text", is_view=True)
62
+ logging.error("error_text", is_view=True)
63
+ logging.debug("debug_text", is_view=True)
64
+ ```
65
+
66
+ ![alt levelcolor](./img/default_loglevel_color.png)
67
+
68
+ ### 사용자 정의 로그
69
+
70
+ ```python
71
+ from cplogger import *
72
+
73
+ logging = Logging()
74
+ logging.custom("custom logger", "yellow", "warn", is_view=True, log_file='LOG_FILENAME')
75
+ ```
76
+
77
+ ![alt custom_logger](./img/custom_logger.png)
78
+
79
+ ### 지원 색상
80
+
81
+ color|attribute
82
+ ---|---
83
+ ![#008000](https://via.placeholder.com/20/008000?text=+)|***green*** (default info color)
84
+ ![#FF00FF](https://via.placeholder.com/20/FF00FF?text=+)|magenta (default warn color)
85
+ ![#ff0000](https://via.placeholder.com/20/ff0000?text=+)|red (default error color)
86
+ ![#FFEA00](https://via.placeholder.com/20/FFEA00?text=+)|yellow (default debug color)
87
+ ![#B6D0E2](https://via.placeholder.com/20/B6D0E2?text=+)|blue
88
+ ![#808080](https://via.placeholder.com/20/808080?text=+)|grey
89
+ ![#00FFFF](https://via.placeholder.com/20/00FFFF?text=+)|cyan
90
+ ![#FFFFFF](https://via.placeholder.com/20/FFFFFF?text=+)|white
91
+
92
+ ### 파일에만 기록 (`log_mode="write"`)
93
+
94
+ ```python
95
+ from cplogger import *
96
+
97
+ logging = Logging(log_mode="write")
98
+ # When log_mode is write, it is not output even if is_view is True.
99
+ logging.info('info_logging to file', is_view=True)
100
+ logging.warn('warn_logging to file', is_view=True)
101
+ logging.error('error_logging to file', is_view=True)
102
+ logging.debug('debug_logging to file', is_view=True)
103
+ ```
104
+
105
+ ![alt only_write](./img/write_to_file.png)
106
+
107
+ ### 콘솔 + 파일 동시 기록 (`log_mode="all"`)
108
+
109
+ ```python
110
+ from cplogger import *
111
+
112
+ logging = Logging(log_mode="all")
113
+ logging.info('info_logging print and write file', is_view=True)
114
+ logging.warn('warn_logging print and write file', is_view=True)
115
+ logging.error('error_logging print and write file', is_view=True)
116
+ logging.debug('debug_logging print and write file', is_view=True)
117
+ ```
118
+
119
+ ![alt log_mode_all](./img/log_mode_all_default.png)
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2022 hnsong
5
+ #
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ from .cplogger import *
@@ -0,0 +1,9 @@
1
+ ####
2
+ __title__ = 'cplogger'
3
+ __description__ = 'Color Print and logging'
4
+ __url__ = 'https://github.com/HonamSong/cplogger'
5
+ __version__ = '0.1.0'
6
+ __author__ = 'Honam Song'
7
+ __author_email__ = 'louky0714@gmail.com'
8
+ __license__ = 'MIT'
9
+ __copyright__ = 'Copyright 2022 hnsong'
@@ -0,0 +1,330 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import os
4
+ import re
5
+ import time
6
+ import inspect
7
+ import asyncio
8
+ import subprocess
9
+ from datetime import datetime, timedelta
10
+ from termcolor import cprint
11
+
12
+
13
+ def todaydate(date_type=None):
14
+ if date_type is None:
15
+ return '%s' % datetime.now().strftime("%Y%m%d")
16
+ elif date_type == "md":
17
+ return '%s' % datetime.now().strftime("%m%d")
18
+ elif date_type == "file":
19
+ return '%s' % datetime.now().strftime("%Y%m%d_%H%M")
20
+ elif date_type == "hour":
21
+ return '%s' % datetime.now().strftime("%H")
22
+ elif date_type == "ms":
23
+ return '%s' % datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
24
+ elif date_type == "log_ms":
25
+ return '%s' % datetime.now().strftime("%Y%m%d%H%M%S")
26
+ elif date_type == "ms_text":
27
+ return '%s' % datetime.now().strftime("%Y%m%d-%H%M%S%f")[:-3]
28
+ elif date_type == "yesterday":
29
+ return '%s' % (datetime.now() - timedelta(days=1)).strftime("%Y%m%d")
30
+
31
+
32
+ def check_dir(dir_path, create_if_missing=False, is_view=False):
33
+ if os.path.isdir(dir_path):
34
+ return_msg = f'Directory is exists :{dir_path}'
35
+ return_color = "green"
36
+ return_value = True
37
+ else:
38
+ if create_if_missing:
39
+ os.makedirs(dir_path, exist_ok=True)
40
+ return_msg = f'Create a Directory :{dir_path}'
41
+ return_color = "green"
42
+ return_value = True
43
+ else:
44
+ return_msg = f'Directory "{dir_path}" does not found'
45
+ return_color = "red"
46
+ return_value = False
47
+
48
+ if is_view:
49
+ cprint(return_msg, return_color)
50
+
51
+ return return_value
52
+
53
+
54
+ def check_file(filename, path=None, is_view=False):
55
+ return_msg = None
56
+ return_color = None
57
+
58
+ orig_path = os.getcwd()
59
+ if path:
60
+ if check_dir(path):
61
+ # path Change
62
+ os.chdir(path)
63
+
64
+ if os.path.isfile(filename):
65
+ if path:
66
+ os.chdir(orig_path)
67
+ return_msg = f'File is exists : {filename}'
68
+ return_color = 'green'
69
+ return_value = os.path.join(path, filename)
70
+ else:
71
+ return_value = os.path.join(filename)
72
+ else:
73
+ return_msg = f'Check file : file "{filename}" does Not Found is file'
74
+ return_color = 'red'
75
+ return_value = False
76
+
77
+ if is_view:
78
+ cprint(return_msg, return_color)
79
+
80
+ return return_value
81
+
82
+
83
+ class Color:
84
+ # TextColor : Text Color
85
+ grey = 'grey'
86
+ red = 'red'
87
+ green = 'green'
88
+ yellow = 'yellow'
89
+ blue = 'blue'
90
+ magenta = 'magenta'
91
+ cyan = 'cyan'
92
+ white = 'white'
93
+
94
+
95
+ class BgColor:
96
+ """
97
+ :param BackGroundColor(Text highlights) : Text Background color
98
+ """
99
+ grey = 'on_grey'
100
+ red = 'on_red'
101
+ green = 'on_green'
102
+ yellow = 'on_yellow'
103
+ blue = 'on_blue'
104
+ magenta = 'on_magenta'
105
+ cyan = 'on_cyan'
106
+ white = 'on_white'
107
+
108
+
109
+ class Logging:
110
+ def __init__(self, log_path=None, log_file=None,
111
+ log_color='green', log_level='INFO', log_mode='print',
112
+ log_rotate=True, log_compress=True,
113
+ log_time_format=None, view_log=True,
114
+ view_line_num=False, view_file_name=False, view_func_name=False):
115
+
116
+ self.log_path = log_path
117
+ self.log_file = log_file
118
+ self.log_color = log_color
119
+ self.log_level = log_level
120
+ self.log_mode = log_mode
121
+ self.log_time_format = log_time_format
122
+ self.log_rotate = log_rotate
123
+ self.log_compress = log_compress
124
+ self.view_log = view_log
125
+ self.view_line_num = view_line_num
126
+ self.view_file_name = view_file_name
127
+ self.view_func_name = view_func_name
128
+
129
+ """
130
+ :param log_path: logging path name
131
+ :param log_file: logging file name
132
+ :param log_color: print log color
133
+ :param log_level: logging level
134
+ :param log_mode: print or loging mode ( default : print), [all|write|print]
135
+ :param log_time_format : logging Time format (default YYYY-MM-DD HH:MM:SS:3F)
136
+ :param view_view : View logs by default [True|False]
137
+ :param view_line_num : view logs in line number
138
+ :param view_func_name : view logs in function name + line number
139
+ :param view_file_name : view logs in file name + line number
140
+ :return:
141
+ """
142
+
143
+ if self.log_mode == 'write' or self.log_mode == 'all':
144
+ if self.log_path:
145
+ check_dir(self.log_path, create_if_missing=True)
146
+ else:
147
+ base_path = os.path.dirname(inspect.getmodule(inspect.stack()[1][0]).__file__)
148
+ self.log_path = os.path.join(base_path, "logs")
149
+ check_dir(self.log_path, create_if_missing=True)
150
+
151
+ if not self.log_file:
152
+ filename = os.path.basename(inspect.getmodule(inspect.stack()[1][0]).__file__)
153
+ # self.log_file = filename.replace('.py', f'_{todaydate()}.log')
154
+ self.log_file = filename.replace('.py', '.log')
155
+
156
+ self.log_file = os.path.join(self.log_path, self.log_file)
157
+
158
+ def file_compress(self, filename):
159
+ gzip_result = None
160
+ if self.log_compress:
161
+ if os.path.exists(filename):
162
+ gzip_result = subprocess.run(['gzip', filename])
163
+
164
+ if gzip_result:
165
+ return True if gzip_result.returncode == 0 else False
166
+ else:
167
+ return False
168
+
169
+ def logrotate(self, log_file):
170
+ if self.log_rotate:
171
+ if os.path.exists(log_file):
172
+ file_access_day = time.strftime("%Y%m%d", time.localtime(os.path.getatime(log_file)))
173
+ if str(file_access_day) != str(todaydate()):
174
+ after_filename = f"{log_file}.{todaydate('yesterday')}"
175
+ os.rename(log_file, after_filename)
176
+ self.file_compress(after_filename)
177
+ return None
178
+
179
+ def log_write(self, log_msg, log_file=None, log_path=None):
180
+ if not log_file:
181
+ log_file = self.log_file
182
+
183
+ if os.path.dirname(log_file):
184
+ log_path = os.path.dirname(log_file)
185
+
186
+ if not log_path:
187
+ log_path = self.log_path
188
+
189
+ log_file = os.path.join(log_path, os.path.basename(log_file))
190
+
191
+ # asyncio.run(self.logrotate(log_file))
192
+ self.logrotate(log_file)
193
+
194
+ # cprint(f'++++++++++++++++++ log_file : {log_file} ' , 'red')
195
+
196
+ if log_msg:
197
+ with open(log_file, 'a+') as f:
198
+ f.write(f'{log_msg}\n')
199
+
200
+ def log_level_check(self, color, level):
201
+ # r_color = None
202
+ # r_level = None
203
+
204
+ if not level:
205
+ level = 'info'
206
+
207
+ if level.upper() == 'WARNING' or level.upper() == 'WARN':
208
+ r_color = Color.magenta
209
+ r_level = 'WARN'
210
+ elif level.upper() == 'ERROR' or level.upper() == 'ERR':
211
+ r_color = Color.red
212
+ r_level = 'ERROR'
213
+ elif level.upper() == 'DEBUG':
214
+ r_color = Color.yellow
215
+ r_level = 'DEBUG'
216
+ else:
217
+ r_color = color if color else self.log_color
218
+ r_level = self.log_level
219
+
220
+ if color:
221
+ r_color = color
222
+
223
+ return r_color, r_level
224
+
225
+ def log_time_format_check(self):
226
+ # log_time = None
227
+ if self.log_time_format:
228
+ format_regex = re.compile('\\.([0-9]){4,8}')
229
+ log_time = datetime.now().strftime(self.log_time_format)
230
+ if format_regex.search(log_time):
231
+ log_time = datetime.now().strftime(self.log_time_format)[:-3]
232
+ else:
233
+ log_time = todaydate(date_type="ms")
234
+
235
+ return log_time
236
+
237
+ def log_print_format_check(self, level, call_name=None):
238
+ # print_fmt = None
239
+
240
+ if call_name:
241
+ print_fmt = f'[{self.log_time_format_check()}] [{level.upper():5}] | {call_name}'
242
+ else:
243
+ print_fmt = f'[{self.log_time_format_check()}] [{level.upper():5}]'
244
+
245
+ return print_fmt
246
+
247
+ def call_check(self, line_num=None, func_name=None, file_name=None):
248
+ call_source_location = line_num
249
+
250
+ if self.view_func_name and not self.view_file_name:
251
+ call_source_location = call_source_location.replace(call_source_location.split('.')[0], func_name)
252
+
253
+ if self.view_file_name and not self.view_func_name:
254
+ call_source_location = call_source_location.replace(call_source_location.split('.')[0], file_name)
255
+
256
+ if self.view_func_name and self.view_file_name:
257
+ call_name = f'{file_name}.{func_name}'
258
+ call_source_location = call_source_location.replace(call_source_location.split('.')[0], call_name)
259
+
260
+ if not self.view_line_num and not self.view_func_name and not self.view_file_name:
261
+ call_source_location = False
262
+
263
+ return call_source_location
264
+
265
+ def printing(self, msg, color, is_view=True, log_file=None):
266
+ if not self.view_log:
267
+ is_view = False
268
+
269
+ if self.log_mode == 'print' or not self.log_mode or self.log_mode == 'all':
270
+ if is_view:
271
+ cprint(msg, color)
272
+
273
+ if self.log_mode == 'write' or self.log_mode == 'all':
274
+ self.log_write(msg, log_file=log_file)
275
+
276
+ def custom(self, msg, color=None, level=None, is_view=True, log_file=None):
277
+ # user custom log
278
+
279
+ # call line number , function name, file name
280
+ # call_file_name = inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
281
+ # call_func_name = inspect.currentframe().f_back.f_code.co_name
282
+ call_source_location = self.call_check(
283
+ line_num=f'line.{inspect.currentframe().f_back.f_lineno}',
284
+ func_name=inspect.currentframe().f_back.f_code.co_name,
285
+ file_name=inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
286
+ )
287
+ color, level = self.log_level_check(color, level)
288
+ print_msg = f'{self.log_print_format_check(level, call_name=call_source_location)} | {msg}'
289
+
290
+ self.printing(print_msg, color, is_view=is_view, log_file=log_file)
291
+
292
+ def info(self, msg, is_view=True,):
293
+ call_source_location = self.call_check(
294
+ line_num=f'line.{inspect.currentframe().f_back.f_lineno}',
295
+ func_name=inspect.currentframe().f_back.f_code.co_name,
296
+ file_name=inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
297
+ )
298
+
299
+ print_msg = f'{self.log_print_format_check("info", call_name=call_source_location)} | {msg}'
300
+ self.printing(print_msg, "green", is_view=is_view)
301
+
302
+ def warn(self, msg, is_view=True,):
303
+ call_source_location = self.call_check(
304
+ line_num=f'line.{inspect.currentframe().f_back.f_lineno}',
305
+ func_name=inspect.currentframe().f_back.f_code.co_name,
306
+ file_name=inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
307
+ )
308
+
309
+ print_msg = f'{self.log_print_format_check("warn", call_name=call_source_location)} | {msg}'
310
+ self.printing(print_msg, "magenta", is_view=is_view)
311
+
312
+ def error(self, msg, is_view=True,):
313
+ call_source_location = self.call_check(
314
+ line_num=f'line.{inspect.currentframe().f_back.f_lineno}',
315
+ func_name=inspect.currentframe().f_back.f_code.co_name,
316
+ file_name=inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
317
+ )
318
+
319
+ print_msg = f'{self.log_print_format_check("error", call_name=call_source_location)} | {msg}'
320
+ self.printing(print_msg, "red", is_view=is_view)
321
+
322
+ def debug(self, msg, is_view=True,):
323
+ call_source_location = self.call_check(
324
+ line_num=f'line.{inspect.currentframe().f_back.f_lineno}',
325
+ func_name=inspect.currentframe().f_back.f_code.co_name,
326
+ file_name=inspect.getmodule(inspect.stack()[1][0]).__file__.split("/")[-1]
327
+ )
328
+
329
+ print_msg = f'{self.log_print_format_check("debug", call_name=call_source_location)} | {msg}'
330
+ self.printing(print_msg, "yellow", is_view=is_view)
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "cplogger"
7
+ dynamic = ["version"]
8
+ description = "Color Print and logging"
9
+ readme = "README.md"
10
+ requires-python = ">=3.7"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Honam Song", email = "louky0714@gmail.com" }]
13
+ keywords = ["print", "logging", "color print"]
14
+ dependencies = [
15
+ "termcolor>=1.1.0",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Developers",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Programming Language :: Python :: 3.7",
25
+ "Programming Language :: Python :: 3.8",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Topic :: System :: Logging",
32
+ "Topic :: Utilities",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/HonamSong/cplogger"
37
+ Repository = "https://github.com/HonamSong/cplogger"
38
+
39
+ [tool.hatch.version]
40
+ path = "cplogger/__version__.py"
41
+
42
+ [tool.hatch.build.targets.wheel]
43
+ packages = ["cplogger"]
44
+
45
+ [tool.hatch.build.targets.sdist]
46
+ include = [
47
+ "cplogger/",
48
+ "README.md",
49
+ "LICENSE",
50
+ ]