Skip to content

Commit

Permalink
Add trace logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed May 2, 2017
1 parent 35f8bc4 commit c4e0f47
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DEVELOP.md
Expand Up @@ -76,7 +76,8 @@ npm run --silent rebuild
- Inspect the Talkie background page view to see console output.
- It is possible to coarsely adjust the console logging level.
- In the background page console, enter one of these logging level commands:
- `this.setLoggingLevel("DEBG");` (maximum logging, default for developers)
- `this.setLoggingLevel("TRAC");` (maximum logging)
- `this.setLoggingLevel("DEBG");` (default for developers)
- `this.setLoggingLevel("INFO");`
- `this.setLoggingLevel("WARN");` (default for normal usage)
- `this.setLoggingLevel("ERRO");`
Expand Down
2 changes: 2 additions & 0 deletions src/background/background.js
Expand Up @@ -24,6 +24,7 @@ import {
} from "../shared/promise";

import {
logTrace,
logDebug,
logInfo,
logWarn,
Expand Down Expand Up @@ -298,6 +299,7 @@ function main() {
.then(() => {
window.broadcaster = () => broadcaster;

window.logTrace = (...args) => logTrace(...args);
window.logDebug = (...args) => logDebug(...args);
window.logInfo = (...args) => logInfo(...args);
window.logWarn = (...args) => logWarn(...args);
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/dual-log.js
Expand Up @@ -19,6 +19,7 @@ along with Talkie. If not, see <https://www.gnu.org/licenses/>.
*/

import {
logTrace,
logDebug,
logInfo,
logWarn,
Expand All @@ -33,6 +34,7 @@ export default class DualLogger {
constructor(localScriptName) {
this.localScriptName = localScriptName;

this.dualLogTrace = this._generateLogger(logTrace, "logTrace");
this.dualLogDebug = this._generateLogger(logDebug, "logDebug");
this.dualLogInfo = this._generateLogger(logInfo, "logInfo");
this.dualLogWarn = this._generateLogger(logWarn, "logWarn");
Expand Down
8 changes: 4 additions & 4 deletions src/shared/broadcaster.js
Expand Up @@ -19,7 +19,7 @@ along with Talkie. If not, see <https://www.gnu.org/licenses/>.
*/

import {
logDebug,
logTrace,
logWarn,
logError,
} from "../shared/log";
Expand Down Expand Up @@ -114,12 +114,12 @@ export default class Broadcaster {
// NOTE: there was no matching action registered.
// throw new Error("There was no matching action: " + actionName);

// logDebug("Skipping", "Sending message", actionName, actionData);
logTrace("Skipping", "Sending message", actionName, actionData);

return undefined;
}

logDebug("Start", "Sending message", actionName, actionData);
logTrace("Start", "Sending message", actionName, actionData);

const listeningActionPromises = listeningActions.map((listeningAction) => {
return promiseTry(
Expand Down Expand Up @@ -148,7 +148,7 @@ export default class Broadcaster {
return undefined;
})
.then(() => {
logDebug("Start", "Sending message", actionName, actionData);
logTrace("Done", "Sending message", actionName, actionData);

return undefined;
})
Expand Down
2 changes: 2 additions & 0 deletions src/shared/log.js
Expand Up @@ -72,6 +72,7 @@ const isDevMode = () => !("update_url" in browser.runtime.getManifest());

// NOTE: 0, 1, ...
const loggingLevels = [
"TRAC",
"DEBG",
"INFO",
"WARN",
Expand Down Expand Up @@ -158,6 +159,7 @@ const generateLogger = (loggingLevelName, consoleFunctioName) => {
return logger;
};

export const logTrace = generateLogger("TRAC", "log");
export const logDebug = generateLogger("DEBG", "log");
export const logInfo = generateLogger("INFO", "info");
export const logWarn = generateLogger("WARN", "warn");
Expand Down

0 comments on commit c4e0f47

Please sign in to comment.