From 93efc56de0de9053f7e1772a8ff416887bcfca0d Mon Sep 17 00:00:00 2001 From: "Brint E. Kriebel" Date: Sun, 30 May 2021 20:49:20 -0700 Subject: [PATCH] logging: Update registration of debug log setting Move thie registration of this setting in with the other setting registrations so the location of it can be controlled. Also add range option for settings helper in case it is needed. --- src/utils/helpers.js | 1 + src/utils/logging.js | 18 ++---------------- src/utils/registerModuleSettings.js | 13 +++++++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 1bf2f55..2d77634 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -45,6 +45,7 @@ export function registerModuleSetting(settingsObject) { config: settingsObject.config, default: settingsObject.default, type: settingsObject.type, + range: settingsObject.range, onChange: settingsObject.onChange, }); } diff --git a/src/utils/logging.js b/src/utils/logging.js index 62906f6..4c516fc 100644 --- a/src/utils/logging.js +++ b/src/utils/logging.js @@ -1,4 +1,4 @@ -import { LANG_NAME, LOG_PREFIX, MODULE_NAME } from "./constants.js"; +import { LOG_PREFIX, MODULE_NAME } from "./constants.js"; /* -------------------------------------------- */ /* Logging Methods */ @@ -38,7 +38,7 @@ export const warn = console.warn.bind(console, LOG_PREFIX); export const error = console.error.bind(console, LOG_PREFIX); // Enable debug & info logs if debugging is enabled -function setDebug(value) { +export function setDebug(value) { if (value) { debug = console.debug.bind(console, LOG_PREFIX); info = console.info.bind(console, LOG_PREFIX); @@ -49,17 +49,3 @@ function setDebug(value) { Hooks.callAll(`${MODULE_NAME}DebugSet`, value); } - -Hooks.once("init", () => { - game.settings.register(MODULE_NAME, "debug", { - name: `${LANG_NAME}.debug`, - hint: `${LANG_NAME}.debugHint`, - scope: "world", - config: true, - default: false, - type: Boolean, - onChange: (value) => setDebug(value), - }); - - setDebug(game.settings.get(MODULE_NAME, "debug")); -}); diff --git a/src/utils/registerModuleSettings.js b/src/utils/registerModuleSettings.js index b256203..bdd652d 100644 --- a/src/utils/registerModuleSettings.js +++ b/src/utils/registerModuleSettings.js @@ -102,4 +102,17 @@ export default function registerModuleSettings() { type: String, onChange: () => helpers.delayReload(), }); + + // Register debug logging setting + helpers.registerModuleSetting({ + name: "debug", + scope: "world", + config: true, + default: false, + type: Boolean, + onChange: (value) => log.setDebug(value), + }); + + // Set the initial debug level + log.setDebug(game.settings.get(MODULE_NAME, "debug")); }