Use logging to log parse errors (#19)
Use `logging` to log parse errors, replacing print()
This commit is contained in:
committed by
GitHub
parent
560a513349
commit
64c07db5b0
+8
-6
@@ -13,6 +13,7 @@
|
|||||||
# https://blogs.msdn.microsoft.com/openspecification/2009/11/06/msg-file-format-part-1/
|
# https://blogs.msdn.microsoft.com/openspecification/2009/11/06/msg-file-format-part-1/
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ from email.utils import parsedate_to_datetime, formatdate, formataddr
|
|||||||
|
|
||||||
import compoundfiles
|
import compoundfiles
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# MAIN FUNCTIONS
|
# MAIN FUNCTIONS
|
||||||
|
|
||||||
@@ -138,7 +141,7 @@ def load_message_stream(entry, is_top_level, doc):
|
|||||||
try:
|
try:
|
||||||
process_attachment(msg, stream, doc)
|
process_attachment(msg, stream, doc)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print("Error processing attachment {} not found".format(str(e)), file=sys.stderr)
|
logger.error("Error processing attachment {} not found".format(str(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
@@ -219,7 +222,7 @@ def parse_properties(properties, is_top_level, container, doc):
|
|||||||
value = innerstream.read()
|
value = innerstream.read()
|
||||||
except:
|
except:
|
||||||
# Stream isn't present!
|
# Stream isn't present!
|
||||||
print("stream missing", streamname, file=sys.stderr)
|
logger.error("stream missing {}".format(streamname))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
value = tag_type.load(value)
|
value = tag_type.load(value)
|
||||||
@@ -231,17 +234,16 @@ def parse_properties(properties, is_top_level, container, doc):
|
|||||||
value = container[streamname]
|
value = container[streamname]
|
||||||
except:
|
except:
|
||||||
# Stream isn't present!
|
# Stream isn't present!
|
||||||
print("stream missing", streamname, file=sys.stderr)
|
logger.error("stream missing {}".format(streamname))
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
value = tag_type.load(value, doc)
|
value = tag_type.load(value, doc)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print("Error while reading stream: {} not found".format(str(e)) , file=sys.stderr)
|
logger.error("Error while reading stream: {} not found".format(str(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# unrecognized type
|
# unrecognized type
|
||||||
print("unhandled property type", hex(property_type), file=sys.stderr)
|
logger.error("unhandled property type {}".format(hex(property_type)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ret[tag_name] = value
|
ret[tag_name] = value
|
||||||
|
|||||||
Reference in New Issue
Block a user