python-printr 4.1__tar.gz → 4.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-printr
3
- Version: 4.1
3
+ Version: 4.3
4
4
  Summary: printr
5
5
  Home-page: https://github.com/xjxckk/python-printr/
6
6
  Download-URL: https://github.com/xjxckk/python-printr/archive/refs/tags/v0.1.tar.gz
@@ -21,6 +21,7 @@ class Logger:
21
21
 
22
22
  logger = logging.getLogger(__name__)
23
23
  logger.setLevel(self.level)
24
+ logger.propagate = False # Disable duplicate messages with headless Chrome
24
25
 
25
26
  if log_to_file:
26
27
  log_file = logging.FileHandler(log_filepath, encoding='utf-8')
@@ -68,13 +69,33 @@ class Logger:
68
69
  coloredlogs.install(level=self.level, logger=self.logger, fmt=self.indent + '%(message)s') # Reset to default log format
69
70
 
70
71
  if self.log_to_file:
71
- log_file = open(self.log_filepath, 'r+', encoding='utf-8', errors='ignore').read()
72
- number_of_lines = len(log_file.splitlines())
72
+ with open(self.log_filepath, 'r+', encoding='utf-8', errors='ignore') as log_file:
73
+ number_of_lines = len(log_file.readlines())
74
+
73
75
  if number_of_lines > self.max_lines:
74
76
  self.logger.info('Resetting log file')
77
+
78
+ # Remove and close the current log file handler
79
+ self.logger.removeHandler(self.log_file)
75
80
  self.log_file.close()
76
- # sleep(10)
77
- # os.replace(self.log_filepath, self.backup_log_filepath)
81
+
82
+ # Rename the current log file to FILE_NAME_2nd_log.txt
83
+ os.replace(self.log_filepath, self.backup_log_filepath)
84
+
85
+ # # Retry logic for renaming the file
86
+ # retries = 5
87
+ # for attempt in range(retries):
88
+ # try:
89
+ # # Rename the current log file to FILE_NAME_2nd_log.txt
90
+ # os.replace(self.log_filepath, self.backup_log_filepath)
91
+ # break
92
+ # except PermissionError:
93
+ # if attempt < retries - 1:
94
+ # print('Permission error renaming log, retrying')
95
+ # sleep(1) # Wait for 1 second before retrying
96
+ # else:
97
+ # raise
98
+
78
99
  log_file = logging.FileHandler(self.log_filepath, mode='w', encoding='utf-8')
79
100
  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
101
  log_file.setFormatter(log_format)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-printr
3
- Version: 4.1
3
+ Version: 4.3
4
4
  Summary: printr
5
5
  Home-page: https://github.com/xjxckk/python-printr/
6
6
  Download-URL: https://github.com/xjxckk/python-printr/archive/refs/tags/v0.1.tar.gz
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
  setup(
4
4
  name = 'python-printr',
5
5
  packages = ['printr'],
6
- version = '4.1',
6
+ version = '4.3',
7
7
  install_requires=['coloredlogs'],
8
8
  description = 'printr',
9
9
  url = 'https://github.com/xjxckk/python-printr/',
File without changes
File without changes
File without changes