Skip to content

Commit 3da56da

Browse files
committed
Adding a logging handler to count num errors and warnings
1 parent de903b7 commit 3da56da

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

scripts/blender_igl_export.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# and hit run
66

77
import bpy
8+
import io
89
import logging
910
import numpy as np
1011
import struct
@@ -19,9 +20,41 @@
1920
from pathlib import Path
2021

2122
# 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)
2558

2659
logger = logging.getLogger(__name__)
2760

@@ -470,8 +503,11 @@ def _begin_export(self, context, file_path):
470503
animation = IGLAnimation(igl_skeleton, parent, self.anim_start, self.anim_end)
471504
animation.export(file_path)
472505

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}")
475511

476512
def _get_valid_asset_path(self, filepath):
477513
if len(filepath.split('.')) > 1:

0 commit comments

Comments
 (0)