python-printr 4.0__tar.gz → 4.2__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.
- {python-printr-4.0/python_printr.egg-info → python-printr-4.2}/PKG-INFO +1 -1
- {python-printr-4.0 → python-printr-4.2}/printr/__init__.py +28 -6
- {python-printr-4.0 → python-printr-4.2/python_printr.egg-info}/PKG-INFO +1 -1
- {python-printr-4.0 → python-printr-4.2}/setup.py +1 -1
- {python-printr-4.0 → python-printr-4.2}/.gitignore +0 -0
- {python-printr-4.0 → python-printr-4.2}/README.md +0 -0
- {python-printr-4.0 → python-printr-4.2}/python_printr.egg-info/SOURCES.txt +0 -0
- {python-printr-4.0 → python-printr-4.2}/python_printr.egg-info/dependency_links.txt +0 -0
- {python-printr-4.0 → python-printr-4.2}/python_printr.egg-info/requires.txt +0 -0
- {python-printr-4.0 → python-printr-4.2}/python_printr.egg-info/top_level.txt +0 -0
- {python-printr-4.0 → python-printr-4.2}/setup.cfg +0 -0
|
@@ -3,7 +3,7 @@ from time import sleep
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class Logger:
|
|
7
7
|
def __init__(self, log_filepath=None, max_lines=100_000, level='info', name=None, log_to_file=True):
|
|
8
8
|
filename = Path(sys.argv[0]).stem
|
|
9
9
|
self.filename = filename
|
|
@@ -68,13 +68,33 @@ class logger:
|
|
|
68
68
|
coloredlogs.install(level=self.level, logger=self.logger, fmt=self.indent + '%(message)s') # Reset to default log format
|
|
69
69
|
|
|
70
70
|
if self.log_to_file:
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
with open(self.log_filepath, 'r+', encoding='utf-8', errors='ignore') as log_file:
|
|
72
|
+
number_of_lines = len(log_file.readlines())
|
|
73
|
+
|
|
73
74
|
if number_of_lines > self.max_lines:
|
|
74
75
|
self.logger.info('Resetting log file')
|
|
76
|
+
|
|
77
|
+
# Remove and close the current log file handler
|
|
78
|
+
self.logger.removeHandler(self.log_file)
|
|
75
79
|
self.log_file.close()
|
|
76
|
-
|
|
77
|
-
#
|
|
80
|
+
|
|
81
|
+
# Rename the current log file to FILE_NAME_2nd_log.txt
|
|
82
|
+
os.replace(self.log_filepath, self.backup_log_filepath)
|
|
83
|
+
|
|
84
|
+
# # Retry logic for renaming the file
|
|
85
|
+
# retries = 5
|
|
86
|
+
# for attempt in range(retries):
|
|
87
|
+
# try:
|
|
88
|
+
# # Rename the current log file to FILE_NAME_2nd_log.txt
|
|
89
|
+
# os.replace(self.log_filepath, self.backup_log_filepath)
|
|
90
|
+
# break
|
|
91
|
+
# except PermissionError:
|
|
92
|
+
# if attempt < retries - 1:
|
|
93
|
+
# print('Permission error renaming log, retrying')
|
|
94
|
+
# sleep(1) # Wait for 1 second before retrying
|
|
95
|
+
# else:
|
|
96
|
+
# raise
|
|
97
|
+
|
|
78
98
|
log_file = logging.FileHandler(self.log_filepath, mode='w', encoding='utf-8')
|
|
79
99
|
log_format = logging.Formatter(fmt=self.indent + '%(levelname)s - %(asctime)s.%(msecs)03d - Line %(lineno)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
|
80
100
|
log_file.setFormatter(log_format)
|
|
@@ -180,4 +200,6 @@ def prettify(items, beautify):
|
|
|
180
200
|
except TypeError:
|
|
181
201
|
pass
|
|
182
202
|
message += str(item)
|
|
183
|
-
return message
|
|
203
|
+
return message
|
|
204
|
+
|
|
205
|
+
logger = Logger
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|