summaryrefslogtreecommitdiff
path: root/crocoite
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2017-12-27 11:41:39 +0100
committerLars-Dominik Braun <lars@6xq.net>2017-12-27 11:41:39 +0100
commit1bf7b6822eb3dce006fc3eab739f50fd384453f8 (patch)
treeb38fe4160d950685d23286a431da19c805314ef0 /crocoite
parentdb16876dda53424725041eec26be1ca7a45a17af (diff)
downloadcrocoite-1bf7b6822eb3dce006fc3eab739f50fd384453f8.tar.gz
crocoite-1bf7b6822eb3dce006fc3eab739f50fd384453f8.tar.bz2
crocoite-1bf7b6822eb3dce006fc3eab739f50fd384453f8.zip
Log messages from browser console
Diffstat (limited to 'crocoite')
-rw-r--r--crocoite/browser.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/crocoite/browser.py b/crocoite/browser.py
index 06f2b22..23b251f 100644
--- a/crocoite/browser.py
+++ b/crocoite/browser.py
@@ -91,12 +91,14 @@ class SiteLoader:
tab.Network.responseReceived = self._responseReceived
tab.Network.loadingFinished = self._loadingFinished
tab.Network.loadingFailed = self._loadingFailed
+ tab.Log.entryAdded = self._entryAdded
#tab.Page.loadEventFired = loadEventFired
# start the tab
tab.start()
# enable events
+ tab.Log.enable ()
tab.Network.enable()
tab.Page.enable ()
tab.Network.clearBrowserCache ()
@@ -137,6 +139,7 @@ class SiteLoader:
tab.Page.stopLoading ()
tab.Network.disable ()
tab.Page.disable ()
+ tab.Log.disable ()
# XXX: we can’t drain the event queue directly, so insert (yet another) wait
tab.wait (1)
tab.Network.requestWillBeSent = None
@@ -144,6 +147,7 @@ class SiteLoader:
tab.Network.loadingFinished = None
tab.Network.loadingFailed = None
tab.Page.loadEventFired = None
+ tab.Log.entryAdded = None
def __exit__ (self, exc_type, exc_value, traceback):
self.tab.stop ()
@@ -224,6 +228,14 @@ class SiteLoader:
item = self.requests.pop (reqId, None)
self.loadingFailed (item)
+ def _entryAdded (self, **kwargs):
+ """ Log entry added """
+ entry = kwargs['entry']
+ level = {'verbose': logging.DEBUG, 'info': logging.INFO,
+ 'warning': logging.WARNING,
+ 'error': logging.ERROR}[entry['level']]
+ self.logger.log (level, 'console: {}: {}'.format (entry['source'], entry['text']), extra=entry)
+
class AccountingSiteLoader (SiteLoader):
"""
SiteLoader that keeps basic statistics about retrieved pages.