From ea8ecfb28f0a247b7d3ccb5607442520cbfff15f Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Wed, 10 Jul 2024 19:36:13 -0400 Subject: [PATCH] chore: use new logger --- app/routes/login.tsx | 3 +-- app/utils/config/headplane.ts | 25 ++++++++++++++++--------- app/utils/config/headscale.ts | 30 ++++++++++++++++-------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/routes/login.tsx b/app/routes/login.tsx index 64f34ec..9199d32 100644 --- a/app/routes/login.tsx +++ b/app/routes/login.tsx @@ -80,8 +80,7 @@ export async function action({ request }: ActionFunctionArgs) { }), }, }) - } catch (error) { - console.error(error) + } catch { return json({ error: 'Invalid API key', }) diff --git a/app/utils/config/headplane.ts b/app/utils/config/headplane.ts index 4e5ad41..0972967 100644 --- a/app/utils/config/headplane.ts +++ b/app/utils/config/headplane.ts @@ -9,8 +9,8 @@ import { resolve } from 'node:path' import { parse } from 'yaml' import { IntegrationFactory, loadIntegration } from '~/integration' - -import { HeadscaleConfig, loadConfig } from './headscale' +import { HeadscaleConfig, loadConfig } from '~/utils/config/headscale' +import log from '~/utils/log' export interface HeadplaneContext { headscaleUrl: string @@ -67,19 +67,26 @@ export async function loadContext(): Promise { context = { headscaleUrl, cookieSecret, - integration: loadIntegration(), + integration: await loadIntegration(), config: contextData, acl: await checkAcl(config), oidc: await checkOidc(config), } - console.log('Completed loading the Headplane Context') - console.log('Headscale URL:', headscaleUrl) - console.log('Integration:', context.integration?.name ?? 'None') - console.log('Config:', contextData.read ? `Found ${contextData.write ? '' : '(Read Only)'}` : 'Unavailable') - console.log('ACL:', context.acl.read ? `Found ${context.acl.write ? '' : '(Read Only)'}` : 'Unavailable') - console.log('OIDC:', context.oidc ? 'Configured' : 'Unavailable') + log.info('CTXT', 'Starting Headplane with Context') + log.info('CTXT', 'HEADSCALE_URL: %s', headscaleUrl) + log.info('CTXT', 'Integration: %s', context.integration?.name ?? 'None') + log.info('CTXT', 'Config: %s', contextData.read + ? `Found ${contextData.write ? '' : '(Read Only)'}` + : 'Unavailable', + ) + log.info('CTXT', 'ACL: %s', context.acl.read + ? `Found ${context.acl.write ? '' : '(Read Only)'}` + : 'Unavailable', + ) + + log.info('CTXT', 'OIDC: %s', context.oidc ? 'Configured' : 'Unavailable') return context } diff --git a/app/utils/config/headscale.ts b/app/utils/config/headscale.ts index dc6e044..34842ff 100644 --- a/app/utils/config/headscale.ts +++ b/app/utils/config/headscale.ts @@ -12,6 +12,8 @@ import { resolve } from 'node:path' import { type Document, parseDocument } from 'yaml' import { z } from 'zod' +import log from '~/utils/log' + const goBool = z .union([z.boolean(), z.literal('true'), z.literal('false')]) .transform((value) => { @@ -229,13 +231,13 @@ export async function loadConfig(path?: string) { }, } as HeadscaleConfig - console.log('Loaded Headscale configuration in non-strict mode') - console.log('By using this mode you forfeit GitHub issue support') - console.log('This is very dangerous and comes with a few caveats:') - console.log('- Headplane could very easily crash') - console.log('- Headplane could break your Headscale installation') - console.log('- The UI could throw random errors/show incorrect data') - console.log('') + log.warn('CFGX', 'Loaded Headscale configuration in non-strict mode') + log.warn('CFGX', 'By using this mode you forfeit GitHub issue support') + log.warn('CFGX', 'This is very dangerous and comes with a few caveats:') + log.warn('CFGX', 'Headplane could very easily crash') + log.warn('CFGX', 'Headplane could break your Headscale installation') + log.warn('CFGX', 'The UI could throw random errors/show incorrect data') + log.warn('CFGX', '') return config } @@ -243,19 +245,19 @@ export async function loadConfig(path?: string) { config = await HeadscaleConfig.parseAsync(configYaml.toJSON()) } catch (error) { if (error instanceof z.ZodError) { - console.log('Failed to parse the Headscale configuration file!') - console.log('The following schema issues were found:') + log.error('CFGX', 'Recieved invalid configuration file') + log.error('CFGX', 'The following schema issues were found:') for (const issue of error.issues) { const path = issue.path.map(String).join('.') const message = issue.message - console.log(`- '${path}': ${message}`) + log.error('CFGX', ` '${path}': ${message}`) } - console.log('') - console.log('Please fix the configuration file and try again.') - console.log('Headplane will operate as if no config is present.') - console.log('') + log.error('CFGX', '') + log.error('CFGX', 'Resolve these issues and try again.') + log.error('CFGX', 'Headplane will operate without the config') + log.error('CFGX', '') } throw error