This function will update log file Args: msg: message (bytes from subprocess) Returns: None
(self, msg)
| 189 | self.stream = stream |
| 190 | |
| 191 | def log(self, msg): |
| 192 | """ |
| 193 | This function will update log file |
| 194 | |
| 195 | Args: |
| 196 | msg: message (bytes from subprocess) |
| 197 | |
| 198 | Returns: |
| 199 | None |
| 200 | """ |
| 201 | # Write into log file |
| 202 | if self.logger: |
| 203 | if msg: |
| 204 | self.logger.write( |
| 205 | get_current_time( |
| 206 | format='%y%m%d%H%M%S%f' |
| 207 | ).encode('utf-8') |
| 208 | ) |
| 209 | self.logger.write(b',') |
| 210 | |
| 211 | # Convert subprocess output from system encoding to UTF-8 |
| 212 | # This fixes garbled text on Windows with non-UTF-8 locales |
| 213 | # (e.g., Japanese CP932, Chinese GBK) |
| 214 | msg = msg.lstrip(b'\r\n' if _IS_WIN else b'\n') |
| 215 | if _subprocess_encoding and \ |
| 216 | _subprocess_encoding.lower() not in ('utf-8', 'utf8'): |
| 217 | try: |
| 218 | msg = msg.decode( |
| 219 | _subprocess_encoding, 'replace' |
| 220 | ).encode('utf-8') |
| 221 | except (UnicodeDecodeError, LookupError): |
| 222 | # If decoding fails, write as-is |
| 223 | pass |
| 224 | |
| 225 | self.logger.write(msg) |
| 226 | self.logger.write(os.linesep.encode('utf-8')) |
| 227 | |
| 228 | return True |
| 229 | return False |
| 230 | |
| 231 | def run(self): |
| 232 | if self.process and self.stream: |