Skip to content

Commit 5965ebc

Browse files
committed
Added log levels
1 parent 4871dc0 commit 5965ebc

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

src/Log.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Log {
2+
var LOG_LEVEL: LogLevel = LogLevel.Error;
3+
export enum LogLevel {
4+
Error, Warning, Info, Debug
5+
}
6+
7+
export function error(message: any) {
8+
log(LogLevel.Error, message);
9+
}
10+
11+
export function warning(message: any) {
12+
log(LogLevel.Warning, message);
13+
}
14+
15+
export function info(message: any) {
16+
log(LogLevel.Info, message);
17+
}
18+
19+
export function debug(message: any) {
20+
log(LogLevel.Debug, message);
21+
}
22+
23+
function log(level: LogLevel, message: any) {
24+
if (level <= LOG_LEVEL) {
25+
console.log(message);
26+
}
27+
}
28+
}

src/Utils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
/// <reference path="d.ts/DefinitelyTyped/chrome/chrome.d.ts"/>
22

33
module Utils {
4-
var logging = false;
5-
export function log(message: any) {
6-
if (logging) {
7-
console.log(message);
8-
}
9-
}
10-
114
export interface ActiveTabCallback {
125
(tab: chrome.tabs.Tab) : void;
136
}

src/background/KeyboardHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/// <reference path="../d.ts/DefinitelyTyped/chrome/chrome.d.ts"/>
22
/// <reference path="../Utils.ts"/>
3+
/// <reference path="../Log.ts"/>
34
/// <reference path="TabStateManager.ts"/>
45

56
module KeyboardHandler {
67
var lastCalled: number = 0;
78

89
export function init(tabStates: TabStateManager) {
910
chrome.commands.onCommand.addListener(function (command: string) {
10-
Utils.log("Received command " + command);
11-
Utils.withActiveTab(function (tab: chrome.tabs.Tab) {
11+
Log.info("Received command " + command);
12+
Utils.withActiveTab(function(tab: chrome.tabs.Tab) {
1213
var id = tab.id;
1314

1415
// The time hack is to get around this function being called twice when

src/background/TabStateManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class TabStateManager {
2323
public set(tabId: number, propName: string, propVal: any);
2424
public set(tabId: number, stateOrPropName: any, propVal?: any) {
2525
if (typeof propVal === "undefined") {
26-
Utils.log("Set " + tabId + " to:");
27-
Utils.log(stateOrPropName);
26+
Log.debug("Set " + tabId + " to:");
27+
Log.debug(stateOrPropName);
2828
this.tabStates[tabId] = stateOrPropName;
2929
} else {
30-
Utils.log("Set " + stateOrPropName + " for " + tabId + " to " + propVal);
30+
Log.debug("Set " + stateOrPropName + " for " + tabId + " to " + propVal);
3131
this.tabStates[tabId][stateOrPropName] = propVal;
3232
}
3333
}

src/popup/popup.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="../d.ts/DefinitelyTyped/chrome/chrome.d.ts"/>
22
/// <reference path="../bg-interface.ts"/>
33
/// <reference path="../Utils.ts"/>
4+
/// <reference path="../Log.ts"/>
45

56
module Popup {
67
var prevButton = document.getElementById("prev");
@@ -16,10 +17,9 @@ module Popup {
1617
// may be a few edge cases where we need to initialize it ourselves,
1718
// like if we enable/reload the extension
1819
if (!tabStates.exists(id)) {
19-
Utils.log("ID doesn't exist. Initializing entry.")
20+
Log.warning("ID doesn't exist. Initializing entry.")
2021
tabStates.resetState(id);
2122
var tabState = tabStates.get(id);
22-
Utils.log(tabState);
2323
}
2424

2525
addListeners(id, tabStates);
@@ -60,7 +60,7 @@ module Popup {
6060

6161
var queryInputKeyDown = function(event) {
6262
if (event.keyCode == 13) {
63-
Utils.log("Enter pressed");
63+
Log.info("Enter pressed");
6464
search(id, tabStates);
6565
}
6666
}
@@ -80,7 +80,7 @@ module Popup {
8080
}
8181

8282
var checkboxClick = function() {
83-
Utils.log("Set checkbox state to " + caseInsensitiveCheckbox.checked);
83+
Log.info("Set checkbox state to " + caseInsensitiveCheckbox.checked);
8484
tabStates.set(id, "caseInsensitive", caseInsensitiveCheckbox.checked);
8585
}
8686

@@ -109,7 +109,7 @@ module Popup {
109109
});
110110
setSearching(tabId, true, tabStates);
111111
} else {
112-
Utils.log("Invalid regex");
112+
Log.info("Invalid regex");
113113
queryInput.className = 'invalid';
114114
}
115115
}

0 commit comments

Comments
 (0)