##// END OF EJS Templates
use logger for canning import error
MinRK -
Show More
@@ -16,6 +16,7 b' __docformat__ = "restructuredtext en"'
16 16 #-------------------------------------------------------------------------------
17 17
18 18 import copy
19 import logging
19 20 import sys
20 21 from types import FunctionType
21 22
@@ -33,6 +34,8 b' import codeutil'
33 34 import py3compat
34 35 from importstring import import_item
35 36
37 from IPython.config import Application
38
36 39 if py3compat.PY3:
37 40 buffer = memoryview
38 41
@@ -142,6 +145,14 b' def CannedBuffer(CannedBytes):'
142 145 # Functions
143 146 #-------------------------------------------------------------------------------
144 147
148 def _error(*args, **kwargs):
149 if Application.initialized():
150 logger = Application.instance().log
151 else:
152 logger = logging.getLogger()
153 if not logger.handlers:
154 logging.basicConfig()
155 logger.error(*args, **kwargs)
145 156
146 157 def can(obj):
147 158 """prepare an object for pickling"""
@@ -150,8 +161,8 b' def can(obj):'
150 161 try:
151 162 cls = import_item(cls)
152 163 except Exception:
153 # not importable
154 print "not importable: %r" % cls
164 _error("cannning class not importable: %r", cls, exc_info=True)
165 cls = None
155 166 continue
156 167 if isinstance(obj, cls):
157 168 return canner(obj)
@@ -182,8 +193,8 b' def uncan(obj, g=None):'
182 193 try:
183 194 cls = import_item(cls)
184 195 except Exception:
185 # not importable
186 print "not importable: %r" % cls
196 _error("uncanning class not importable: %r", cls, exc_info=True)
197 cls = None
187 198 continue
188 199 if isinstance(obj, cls):
189 200 return uncanner(obj, g)
General Comments 0
You need to be logged in to leave comments. Login now