Skip to content

Commit

Permalink
cleanup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkLightTuna committed Dec 19, 2023
1 parent 88a8bd9 commit 32f973f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/settings-form-application.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}

Expand All @@ -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
Expand Down
20 changes: 14 additions & 6 deletions src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

/**
Expand Down

0 comments on commit 32f973f

Please sign in to comment.