mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-24 08:39:59 -05:00
__init__: port logging statements
This commit is contained in:
parent
712ecb9690
commit
a7e915b35f
@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import structlog
|
||||||
from pkg_resources import get_distribution as _get_distribution
|
from pkg_resources import get_distribution as _get_distribution
|
||||||
|
|
||||||
__version__ = _get_distribution("brozzler").version
|
__version__ = _get_distribution("brozzler").version
|
||||||
@ -146,7 +147,9 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
|||||||
"""
|
"""
|
||||||
Returns the javascript behavior string populated with template_parameters.
|
Returns the javascript behavior string populated with template_parameters.
|
||||||
"""
|
"""
|
||||||
import re, logging, json
|
import re, json
|
||||||
|
|
||||||
|
logger = structlog.get_logger()
|
||||||
|
|
||||||
for behavior in behaviors(behaviors_dir=behaviors_dir):
|
for behavior in behaviors(behaviors_dir=behaviors_dir):
|
||||||
if re.match(behavior["url_regex"], url):
|
if re.match(behavior["url_regex"], url):
|
||||||
@ -159,18 +162,18 @@ def behavior_script(url, template_parameters=None, behaviors_dir=None):
|
|||||||
behavior["behavior_js_template"]
|
behavior["behavior_js_template"]
|
||||||
)
|
)
|
||||||
script = template.render(parameters)
|
script = template.render(parameters)
|
||||||
logging.info(
|
logger.info(
|
||||||
"using template=%r populated with parameters=%r for %r",
|
"rendering template",
|
||||||
behavior["behavior_js_template"],
|
template=behavior["behavior_js_template"],
|
||||||
json.dumps(parameters),
|
parameters=json.dumps(parameters),
|
||||||
url,
|
url=url,
|
||||||
)
|
)
|
||||||
return script
|
return script
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ThreadExceptionGate:
|
class ThreadExceptionGate:
|
||||||
logger = logging.getLogger(__module__ + "." + __qualname__)
|
logger = structlog.get_logger(__module__ + "." + __qualname__)
|
||||||
|
|
||||||
def __init__(self, thread):
|
def __init__(self, thread):
|
||||||
self.thread = thread
|
self.thread = thread
|
||||||
@ -181,7 +184,7 @@ class ThreadExceptionGate:
|
|||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
assert self.thread == threading.current_thread()
|
assert self.thread == threading.current_thread()
|
||||||
if self.pending_exception:
|
if self.pending_exception:
|
||||||
self.logger.info("raising pending exception %s", self.pending_exception)
|
self.logger.info("raising pending exception", pending_exception=self.pending_exception)
|
||||||
tmp = self.pending_exception
|
tmp = self.pending_exception
|
||||||
self.pending_exception = None
|
self.pending_exception = None
|
||||||
raise tmp
|
raise tmp
|
||||||
@ -198,10 +201,10 @@ class ThreadExceptionGate:
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
if self.pending_exception:
|
if self.pending_exception:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"%r already pending for thread %r, discarding %r",
|
"exception already pending for thread, discarding",
|
||||||
self.pending_exception,
|
pending_exception=self.pending_exception,
|
||||||
self.thread,
|
thread=self.thread,
|
||||||
e,
|
exception=e,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.pending_exception = e
|
self.pending_exception = e
|
||||||
@ -266,7 +269,9 @@ def thread_raise(thread, exctype):
|
|||||||
TypeError if `exctype` is not a class
|
TypeError if `exctype` is not a class
|
||||||
ValueError, SystemError in case of unexpected problems
|
ValueError, SystemError in case of unexpected problems
|
||||||
"""
|
"""
|
||||||
import ctypes, inspect, threading, logging
|
import ctypes, inspect, threading, structlog
|
||||||
|
|
||||||
|
logger = structlog.get_logger(exctype=exctype, thread=thread)
|
||||||
|
|
||||||
if not inspect.isclass(exctype):
|
if not inspect.isclass(exctype):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
@ -278,7 +283,7 @@ def thread_raise(thread, exctype):
|
|||||||
with gate.lock:
|
with gate.lock:
|
||||||
if gate.ok_to_raise.is_set() and thread.is_alive():
|
if gate.ok_to_raise.is_set() and thread.is_alive():
|
||||||
gate.ok_to_raise.clear()
|
gate.ok_to_raise.clear()
|
||||||
logging.info("raising %s in thread %s", exctype, thread)
|
logger.info("raising exception in thread")
|
||||||
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
|
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
|
||||||
ctypes.c_long(thread.ident), ctypes.py_object(exctype)
|
ctypes.c_long(thread.ident), ctypes.py_object(exctype)
|
||||||
)
|
)
|
||||||
@ -290,7 +295,7 @@ def thread_raise(thread, exctype):
|
|||||||
ctypes.pythonapi.PyThreadState_SetAsyncExc(thread.ident, 0)
|
ctypes.pythonapi.PyThreadState_SetAsyncExc(thread.ident, 0)
|
||||||
raise SystemError("PyThreadState_SetAsyncExc failed")
|
raise SystemError("PyThreadState_SetAsyncExc failed")
|
||||||
else:
|
else:
|
||||||
logging.info("queueing %s for thread %s", exctype, thread)
|
logger.info("queueing exception for thread")
|
||||||
gate.queue_exception(exctype)
|
gate.queue_exception(exctype)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user