From 2ecc5fdd8a04ac4acc07deb5fa08ec73a765a727 Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Mon, 6 Aug 2018 21:34:04 +0000 Subject: [PATCH] Properly set npm debug log filter --- src/hub.html | 3 --- src/hub.js | 1 + src/utils/logging.js | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/utils/logging.js diff --git a/src/hub.html b/src/hub.html index 45a849b2f..1b8402632 100644 --- a/src/hub.html +++ b/src/hub.html @@ -10,9 +10,6 @@ <link rel="shortcut icon" type="image/png" href="/favicon.ico"> <title>Get together | Hubs by Mozilla</title> <link href="https://fonts.googleapis.com/css?family=Zilla+Slab:300,300i,400,400i,700" rel="stylesheet"> - - <!-- HACK: this has to run after A-Frame but before our bundle, since A-Frame blows away the local storage setting --> - <script src="https://cdn.rawgit.com/gfodor/ba8f88d9f34fe9cbe59a01ce3c48420d/raw/03e31f0ef7b9eac5e947bd39e440f34df0701f75/naf-janus-adapter-logging.js" integrity="sha384-4q1V8Q88oeCFriFefFo5uEUtMzbw6K116tFyC9cwbiPr6wEe7050l5HoJUxMvnzj" crossorigin="anonymous"></script> </head> <body> diff --git a/src/hub.js b/src/hub.js index 564462417..cc6ad39c6 100644 --- a/src/hub.js +++ b/src/hub.js @@ -3,6 +3,7 @@ console.log(`Hubs version: ${process.env.BUILD_VERSION || "?"}`); import "./assets/stylesheets/hub.scss"; import "aframe"; +import "./utils/logging"; import { patchWebGLRenderingContext } from "./utils/webgl"; patchWebGLRenderingContext(); diff --git a/src/utils/logging.js b/src/utils/logging.js new file mode 100644 index 000000000..1114f6572 --- /dev/null +++ b/src/utils/logging.js @@ -0,0 +1,18 @@ +// A-Frame blows away any npm debug log filters so this allow the user to set the log filter +// via the query string. +import debug from "debug"; + +const qs = new URLSearchParams(location.search); + +function qsTruthy(param) { + const val = qs.get(param); + // if the param exists but is not set (e.g. "?foo&bar"), its value is the empty string. + return val === "" || /1|on|true/i.test(val); +} + +const isDebug = qsTruthy("debug"); +const logFilter = qs.get("log_filter") || (isDebug && "naf-janus-adapter:*"); + +if (logFilter) { + debug.enable(logFilter); +} -- GitLab