Skip to content

Commit

Permalink
feat: Add global class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Nov 3, 2021
1 parent 7f42b03 commit ef88389
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/logger",
"version": "1.1.7",
"version": "1.1.8",
"description": "",
"scripts": {
"build": "tsc",
Expand Down
6 changes: 5 additions & 1 deletion src/Logger/defaultMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { LogMapper } from './LogMapper'
import { ContextFormatter } from '../Formatters/ContextFormatter'
import { ConsoleTransporter } from '../Transporters/ConsoleTransporter'

export const defaultMapper = new LogMapper(
export let defaultMapper = new LogMapper(
[new ContextFormatter()],
[new ConsoleTransporter()],
)

export function changeDefaultMapper(m: LogMapper) {
defaultMapper = m
}
20 changes: 20 additions & 0 deletions src/utils/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Log } from '../Logger/Log'
import { Logger } from '../Logger/Logger'
import { LogMapper } from '../Logger/LogMapper'
import { DebugFormatter } from '../Formatters/DebugFormatter'
import { DebugTransporter } from '../Transporters/DebugTransporter'

export {}

declare global {
function Log(message: any, formatterOpts?: any, transporterOpts?: any): void
function Debug(message: any, formatterOpts?: any, transporterOpts?: any): void
}

const _global = global as any

_global.Log = Log
_global.Debug = new Logger().debug.bind({
context: 'Debugger',
mapper: new LogMapper([new DebugFormatter()], [new DebugTransporter()]),
})

0 comments on commit ef88389

Please sign in to comment.