|
5 | 5 | # and hit run |
6 | 6 |
|
7 | 7 | import bpy |
| 8 | +import io |
8 | 9 | import logging |
9 | 10 | import numpy as np |
10 | 11 | import struct |
|
19 | 20 | from pathlib import Path |
20 | 21 |
|
21 | 22 | # LOGGING SETUP |
22 | | -log_file = str(Path('~/Documents/blender_igl_export.log').expanduser()) |
23 | | -logging.basicConfig(filename=log_file, |
24 | | - filemode='w', level=logging.DEBUG, force=True) |
| 23 | +class ExportFileHandler(logging.FileHandler): |
| 24 | + def __init__(self) -> None: |
| 25 | + self._log_file = str(Path('~/Documents/blender_igl_export.log').expanduser()) |
| 26 | + super().__init__( |
| 27 | + self._log_file, |
| 28 | + "w", |
| 29 | + None, |
| 30 | + False, |
| 31 | + 'backslashreplace') |
| 32 | + |
| 33 | + self._n_errors = 0 |
| 34 | + self._n_warns = 0 |
| 35 | + |
| 36 | + @property |
| 37 | + def log_file(self): |
| 38 | + return self._log_file |
| 39 | + |
| 40 | + @property |
| 41 | + def num_warns(self): |
| 42 | + return self._n_warns |
| 43 | + |
| 44 | + @property |
| 45 | + def num_errors(self): |
| 46 | + return self._n_errors |
| 47 | + |
| 48 | + def emit(self, record) -> None: |
| 49 | + if record.levelno == logging.ERROR or record.levelno == logging.CRITICAL: |
| 50 | + self._n_errors += 1 |
| 51 | + elif record.levelno == logging.WARN or record.levelno == logging.WARNING: |
| 52 | + self._n_warns += 1 |
| 53 | + |
| 54 | + return super().emit(record) |
| 55 | + |
| 56 | +log_handler = ExportFileHandler() |
| 57 | +logging.basicConfig(handlers=[log_handler], level=logging.DEBUG, force=True) |
25 | 58 |
|
26 | 59 | logger = logging.getLogger(__name__) |
27 | 60 |
|
@@ -470,8 +503,11 @@ def _begin_export(self, context, file_path): |
470 | 503 | animation = IGLAnimation(igl_skeleton, parent, self.anim_start, self.anim_end) |
471 | 504 | animation.export(file_path) |
472 | 505 |
|
473 | | - self.report({'INFO'}, f"Finished Export to {file_path}") |
474 | | - self.report({'INFO'}, f"Log dumped to {log_file}") |
| 506 | + self.report({'INFO'}, ( |
| 507 | + f"Finished Export to {file_path}." |
| 508 | + f" Errors: {log_handler.num_errors}, Warnings: {log_handler.num_warns}" |
| 509 | + )) |
| 510 | + self.report({'INFO'}, f"Log dumped to {log_handler.log_file}") |
475 | 511 |
|
476 | 512 | def _get_valid_asset_path(self, filepath): |
477 | 513 | if len(filepath.split('.')) > 1: |
|
0 commit comments