Skip to content

Commit

Permalink
refactor: remove @secjs/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Dec 4, 2021
1 parent 05c39c4 commit 0a799e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/config",
"version": "1.0.8",
"version": "1.0.9",
"description": "",
"license": "MIT",
"author": "João Lenon",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from './utils/logger'
import { debugFn } from './utils/debug'

import { parse } from 'path'
import { Env } from '@secjs/env'
Expand All @@ -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',
)
}
Expand Down Expand Up @@ -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)
}
}
31 changes: 31 additions & 0 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -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))
}
14 changes: 0 additions & 14 deletions src/utils/logger.ts

This file was deleted.

0 comments on commit 0a799e7

Please sign in to comment.