44from pathlib import Path
55import sys
66import threading
7+ from typing import Optional , Union
78import typing_extensions
89import re
910import io
3132URL_CREDENTIALS_PATTERN = (r'(\w+://[^/\s:@]*):[^/\s]+@' , r'\1:***REDACTED***@' )
3233
3334
34- def redact_sensitive_info (message : str , additional_fields : list = None ) -> str :
35+ def redact_sensitive_info (message : str , additional_fields : Optional [ list ] = None ) -> str :
3536 """
3637 Redacts sensitive information from the given message.
3738
@@ -163,7 +164,7 @@ def clear(self):
163164 self .line_count = 0
164165
165166
166- def clear_in_memory_log_handler (logger_name : str = None ) -> None :
167+ def clear_in_memory_log_handler (logger_name : Optional [ str ] = None ) -> None :
167168 if logger_name is None :
168169 # Clear all in-memory log handlers
169170 for handler in in_memory_log_handlers .values ():
@@ -174,8 +175,8 @@ def clear_in_memory_log_handler(logger_name: str = None) -> None:
174175 in_memory_log_handlers [logger_name ].clear ()
175176
176177
177- def write_logs_to_file (logger_name : str = None ) -> None :
178- def rotate_logs (base_path : str , name : str ):
178+ def write_logs_to_file (logger_name : Optional [ str ] = None ) -> None :
179+ def rotate_logs (base_path : Union [ str , os . PathLike ] , name : str ):
179180 # Rotate the log files
180181 for i in range (NUMBER_OF_LOGFILES - 1 , 0 , - 1 ):
181182 src = os .path .join (base_path , f'{ name } .previous{ i } .log' )
@@ -187,7 +188,7 @@ def rotate_logs(base_path: str, name: str):
187188 if os .path .exists (current_log ):
188189 shutil .move (current_log , os .path .join (base_path , f'{ name } .previous1.log' ))
189190
190- def combine_logs (base_path : str , name : str ):
191+ def combine_logs (base_path : Union [ str , os . PathLike ] , name : str ):
191192 latest_log_path = os .path .join (base_path , f'{ name } .latest.log' )
192193 with open (latest_log_path , 'w' ) as latest_log :
193194 for i in range (NUMBER_OF_LOGFILES - 1 , - 1 , - 1 ):
@@ -257,8 +258,8 @@ def setup_generate_totals_logging(include_process_log: bool = False) -> None:
257258
258259
259260def setup_logging () -> None :
260- def mb_to_bytes (megabytes : int ) -> int :
261- return megabytes * 1000000
261+ def mb_to_bytes (megabytes : float ) -> int :
262+ return int ( megabytes * 1000000 )
262263
263264 global in_memory_log_handlers
264265 in_memory_log_handlers = {name : InMemoryLogHandler () for name in ["main" , "internal_chargepoint" ]}
0 commit comments