pretty-pie-log 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.
- pretty-pie-log-0.1.0/LICENSE +21 -0
- pretty-pie-log-0.1.0/PKG-INFO +27 -0
- pretty-pie-log-0.1.0/README.md +1 -0
- pretty-pie-log-0.1.0/pretty_pie_log/__init__.py +2 -0
- pretty-pie-log-0.1.0/pretty_pie_log/examples.py +24 -0
- pretty-pie-log-0.1.0/pretty_pie_log/pie_log_level.py +21 -0
- pretty-pie-log-0.1.0/pretty_pie_log/pie_logger.py +467 -0
- pretty-pie-log-0.1.0/pretty_pie_log.egg-info/PKG-INFO +27 -0
- pretty-pie-log-0.1.0/pretty_pie_log.egg-info/SOURCES.txt +12 -0
- pretty-pie-log-0.1.0/pretty_pie_log.egg-info/dependency_links.txt +1 -0
- pretty-pie-log-0.1.0/pretty_pie_log.egg-info/requires.txt +2 -0
- pretty-pie-log-0.1.0/pretty_pie_log.egg-info/top_level.txt +1 -0
- pretty-pie-log-0.1.0/setup.cfg +4 -0
- pretty-pie-log-0.1.0/setup.py +55 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Chanpreet Singh
|
|
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,27 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pretty-pie-log
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A feature-rich logging utility that provides colorized console output with customizable formatting
|
|
5
|
+
Home-page: https://github.com/chanpreet3000/pretty-pie-log
|
|
6
|
+
Author: chanpreet3000
|
|
7
|
+
Author-email: chanpreet3000@gmail.com
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/chanpreet3000/pretty-pie-log/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/chanpreet3000/pretty-pie-log
|
|
10
|
+
Keywords: logging,colorized,console,debug,formatting,pretty-print,thread-safe,timezone,structured-logging
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: System :: Logging
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
|
|
27
|
+
# pretty-pie-log
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# pretty-pie-log
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from pie_log_level import PieLogLevel
|
|
4
|
+
from pie_logger import PieLogger
|
|
5
|
+
|
|
6
|
+
logger = PieLogger('Logger')
|
|
7
|
+
|
|
8
|
+
logger.log(PieLogLevel.CRITICAL, 'This is a critical message', {'key': 'value'})
|
|
9
|
+
logger.info('This is an info message', {'key': 'value'})
|
|
10
|
+
logger.debug('This is a debug message', {'key': 'value'}, colorful=False)
|
|
11
|
+
logger.info('This is an info message', {'key': 'value'}, colorful=False)
|
|
12
|
+
logger.warning('This is a warning message', {'key': 'value'}, colorful=False)
|
|
13
|
+
logger.error('This is an error message', {'key': 'value'}, colorful=False)
|
|
14
|
+
logger.critical('This is a critical message', {'key': 'value'}, colorful=True)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@logger.log_execution(print_args_at_start=True, print_result_at_end=True, start_message="Starting my task",
|
|
18
|
+
start_message_log_level=logging.DEBUG, end_message_log_level=logging.INFO)
|
|
19
|
+
def main(str):
|
|
20
|
+
logger.info("This is an info message", {'str': str})
|
|
21
|
+
return True
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
main('here')
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class PieLogLevel:
|
|
2
|
+
DEBUG = 0
|
|
3
|
+
INFO = 1
|
|
4
|
+
WARNING = 2
|
|
5
|
+
ERROR = 3
|
|
6
|
+
CRITICAL = 4
|
|
7
|
+
|
|
8
|
+
@staticmethod
|
|
9
|
+
def get_level_str(level: int):
|
|
10
|
+
if level == PieLogLevel.DEBUG:
|
|
11
|
+
return "DEBUG"
|
|
12
|
+
elif level == PieLogLevel.INFO:
|
|
13
|
+
return "INFO"
|
|
14
|
+
elif level == PieLogLevel.WARNING:
|
|
15
|
+
return "WARNING"
|
|
16
|
+
elif level == PieLogLevel.ERROR:
|
|
17
|
+
return "ERROR"
|
|
18
|
+
elif level == PieLogLevel.CRITICAL:
|
|
19
|
+
return "CRITICAL"
|
|
20
|
+
else:
|
|
21
|
+
return "UNKNOWN"
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
# Copyright (c) 2024 Chanpreet Singh
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
import logging
|
|
23
|
+
import inspect
|
|
24
|
+
from functools import wraps
|
|
25
|
+
from threading import Lock
|
|
26
|
+
|
|
27
|
+
import pytz
|
|
28
|
+
import os
|
|
29
|
+
import sys
|
|
30
|
+
import traceback
|
|
31
|
+
from datetime import datetime
|
|
32
|
+
from colorama import Fore
|
|
33
|
+
from typing import Any, Callable, Dict, Optional, TypeVar, Union
|
|
34
|
+
|
|
35
|
+
from pie_log_level import PieLogLevel
|
|
36
|
+
|
|
37
|
+
T = TypeVar('T') # For generic return type in decorator
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PieLogger:
|
|
41
|
+
"""
|
|
42
|
+
A thread-safe, feature-rich logging utility that provides colorized console output with customizable formatting.
|
|
43
|
+
|
|
44
|
+
The Logger class extends Python's built-in logging functionality with additional features such as:
|
|
45
|
+
- Colored output using colorama
|
|
46
|
+
- Timezone support
|
|
47
|
+
- Structured logging with JSON formatting
|
|
48
|
+
- Automatic file path detection
|
|
49
|
+
- Stack trace inclusion
|
|
50
|
+
- Thread-safe logging operations
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(
|
|
54
|
+
self,
|
|
55
|
+
logger_name: str,
|
|
56
|
+
timezone: Optional[str] = None,
|
|
57
|
+
timestamp_padding: int = 30,
|
|
58
|
+
log_level_padding: int = 10,
|
|
59
|
+
file_path_padding: int = 30,
|
|
60
|
+
debug_log_color: Fore = Fore.CYAN,
|
|
61
|
+
info_log_color: Fore = Fore.GREEN,
|
|
62
|
+
warning_log_color: Fore = Fore.YELLOW,
|
|
63
|
+
error_log_color: Fore = Fore.RED,
|
|
64
|
+
critical_log_color: Fore = Fore.MAGENTA,
|
|
65
|
+
timestamp_log_color: Fore = Fore.WHITE,
|
|
66
|
+
file_path_log_color: Fore = Fore.WHITE,
|
|
67
|
+
details_log_color: Fore = Fore.LIGHTWHITE_EX,
|
|
68
|
+
colorful: bool = True,
|
|
69
|
+
minimum_log_level: int = PieLogLevel.INFO,
|
|
70
|
+
default_log_color: Fore = Fore.WHITE,
|
|
71
|
+
details_indent: int = 2
|
|
72
|
+
) -> None:
|
|
73
|
+
"""
|
|
74
|
+
Initialize a new Logger instance with customizable formatting and color options.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
logger_name (str): Unique identifier for the logger instance
|
|
78
|
+
timezone (Optional[str]): Timezone for timestamp display (default: None, using UTC)
|
|
79
|
+
timestamp_padding (int): Minimum width of timestamp field (default: 30)
|
|
80
|
+
log_level_padding (int): Minimum width of log level field (default: 10)
|
|
81
|
+
file_path_padding (int): Minimum width of file path field (default: 30)
|
|
82
|
+
debug_log_color (Fore): Color for debug level messages (default: Fore.CYAN)
|
|
83
|
+
info_log_color (Fore): Color for info level messages (default: Fore.GREEN)
|
|
84
|
+
warning_log_color (Fore): Color for warning level messages (default: Fore.YELLOW)
|
|
85
|
+
error_log_color (Fore): Color for error level messages (default: Fore.RED)
|
|
86
|
+
critical_log_color (Fore): Color for critical level messages (default: Fore.MAGENTA)
|
|
87
|
+
timestamp_log_color (Fore): Color for timestamp (default: Fore.WHITE)
|
|
88
|
+
file_path_log_color (Fore): Color for file path (default: Fore.WHITE)
|
|
89
|
+
details_log_color (Fore): Color for JSON details (default: Fore.LIGHTWHITE_EX)
|
|
90
|
+
colorful (bool): Enable/disable colored output (default: True)
|
|
91
|
+
minimum_log_level (int): Minimum logging level (default: PieLogLevel.INFO)
|
|
92
|
+
default_log_color (Fore): Fallback color when colorful is False (default: Fore.WHITE)
|
|
93
|
+
details_indent (int): Spaces for JSON indentation (default: 2)
|
|
94
|
+
"""
|
|
95
|
+
self._logger_name = logger_name
|
|
96
|
+
self._timezone = timezone
|
|
97
|
+
self._timestamp_padding = timestamp_padding
|
|
98
|
+
self._log_level_padding = log_level_padding
|
|
99
|
+
self._file_path_padding = file_path_padding
|
|
100
|
+
self._colorful = colorful
|
|
101
|
+
self._project_root = PieLogger.__get_project_root()
|
|
102
|
+
self._minimum_log_level = minimum_log_level
|
|
103
|
+
self._default_log_color = default_log_color
|
|
104
|
+
self._details_indent = details_indent
|
|
105
|
+
self._log_lock = Lock()
|
|
106
|
+
self.console_logger: logging.Logger
|
|
107
|
+
|
|
108
|
+
if self._colorful:
|
|
109
|
+
self._debug_log_color = debug_log_color
|
|
110
|
+
self._info_log_color = info_log_color
|
|
111
|
+
self._warning_log_color = warning_log_color
|
|
112
|
+
self._error_log_color = error_log_color
|
|
113
|
+
self._critical_log_color = critical_log_color
|
|
114
|
+
self._timestamp_log_color = timestamp_log_color
|
|
115
|
+
self._file_path_log_color = file_path_log_color
|
|
116
|
+
self._details_log_color = details_log_color
|
|
117
|
+
else:
|
|
118
|
+
self._debug_log_color = default_log_color
|
|
119
|
+
self._info_log_color = default_log_color
|
|
120
|
+
self._warning_log_color = default_log_color
|
|
121
|
+
self._error_log_color = default_log_color
|
|
122
|
+
self._critical_log_color = default_log_color
|
|
123
|
+
self._timestamp_log_color = default_log_color
|
|
124
|
+
self._file_path_log_color = default_log_color
|
|
125
|
+
self._details_log_color = default_log_color
|
|
126
|
+
|
|
127
|
+
self.__initialize_logger()
|
|
128
|
+
|
|
129
|
+
def __initialize_logger(self) -> None:
|
|
130
|
+
"""
|
|
131
|
+
Initialize the console logger with the specified minimum log level and stdout handler.
|
|
132
|
+
"""
|
|
133
|
+
self.console_logger = logging.getLogger(f"{self._logger_name}_console")
|
|
134
|
+
self.console_logger.setLevel(self._minimum_log_level)
|
|
135
|
+
self.console_logger.addHandler(logging.StreamHandler(sys.stdout))
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def __get_project_root() -> str:
|
|
139
|
+
"""
|
|
140
|
+
Determine the project root directory by looking for main.py file. If not found, use the current directory.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
str: Absolute path to the project root directory
|
|
144
|
+
"""
|
|
145
|
+
current_path = os.path.abspath(os.path.dirname(__file__))
|
|
146
|
+
while True:
|
|
147
|
+
if os.path.exists(os.path.join(current_path, 'main.py')):
|
|
148
|
+
return current_path
|
|
149
|
+
parent_path = os.path.dirname(current_path)
|
|
150
|
+
if parent_path == current_path:
|
|
151
|
+
return os.path.abspath(os.path.dirname(__file__))
|
|
152
|
+
current_path = parent_path
|
|
153
|
+
|
|
154
|
+
def __get_log_details(self) -> str:
|
|
155
|
+
"""
|
|
156
|
+
Extract file path and line number information from the call stack.
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
str: Formatted string containing relative file path and line number
|
|
160
|
+
"""
|
|
161
|
+
frame = inspect.stack()[4]
|
|
162
|
+
file_name = frame.filename
|
|
163
|
+
line_number = frame.lineno
|
|
164
|
+
|
|
165
|
+
project_root = self._project_root
|
|
166
|
+
relative_file_name = os.path.relpath(file_name, project_root)
|
|
167
|
+
relative_file_name = f"./{relative_file_name.replace(os.sep, '/')}"
|
|
168
|
+
|
|
169
|
+
file_path_info = f"{relative_file_name}:{line_number}"
|
|
170
|
+
return file_path_info
|
|
171
|
+
|
|
172
|
+
def __get_timestamp(self) -> str:
|
|
173
|
+
"""
|
|
174
|
+
Generate a formatted timestamp string in the configured timezone.
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
str: Formatted timestamp string with millisecond precision
|
|
178
|
+
"""
|
|
179
|
+
current_time = datetime.now(pytz.utc)
|
|
180
|
+
if self._timezone:
|
|
181
|
+
tz = pytz.timezone(self._timezone)
|
|
182
|
+
current_time = current_time.astimezone(tz)
|
|
183
|
+
return current_time.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
|
184
|
+
|
|
185
|
+
def __get_color_from_level(self, level: int) -> Fore:
|
|
186
|
+
"""
|
|
187
|
+
Determine the appropriate color for a given log level.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
level (int): Logging level (DEBUG, INFO, WARNING, ERROR, or CRITICAL)
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Fore: Colorama color code for the specified log level
|
|
194
|
+
"""
|
|
195
|
+
if level == PieLogLevel.DEBUG:
|
|
196
|
+
return self._debug_log_color
|
|
197
|
+
elif level == PieLogLevel.INFO:
|
|
198
|
+
return self._info_log_color
|
|
199
|
+
elif level == PieLogLevel.WARNING:
|
|
200
|
+
return self._warning_log_color
|
|
201
|
+
elif level == PieLogLevel.ERROR:
|
|
202
|
+
return self._error_log_color
|
|
203
|
+
elif level == PieLogLevel.CRITICAL:
|
|
204
|
+
return self._critical_log_color
|
|
205
|
+
|
|
206
|
+
return self._default_log_color
|
|
207
|
+
|
|
208
|
+
def __console_log(
|
|
209
|
+
self,
|
|
210
|
+
level: int,
|
|
211
|
+
message: str,
|
|
212
|
+
details: Optional[Dict[str, Any]],
|
|
213
|
+
exec_info: Optional[Union[bool, Exception]],
|
|
214
|
+
colorful: bool
|
|
215
|
+
) -> str:
|
|
216
|
+
"""
|
|
217
|
+
Format a log message with all configured components in a thread-safe manner.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
level (int): Logging level
|
|
221
|
+
message (str): Main log message
|
|
222
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
223
|
+
exec_info (Optional[Union[bool, Exception]]): Exception object or boolean for stack trace inclusion
|
|
224
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
str: Formatted log message string
|
|
228
|
+
"""
|
|
229
|
+
with self._log_lock:
|
|
230
|
+
timestamp_log_color = self._timestamp_log_color if colorful else self._default_log_color
|
|
231
|
+
file_path_log_color = self._file_path_log_color if colorful else self._default_log_color
|
|
232
|
+
details_log_color = self._details_log_color if colorful else self._default_log_color
|
|
233
|
+
level_color = self.__get_color_from_level(level) if colorful else self._default_log_color
|
|
234
|
+
|
|
235
|
+
file_path_info = self.__get_log_details()
|
|
236
|
+
timestamp = self.__get_timestamp()
|
|
237
|
+
|
|
238
|
+
console_log_parts = [
|
|
239
|
+
f"{timestamp_log_color}{timestamp:<{self._timestamp_padding}}",
|
|
240
|
+
f"{level_color}{PieLogLevel.get_level_str(level):<{self._log_level_padding}}",
|
|
241
|
+
f"{file_path_log_color}{file_path_info:<{self._file_path_padding}}",
|
|
242
|
+
f": {level_color}{message}"
|
|
243
|
+
]
|
|
244
|
+
console_log = " ".join(console_log_parts)
|
|
245
|
+
|
|
246
|
+
if details:
|
|
247
|
+
formatted_details = json.dumps(details, indent=self._details_indent)
|
|
248
|
+
console_log += f"\n{details_log_color}{formatted_details}"
|
|
249
|
+
|
|
250
|
+
if exec_info:
|
|
251
|
+
exec_details = ''.join(traceback.format_exc())
|
|
252
|
+
console_log += f"\n{level_color}{exec_details}"
|
|
253
|
+
|
|
254
|
+
return console_log
|
|
255
|
+
|
|
256
|
+
def __log(
|
|
257
|
+
self,
|
|
258
|
+
level: int,
|
|
259
|
+
message: str,
|
|
260
|
+
details: Optional[Dict[str, Any]] = None,
|
|
261
|
+
exec_info: bool = False,
|
|
262
|
+
colorful: bool = True
|
|
263
|
+
) -> None:
|
|
264
|
+
"""
|
|
265
|
+
Internal method to process and output a log message.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
level (int): Logging level
|
|
269
|
+
message (str): Main log message
|
|
270
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
271
|
+
exec_info (bool): Whether to include stack trace
|
|
272
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
273
|
+
"""
|
|
274
|
+
console_log = self.__console_log(level, message, details, exec_info, colorful)
|
|
275
|
+
self.console_logger.log(level, console_log)
|
|
276
|
+
|
|
277
|
+
def log(
|
|
278
|
+
self,
|
|
279
|
+
level: int,
|
|
280
|
+
message: str,
|
|
281
|
+
details: Optional[Dict[str, Any]] = None,
|
|
282
|
+
exec_info: bool = False,
|
|
283
|
+
colorful: bool = True
|
|
284
|
+
) -> None:
|
|
285
|
+
"""
|
|
286
|
+
Log a message at the specified level.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
level (int): Logging level
|
|
290
|
+
message (str): Main log message
|
|
291
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
292
|
+
exec_info (bool): Whether to include stack trace
|
|
293
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
294
|
+
"""
|
|
295
|
+
self.__log(level, message, details, exec_info, colorful)
|
|
296
|
+
|
|
297
|
+
def debug(
|
|
298
|
+
self,
|
|
299
|
+
message: str,
|
|
300
|
+
details: Optional[Dict[str, Any]] = None,
|
|
301
|
+
exec_info: bool = False,
|
|
302
|
+
colorful: bool = True
|
|
303
|
+
) -> None:
|
|
304
|
+
"""
|
|
305
|
+
Log a debug level message.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
message (str): Main log message
|
|
309
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
310
|
+
exec_info (bool): Whether to include stack trace
|
|
311
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
312
|
+
"""
|
|
313
|
+
self.__log(PieLogLevel.DEBUG, message, details, exec_info, colorful)
|
|
314
|
+
|
|
315
|
+
def info(
|
|
316
|
+
self,
|
|
317
|
+
message: str,
|
|
318
|
+
details: Optional[Dict[str, Any]] = None,
|
|
319
|
+
exec_info: bool = False,
|
|
320
|
+
colorful: bool = True
|
|
321
|
+
) -> None:
|
|
322
|
+
"""
|
|
323
|
+
Log an info level message.
|
|
324
|
+
|
|
325
|
+
Args:
|
|
326
|
+
message (str): Main log message
|
|
327
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
328
|
+
exec_info (bool): Whether to include stack trace
|
|
329
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
330
|
+
"""
|
|
331
|
+
self.__log(PieLogLevel.INFO, message, details, exec_info, colorful)
|
|
332
|
+
|
|
333
|
+
def warning(
|
|
334
|
+
self,
|
|
335
|
+
message: str,
|
|
336
|
+
details: Optional[Dict[str, Any]] = None,
|
|
337
|
+
exec_info: bool = False,
|
|
338
|
+
colorful: bool = True
|
|
339
|
+
) -> None:
|
|
340
|
+
"""
|
|
341
|
+
Log a warning level message.
|
|
342
|
+
|
|
343
|
+
Args:
|
|
344
|
+
message (str): Main log message
|
|
345
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
346
|
+
exec_info (bool): Whether to include stack trace
|
|
347
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
348
|
+
"""
|
|
349
|
+
self.__log(PieLogLevel.WARNING, message, details, exec_info, colorful)
|
|
350
|
+
|
|
351
|
+
def error(
|
|
352
|
+
self,
|
|
353
|
+
message: str,
|
|
354
|
+
details: Optional[Dict[str, Any]] = None,
|
|
355
|
+
exec_info: bool = False,
|
|
356
|
+
colorful: bool = True
|
|
357
|
+
) -> None:
|
|
358
|
+
"""
|
|
359
|
+
Log an error level message.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
message (str): Main log message
|
|
363
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
364
|
+
exec_info (bool): Whether to include stack trace
|
|
365
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
366
|
+
"""
|
|
367
|
+
self.__log(PieLogLevel.ERROR, message, details, exec_info, colorful)
|
|
368
|
+
|
|
369
|
+
def critical(
|
|
370
|
+
self,
|
|
371
|
+
message: str,
|
|
372
|
+
details: Optional[Dict[str, Any]] = None,
|
|
373
|
+
exec_info: bool = False,
|
|
374
|
+
colorful: bool = True
|
|
375
|
+
) -> None:
|
|
376
|
+
"""
|
|
377
|
+
Log a critical level message.
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
message (str): Main log message
|
|
381
|
+
details (Optional[Dict[str, Any]]): Additional structured data to include as JSON
|
|
382
|
+
exec_info (bool): Whether to include stack trace
|
|
383
|
+
colorful (bool): Whether to apply colors to this specific message
|
|
384
|
+
"""
|
|
385
|
+
self.__log(PieLogLevel.CRITICAL, message, details, exec_info, colorful)
|
|
386
|
+
|
|
387
|
+
def log_execution(
|
|
388
|
+
self,
|
|
389
|
+
start_message: Optional[str] = None,
|
|
390
|
+
end_message: Optional[str] = None,
|
|
391
|
+
print_args_at_start: bool = False,
|
|
392
|
+
print_result_at_end: bool = False,
|
|
393
|
+
start_message_log_level: int = PieLogLevel.INFO,
|
|
394
|
+
end_message_log_level: int = PieLogLevel.INFO
|
|
395
|
+
) -> Callable[[Callable[..., T]], Callable[..., T]]:
|
|
396
|
+
"""
|
|
397
|
+
Creates a decorator that logs function entry and exit with timestamps.
|
|
398
|
+
|
|
399
|
+
Args:
|
|
400
|
+
start_message (Optional[str]): Custom message for function start
|
|
401
|
+
end_message (Optional[str]): Custom message for function end
|
|
402
|
+
print_args_at_start (bool): Include function arguments in start message
|
|
403
|
+
print_result_at_end (bool): Include function result in end message
|
|
404
|
+
start_message_log_level (int): Log level for start message
|
|
405
|
+
end_message_log_level (int): Log level for end message
|
|
406
|
+
|
|
407
|
+
Returns:
|
|
408
|
+
Callable[[Callable[..., T]], Callable[..., T]]: A decorator function that wraps the original
|
|
409
|
+
function with logging functionality while preserving its return type
|
|
410
|
+
|
|
411
|
+
Example:
|
|
412
|
+
```python
|
|
413
|
+
logger = PieLogger("my_logger")
|
|
414
|
+
|
|
415
|
+
@logger.log_execution(
|
|
416
|
+
start_message="Starting task",
|
|
417
|
+
end_message="Task completed",
|
|
418
|
+
print_args_at_start=True,
|
|
419
|
+
print_result_at_end=True
|
|
420
|
+
)
|
|
421
|
+
def process_data(data: List[str]) -> Dict[str, Any]:
|
|
422
|
+
# Function implementation
|
|
423
|
+
return {"status": "success"}
|
|
424
|
+
```
|
|
425
|
+
"""
|
|
426
|
+
|
|
427
|
+
def decorator(func: Callable[..., T]) -> Callable[..., T]:
|
|
428
|
+
@wraps(func)
|
|
429
|
+
def wrapper(*args: Any, **kwargs: Any) -> T:
|
|
430
|
+
# Use custom start message or default
|
|
431
|
+
start_msg = start_message or f"Start of {func.__name__}"
|
|
432
|
+
start_details: Optional[Dict[str, str]] = None
|
|
433
|
+
if print_args_at_start:
|
|
434
|
+
start_details = {
|
|
435
|
+
"function": func.__name__,
|
|
436
|
+
"args": str(args),
|
|
437
|
+
"kwargs": str(kwargs)
|
|
438
|
+
}
|
|
439
|
+
self.__log(
|
|
440
|
+
level=start_message_log_level,
|
|
441
|
+
message=start_msg,
|
|
442
|
+
details=start_details,
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
# Execute function
|
|
446
|
+
result: T = func(*args, **kwargs)
|
|
447
|
+
|
|
448
|
+
# Use custom end message or default
|
|
449
|
+
end_msg = end_message or f"End of {func.__name__}"
|
|
450
|
+
end_details: Optional[Dict[str, str]] = None
|
|
451
|
+
if print_result_at_end:
|
|
452
|
+
end_details = {
|
|
453
|
+
"function": func.__name__,
|
|
454
|
+
"result": str(result)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
self.__log(
|
|
458
|
+
level=end_message_log_level,
|
|
459
|
+
message=end_msg,
|
|
460
|
+
details=end_details,
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
return result
|
|
464
|
+
|
|
465
|
+
return wrapper
|
|
466
|
+
|
|
467
|
+
return decorator
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pretty-pie-log
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A feature-rich logging utility that provides colorized console output with customizable formatting
|
|
5
|
+
Home-page: https://github.com/chanpreet3000/pretty-pie-log
|
|
6
|
+
Author: chanpreet3000
|
|
7
|
+
Author-email: chanpreet3000@gmail.com
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/chanpreet3000/pretty-pie-log/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/chanpreet3000/pretty-pie-log
|
|
10
|
+
Keywords: logging,colorized,console,debug,formatting,pretty-print,thread-safe,timezone,structured-logging
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: System :: Logging
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
|
|
27
|
+
# pretty-pie-log
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
pretty_pie_log/__init__.py
|
|
5
|
+
pretty_pie_log/examples.py
|
|
6
|
+
pretty_pie_log/pie_log_level.py
|
|
7
|
+
pretty_pie_log/pie_logger.py
|
|
8
|
+
pretty_pie_log.egg-info/PKG-INFO
|
|
9
|
+
pretty_pie_log.egg-info/SOURCES.txt
|
|
10
|
+
pretty_pie_log.egg-info/dependency_links.txt
|
|
11
|
+
pretty_pie_log.egg-info/requires.txt
|
|
12
|
+
pretty_pie_log.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pretty_pie_log
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
# Read README.md for long description
|
|
4
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
|
+
long_description = fh.read()
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name="pretty-pie-log",
|
|
9
|
+
version="0.1.0",
|
|
10
|
+
author="chanpreet3000",
|
|
11
|
+
author_email="chanpreet3000@gmail.com",
|
|
12
|
+
description="A feature-rich logging utility that provides colorized console output with customizable formatting",
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
url="https://github.com/chanpreet3000/pretty-pie-log",
|
|
16
|
+
project_urls={
|
|
17
|
+
"Bug Tracker": "https://github.com/chanpreet3000/pretty-pie-log/issues",
|
|
18
|
+
"Source Code": "https://github.com/chanpreet3000/pretty-pie-log",
|
|
19
|
+
},
|
|
20
|
+
packages=find_packages(),
|
|
21
|
+
classifiers=[
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
"Topic :: System :: Logging",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.7",
|
|
28
|
+
"Programming Language :: Python :: 3.8",
|
|
29
|
+
"Programming Language :: Python :: 3.9",
|
|
30
|
+
"Programming Language :: Python :: 3.10",
|
|
31
|
+
"Programming Language :: Python :: 3.11",
|
|
32
|
+
"License :: OSI Approved :: MIT License",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
],
|
|
35
|
+
python_requires=">=3.7",
|
|
36
|
+
install_requires=[
|
|
37
|
+
"colorama>=0.4.6",
|
|
38
|
+
"pytz>=2024.2"
|
|
39
|
+
],
|
|
40
|
+
keywords=[
|
|
41
|
+
"logging",
|
|
42
|
+
"colorized",
|
|
43
|
+
"console",
|
|
44
|
+
"debug",
|
|
45
|
+
"formatting",
|
|
46
|
+
"pretty-print",
|
|
47
|
+
"thread-safe",
|
|
48
|
+
"timezone",
|
|
49
|
+
"structured-logging"
|
|
50
|
+
],
|
|
51
|
+
package_data={
|
|
52
|
+
"pretty_pie_log": ["py.typed"], # Include type information
|
|
53
|
+
},
|
|
54
|
+
include_package_data=True,
|
|
55
|
+
)
|