Skip to content

Commit 1984ee3

Browse files
author
Kurt Yoder
authored
Merge pull request #60 from einarf/logging
Logging
2 parents 9dd0ad7 + 92406d9 commit 1984ee3

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ obj = pywavefront.Wavefront('something.obj')
7676
visualization.draw(obj)
7777
```
7878

79+
## Logging
80+
81+
The default log level is `ERROR`. This is configurable including overriding the formatter.
82+
83+
```python
84+
import logging
85+
import pywavefront
86+
87+
pywavefront.configure_logging(
88+
logging.DEBUG,
89+
formatter=logging.Formatter('%(name)s-%(levelname)s: %(message)s')
90+
)
91+
```
92+
7993
### Example Scripts
8094

8195
The `example` directory contains some basic examples using the `visualization` module

pywavefront/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
# POSSIBILITY OF SUCH DAMAGE.
3333
# ----------------------------------------------------------------------------
34+
import logging
35+
3436
from pywavefront.exceptions import PywavefrontException
3537
from pywavefront.obj import ObjParser
3638
from pywavefront.wavefront import Wavefront
39+
40+
logger = logging.getLogger("pywavefront")
41+
log_handler = logging.StreamHandler()
42+
logger.addHandler(log_handler)
43+
44+
45+
def configure_logging(level, formatter=None):
46+
logger.setLevel(level)
47+
log_handler.setLevel(level)
48+
49+
if formatter:
50+
log_handler.setFormatter(formatter)
51+
52+
53+
configure_logging(logging.ERROR, logging.Formatter('%(name)s-%(levelname)s: %(message)s'))

pywavefront/material.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
# POSSIBILITY OF SUCH DAMAGE.
3333
# ----------------------------------------------------------------------------
34+
import logging
3435
import os
3536

3637
from pywavefront.parser import Parser, auto_consume
3738
from pywavefront.texture import Texture
3839

40+
logger = logging.getLogger("pywavefront")
41+
3942

4043
class Material(object):
4144
def __init__(self, name=None, is_default=False):

pywavefront/obj.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import logging
12
import os
23

34
from pywavefront.exceptions import PywavefrontException
45
from pywavefront.parser import Parser, auto_consume
56
from pywavefront.material import Material, MaterialParser
67
from pywavefront.mesh import Mesh
78

9+
logger = logging.getLogger("pywavefront")
10+
811

912
class ObjParser(Parser):
1013
"""This parser parses lines from .obj files."""

pywavefront/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
from pywavefront.exceptions import PywavefrontException
4141

42+
logger = logging.getLogger("pywavefront")
43+
4244

4345
def auto_consume(func):
4446
"""Decorator for auto consuming lines when leaving the function"""
@@ -141,7 +143,7 @@ def parse_fallback(self):
141143
raise PywavefrontException("Unimplemented OBJ format statement '%s' on line '%s'"
142144
% (self.values[0], self.line.rstrip()))
143145
else:
144-
logging.warning("Unimplemented OBJ format statement '%s' on line '%s'"
146+
logger.warning("Unimplemented OBJ format statement '%s' on line '%s'"
145147
% (self.values[0], self.line.rstrip()))
146148

147149
def _build_dispatch_map(self):

pywavefront/wavefront.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import logging
12
from pywavefront import ObjParser
23

4+
logger = logging.getLogger("pywavefront")
5+
36

47
class Wavefront(object):
58
# Can be used to override the parser when extending the class

0 commit comments

Comments
 (0)