From e507eb8e3fc1b7f6a9ff7fb0c46760161997912a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 6 Mar 2016 07:28:41 +0000 Subject: Logging; move logMessage to BgUtils." --- background_scripts/bg_utils.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'background_scripts/bg_utils.coffee') diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index ca042686..0b6e4338 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -53,4 +53,16 @@ class TabRecency BgUtils = tabRecency: new TabRecency() + # Log messages to the extension's logging page, but only if that page is open. + log: do -> + loggingPageUrl = chrome.runtime.getURL "pages/logging.html" + console.log "Vimium logging URL:\n #{loggingPageUrl}" if loggingPageUrl? # Do not output URL for tests. + (message, sender = null) -> + for viewWindow in chrome.extension.getViews {type: "tab"} + if viewWindow.location.pathname == "/pages/logging.html" + # Don't log messages from the logging page itself. We do this check late because most of the time + # it's not needed. + if sender?.url != loggingPageUrl + viewWindow.document.getElementById("log-text").value += "#{(new Date()).toISOString()}: #{message}\n" + root.BgUtils = BgUtils -- cgit v1.2.3 From a7cd51c8b4c6694ec66711535dbba4ba7a3b813b Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 6 Mar 2016 07:39:23 +0000 Subject: Logging; add auto-lauch option. --- background_scripts/bg_utils.coffee | 2 ++ 1 file changed, 2 insertions(+) (limited to 'background_scripts/bg_utils.coffee') diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index 0b6e4338..bff005ab 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -57,6 +57,8 @@ BgUtils = log: do -> loggingPageUrl = chrome.runtime.getURL "pages/logging.html" console.log "Vimium logging URL:\n #{loggingPageUrl}" if loggingPageUrl? # Do not output URL for tests. + # For development, it's sometimes useful to automatically launch the logging page on reload. + chrome.windows.create url: loggingPageUrl, focused: false if localStorage.autoLaunchLoggingPage (message, sender = null) -> for viewWindow in chrome.extension.getViews {type: "tab"} if viewWindow.location.pathname == "/pages/logging.html" -- cgit v1.2.3 From 5bdf71a3c5b4c1a342c5c6bc644e8feea62d17b8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 6 Mar 2016 07:53:32 +0000 Subject: Logging; only show the time... ... we know what day it is! --- background_scripts/bg_utils.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'background_scripts/bg_utils.coffee') diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index bff005ab..ca823247 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -65,6 +65,14 @@ BgUtils = # Don't log messages from the logging page itself. We do this check late because most of the time # it's not needed. if sender?.url != loggingPageUrl - viewWindow.document.getElementById("log-text").value += "#{(new Date()).toISOString()}: #{message}\n" + date = new Date + [hours, minutes, seconds, milliseconds] = + [date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()] + minutes = "0" + minutes if minutes < 10 + seconds = "0" + seconds if seconds < 10 + milliseconds = "00" + milliseconds if milliseconds < 10 + milliseconds = "0" + milliseconds if milliseconds < 100 + dateString = "#{hours}:#{minutes}:#{seconds}.#{milliseconds}" + viewWindow.document.getElementById("log-text").value += "#{dateString}: #{message}\n" root.BgUtils = BgUtils -- cgit v1.2.3 From 5eae0eebd96357a67853de79a47c01d5e1bd4e3d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 6 Mar 2016 08:03:18 +0000 Subject: Logging; auto scroll to end. --- background_scripts/bg_utils.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'background_scripts/bg_utils.coffee') diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index ca823247..ea54c900 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -73,6 +73,8 @@ BgUtils = milliseconds = "00" + milliseconds if milliseconds < 10 milliseconds = "0" + milliseconds if milliseconds < 100 dateString = "#{hours}:#{minutes}:#{seconds}.#{milliseconds}" - viewWindow.document.getElementById("log-text").value += "#{dateString}: #{message}\n" + logElement = viewWindow.document.getElementById "log-text" + logElement.value += "#{dateString}: #{message}\n" + logElement.scrollTop = 2000000000 root.BgUtils = BgUtils -- cgit v1.2.3