diff --git a/package.json b/package.json index 93f74f9..639c2c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@secjs/config", - "version": "1.0.8", + "version": "1.0.9", "description": "", "license": "MIT", "author": "João Lenon", @@ -22,7 +22,6 @@ "@secjs/contracts": "1.1.7", "@secjs/env": "1.2.5", "@secjs/exceptions": "1.0.4", - "@secjs/logger": "1.2.2", "@secjs/utils": "1.4.3", "@types/debug": "4.1.5", "@types/jest": "27.0.1", diff --git a/src/Config.ts b/src/Config.ts index 59bdcd6..0115189 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1,4 +1,4 @@ -import logger from './utils/logger' +import { debugFn } from './utils/debug' import { parse } from 'path' import { Env } from '@secjs/env' @@ -12,7 +12,7 @@ export class Config { const isInitialized = Config.configs.size >= 1 if (isInitialized) { - logger.debug( + debugFn( 'Reloading the Config class has no effect on the configuration files, only for environment variables, as the files have already been loaded as Singletons', ) } @@ -112,7 +112,7 @@ export class Config { } } - logger.debug(`Loading ${name} configuration file`) + debugFn(`Loading ${name} configuration file`) this.configs.set(name, require(`${dir}/${name}`).default) } } diff --git a/src/utils/debug.ts b/src/utils/debug.ts new file mode 100644 index 0000000..64bf089 --- /dev/null +++ b/src/utils/debug.ts @@ -0,0 +1,31 @@ +import debug from 'debug' + +import Chalk from 'chalk' + +function format(message: any) { + const pid = Chalk.hex('#7059C1')(`[SecJS Debugger] - PID: ${process.pid}`) + const timestamp = getTimestamp() + const messageCtx = Chalk.hex('#ffe600')(`[Config] `) + + return `${pid} - ${timestamp} ${messageCtx}${Chalk.hex('#7059C1')(message)}` +} + +function getTimestamp(): string { + const localeStringOptions = { + year: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + day: '2-digit', + month: '2-digit', + } + + return new Date(Date.now()).toLocaleString( + undefined, + localeStringOptions as Intl.DateTimeFormatOptions, + ) +} + +export function debugFn(message: string) { + debug('api:configurations')(format(message)) +} diff --git a/src/utils/logger.ts b/src/utils/logger.ts deleted file mode 100644 index 25ee71e..0000000 --- a/src/utils/logger.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { - DebugFormatter, - DebugTransporter, - Logger, - LogMapper, -} from '@secjs/logger' - -export default new Logger( - 'Debug', - new LogMapper( - [new DebugFormatter()], - [new DebugTransporter('api:configurations')], - ), -)