From 598241c7a3a9bf38681bc976228e1b90e6c5f2d2 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:51:36 -0600 Subject: [PATCH] feat: logging for experimental json loading --- src/core/module-loading.ts | 11 ++++++----- src/sern.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index 81146880..a5e89690 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -7,6 +7,7 @@ import { createRequire } from 'node:module'; import type { ImportPayload, Wrapper } from '../types/core'; import type { Module } from '../types/core-modules'; import { existsSync } from 'fs'; +import type { Logging } from './contracts/logging'; export const shouldHandle = (path: string, fpath: string) => { const file_name = fpath+extname(path); @@ -107,11 +108,11 @@ async function* readPaths(dir: string): AsyncGenerator { export const requir = createRequire(import.meta.url); -export function loadConfig(wrapper: Wrapper | 'file'): Wrapper { +export function loadConfig(wrapper: Wrapper | 'file', log: Logging | undefined): Wrapper { if (wrapper !== 'file') { return wrapper; } - console.log('Experimental loading of sern.config.json'); + log?.info({ message: 'Experimental loading of sern.config.json'}); const config = requir(resolve('sern.config.json')); const makePath = (dir: PropertyKey) => @@ -119,14 +120,14 @@ export function loadConfig(wrapper: Wrapper | 'file'): Wrapper { ? join('dist', config.paths[dir]!) : join(config.paths[dir]!); - console.log('Loading config: ', config); + log?.info({ message: 'Loading config: ' + JSON.stringify(config, null, 4) }); const commandsPath = makePath('commands'); - console.log('Commands path is set to', commandsPath); + log?.info({ message: `Commands path is set to ${commandsPath}` }); let eventsPath: string | undefined; if (config.paths.events) { eventsPath = makePath('events'); - console.log('Events path is set to', eventsPath); + log?.info({ message: `Events path is set to ${eventsPath} `}); } return { defaultPrefix: config.defaultPrefix, diff --git a/src/sern.ts b/src/sern.ts index d294e7f3..e633be01 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -25,7 +25,6 @@ import { Client } from 'discord.js'; */ export function init(maybeWrapper: Wrapper | 'file') { const startTime = performance.now(); - const wrapper = Files.loadConfig(maybeWrapper); const dependencies = Services('@sern/emitter', '@sern/errors', '@sern/logger', @@ -34,6 +33,7 @@ export function init(maybeWrapper: Wrapper | 'file') { const logger = dependencies[2], errorHandler = dependencies[1]; + const wrapper = Files.loadConfig(maybeWrapper, logger); if (wrapper.events !== undefined) { eventsHandler(dependencies, Files.getFullPathTree(wrapper.events)); }