Skip to content

Commit

Permalink
logging: Update registration of debug log setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bekriebel committed May 31, 2021
1 parent ceab780 commit 93efc56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function registerModuleSetting(settingsObject) {
config: settingsObject.config,
default: settingsObject.default,
type: settingsObject.type,
range: settingsObject.range,
onChange: settingsObject.onChange,
});
}
18 changes: 2 additions & 16 deletions src/utils/logging.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LANG_NAME, LOG_PREFIX, MODULE_NAME } from "./constants.js";
import { LOG_PREFIX, MODULE_NAME } from "./constants.js";

/* -------------------------------------------- */
/* Logging Methods */
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
});
13 changes: 13 additions & 0 deletions src/utils/registerModuleSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

0 comments on commit 93efc56

Please sign in to comment.