From a5fbcb7958dcdf673e62861f520694c1b3ef9495 Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Fri, 18 Jul 2025 18:03:18 -0700 Subject: [PATCH] refactor(mothership): improve logging consistency and clarity in instance handlers --- .../lib/handlers/instance/api/HandleInstanceCreate.ts | 10 +++++----- .../instance/bootstrap/HandleMigrateRegions.ts | 7 +++++-- .../instance/model/HandleInstanceBeforeUpdate.ts | 2 +- .../lib/handlers/meta/boot/HandleMetaUpdateAtBoot.ts | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/api/HandleInstanceCreate.ts b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/api/HandleInstanceCreate.ts index 5a980368..c2a0a6ec 100644 --- a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/api/HandleInstanceCreate.ts +++ b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/api/HandleInstanceCreate.ts @@ -6,31 +6,31 @@ export const HandleInstanceCreate = (c: echo.Context) => { const log = mkLog(`POST:instance`) const authRecord = c.get('authRecord') as models.Record | undefined // empty if not authenticated as regular auth record - log(`***authRecord`, JSON.stringify(authRecord)) + log(`authRecord`, JSON.stringify(authRecord)) if (!authRecord) { throw new Error(`Expected authRecord here`) } - log(`***TOP OF POST`) + log(`TOP OF POST`) let data = new DynamicModel({ subdomain: '', version: versions[0], region: 'sfo-2', }) as { subdomain?: string; version?: string; region?: string } - log(`***before bind`) + log(`before bind`) c.bind(data) - log(`***after bind`) + log(`after bind`) // This is necessary for destructuring to work correctly data = JSON.parse(JSON.stringify(data)) const { subdomain, version, region } = data - log(`***vars`, JSON.stringify({ subdomain, region })) + log(`vars`, JSON.stringify({ subdomain, region })) if (!subdomain) { throw new BadRequestError(`Subdomain is required when creating an instance.`) diff --git a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/bootstrap/HandleMigrateRegions.ts b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/bootstrap/HandleMigrateRegions.ts index 0e9f6039..705601a6 100644 --- a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/bootstrap/HandleMigrateRegions.ts +++ b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/bootstrap/HandleMigrateRegions.ts @@ -1,7 +1,10 @@ +import { mkLog } from '$util/Logger' + /** Migrate version numbers */ export const HandleMigrateRegions = (e: core.BootstrapEvent) => { const dao = $app.dao() - - console.log(`***Migrating regions`) + const log = mkLog(`HandleMigrateRegions`) + log(`Migrating regions`) dao.db().newQuery(`update instances set region='sfo-1' where region=''`).execute() + log(`Migrated regions`) } diff --git a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/model/HandleInstanceBeforeUpdate.ts b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/model/HandleInstanceBeforeUpdate.ts index 48e1026c..6d2c4c2d 100644 --- a/packages/pockethost/src/mothership-app/src/lib/handlers/instance/model/HandleInstanceBeforeUpdate.ts +++ b/packages/pockethost/src/mothership-app/src/lib/handlers/instance/model/HandleInstanceBeforeUpdate.ts @@ -25,7 +25,7 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => { try { dao.db().newQuery(`select id from instances where cname='${cname}' and id <> '${id}'`).one(result) } catch (e) { - // log(`*** cname OK ${cname}`) + // log(` cname OK ${cname}`) return false } return true diff --git a/packages/pockethost/src/mothership-app/src/lib/handlers/meta/boot/HandleMetaUpdateAtBoot.ts b/packages/pockethost/src/mothership-app/src/lib/handlers/meta/boot/HandleMetaUpdateAtBoot.ts index 2b4a53d7..80c416d5 100644 --- a/packages/pockethost/src/mothership-app/src/lib/handlers/meta/boot/HandleMetaUpdateAtBoot.ts +++ b/packages/pockethost/src/mothership-app/src/lib/handlers/meta/boot/HandleMetaUpdateAtBoot.ts @@ -3,7 +3,7 @@ import { mkLog } from '$util/Logger' export const HandleMetaUpdateAtBoot = (c: core.BootstrapEvent) => { const log = mkLog('HandleMetaUpdateAtBoot') log(`At top of HandleMetaUpdateAtBoot`) - log(`***app URL`, process.env.APP_URL) + log(`app URL`, process.env.APP_URL) const form = new SettingsUpsertForm($app) form.meta = { ...$app.settings().meta,