diff --git a/src/settings-form-application.mjs b/src/settings-form-application.mjs index d459a50..e37d198 100644 --- a/src/settings-form-application.mjs +++ b/src/settings-form-application.mjs @@ -96,14 +96,14 @@ export class OronderSettingsFormApplication extends FormApplication { return this.object.players.find(p => p.discord_id === invalid_discord_id).foundry_name }) if (invalid_player_names.length===1) { - Logger.logError( + Logger.error( `${invalid_player_names[0]} ${game.i18n.localize("oronder.Could-Not-Be-Found")}` ) } else { valid_config = true } }) - .catch(Logger.logError) + .catch(Logger.error) game.settings.set(MODULE_ID, VALID_CONFIG, valid_config) game.settings.set(MODULE_ID, GUILD_ID, this.object.guild_id) @@ -118,7 +118,7 @@ export class OronderSettingsFormApplication extends FormApplication { this.object.full_sync_sync_disabled = true this.render() - await full_sync().catch(Logger.logError) + await full_sync().catch(Logger.error) this.object.full_sync_button_icon = "fa-solid fa-users" this.object.full_sync_sync_disabled = false @@ -139,15 +139,15 @@ export class OronderSettingsFormApplication extends FormApplication { if (!Number.fromString(this.object.guild_id)) { err = true - Logger.logError(game.i18n.localize("oronder.Server-Id-NaN")) + Logger.error(game.i18n.localize("oronder.Server-Id-NaN")) } if (!this.object.auth) { err = true - Logger.logError(game.i18n.localize("oronder.Auth-Token-Empty")) + Logger.error(game.i18n.localize("oronder.Auth-Token-Empty")) } if (!players_without_discord_ids.length) { err = true - Logger.logWarning(game.i18n.localize("oronder.No-Players-To-Sync")) + Logger.warn(game.i18n.localize("oronder.No-Players-To-Sync")) } if (err) { @@ -172,7 +172,7 @@ export class OronderSettingsFormApplication extends FormApplication { this.object.players.find(p => p.foundry_name === foundry_name).discord_id = discord_user_id } }) - .catch(Logger.logError) + .catch(Logger.error) this.object.fetch_button_icon = "fa-solid fa-rotate" this.object.fetch_sync_disabled = false diff --git a/src/sync.mjs b/src/sync.mjs index 5cd5496..446ebc3 100644 --- a/src/sync.mjs +++ b/src/sync.mjs @@ -198,7 +198,7 @@ export async function sync_actor(actor) { return Promise.resolve() } if (!actor_to_discord_ids(actor).length) { - Logger.log( + Logger.info( `${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor.name}. ${game.i18n.localize("oronder.No-Owner")}` ); return Promise.resolve() @@ -209,23 +209,23 @@ export async function sync_actor(actor) { const new_hash = hash(actor_obj) if (old_hash && old_hash === new_hash) { - Logger.log(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Change")}`); + Logger.info(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Change")}`); return Promise.resolve() } if (!actor_obj.details.level) { - Logger.log(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Level")}`); + Logger.info(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Level")}`); return Promise.resolve() } if (!actor_obj.details.race) { - Logger.log(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Race")}`); + Logger.info(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Race")}`); return Promise.resolve() } if (!actor_obj.details.background) { - Logger.log(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Background")}`); + Logger.info(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Background")}`); return Promise.resolve() } if (!Object.keys(actor_obj.classes).length) { - Logger.log(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Class")}`); + Logger.info(`${game.i18n.localize("oronder.Skipping-Sync-For")} ${actor_obj.name}. ${game.i18n.localize("oronder.No-Class")}`); return Promise.resolve() } @@ -234,9 +234,9 @@ export async function sync_actor(actor) { localStorage.setItem(`${ACTORS}.${actor.id}`, new_hash) Logger.log(`${game.i18n.localize("oronder.Synced")} ${actor_obj.name}`); } else { - Logger.logError(`${actor_obj.name} ${game.i18n.localize("oronder.Failed-To-Sync")}`); + Logger.error(`${actor_obj.name} ${game.i18n.localize("oronder.Failed-To-Sync")}`); } - }).catch(Logger.logError) + }).catch(Logger.error) Logger.log(`${actor.name}: ${Math.floor((Date.now() - a) / 1000)} seconds`) return p diff --git a/src/util.mjs b/src/util.mjs index 0eab50b..b3428b7 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -6,19 +6,27 @@ import objectHash from 'object-hash'; */ export class Logger { - static log(logString) { - console.log(..._processLog(logString)); + static debug(logString) { + console.debug(..._processLog(logString)); } - static logError(logString, options = {}) { - if (options.ui ?? true) ui.notifications.error(logString, {console: false}); - if (options.console ?? true) console.error(..._processLog(logString)); + static info(logString) { + console.info(..._processLog(logString)); + } + + static log(logString) { + console.log(..._processLog(logString)); } - static logWarning(logString, options = {}) { + static warn(logString, options = {}) { if (options.ui ?? true) ui.notifications.warn(logString, {console: false}); if (options.console ?? true) console.warn(..._processLog(logString)); } + + static error(logString, options = {}) { + if (options.ui ?? true) ui.notifications.error(logString, {console: false}); + if (options.console ?? true) console.error(..._processLog(logString)); + } } /**