python-printr 4.5__tar.gz → 4.7__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.5/python_printr.egg-info → python-printr-4.7}/PKG-INFO +1 -1
- {python-printr-4.5 → python-printr-4.7}/printr/__init__.py +11 -23
- {python-printr-4.5 → python-printr-4.7/python_printr.egg-info}/PKG-INFO +1 -1
- {python-printr-4.5 → python-printr-4.7}/setup.py +1 -1
- {python-printr-4.5 → python-printr-4.7}/.gitignore +0 -0
- {python-printr-4.5 → python-printr-4.7}/README.md +0 -0
- {python-printr-4.5 → python-printr-4.7}/python_printr.egg-info/SOURCES.txt +0 -0
- {python-printr-4.5 → python-printr-4.7}/python_printr.egg-info/dependency_links.txt +0 -0
- {python-printr-4.5 → python-printr-4.7}/python_printr.egg-info/requires.txt +0 -0
- {python-printr-4.5 → python-printr-4.7}/python_printr.egg-info/top_level.txt +0 -0
- {python-printr-4.5 → python-printr-4.7}/setup.cfg +0 -0
|
@@ -7,16 +7,15 @@ class Logger:
|
|
|
7
7
|
def __init__(self, log_filepath=None, max_lines=10_000, level='info', name=None, log_to_file=True):
|
|
8
8
|
filename = Path(sys.argv[0]).stem
|
|
9
9
|
if not log_filepath:
|
|
10
|
-
log_filepath = f'{os.getcwd()}/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
log_filepath = f'{os.getcwd()}/{filename}.txt'
|
|
11
|
+
else:
|
|
12
|
+
path_tree = log_filepath.split('/') # ['logs', 'bot.txt']
|
|
13
|
+
if len(path_tree) > 1:
|
|
14
|
+
folder_path = '/'.join(path_tree[:-1]) # Remove last item to just keep folder path - e.g. ['logs']
|
|
15
|
+
if not os.path.isdir(folder_path):
|
|
16
|
+
os.mkdir(folder_path)
|
|
17
17
|
|
|
18
18
|
self.log_filepath = log_filepath
|
|
19
|
-
self.backup_log_filepath = log_filepath.replace('.txt', '_2nd_log.txt')
|
|
20
19
|
self.max_lines = max_lines
|
|
21
20
|
self.log_to_file = log_to_file
|
|
22
21
|
|
|
@@ -86,21 +85,10 @@ class Logger:
|
|
|
86
85
|
self.log_file.close()
|
|
87
86
|
|
|
88
87
|
# Rename the current log file to FILE_NAME_2nd_log.txt
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
# for attempt in range(retries):
|
|
94
|
-
# try:
|
|
95
|
-
# # Rename the current log file to FILE_NAME_2nd_log.txt
|
|
96
|
-
# os.replace(self.log_filepath, self.backup_log_filepath)
|
|
97
|
-
# break
|
|
98
|
-
# except PermissionError:
|
|
99
|
-
# if attempt < retries - 1:
|
|
100
|
-
# print('Permission error renaming log, retrying')
|
|
101
|
-
# sleep(1) # Wait for 1 second before retrying
|
|
102
|
-
# else:
|
|
103
|
-
# raise
|
|
88
|
+
current_datetime = datetime.now()
|
|
89
|
+
formatted_datetime = current_datetime.strftime('%Y-%m-%d %H-%M-%S')
|
|
90
|
+
archive_log_filepath = self.log_filepath.replace('.txt', f' {formatted_datetime}.txt')
|
|
91
|
+
os.replace(self.log_filepath, archive_log_filepath)
|
|
104
92
|
|
|
105
93
|
log_file = logging.FileHandler(self.log_filepath, mode='w', encoding='utf-8')
|
|
106
94
|
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')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|