diff --git a/package.json b/package.json index d4e9ab1..f8fb382 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@secjs/logger", - "version": "1.1.5", + "version": "1.1.6", "description": "", "scripts": { "build": "tsc", diff --git a/src/Logger/Log.ts b/src/Logger/Log.ts index e01d005..3c5dc1e 100644 --- a/src/Logger/Log.ts +++ b/src/Logger/Log.ts @@ -1,17 +1,15 @@ import { LogMapper } from './LogMapper' -import { ContextFormatter } from '../Formatters/ContextFormatter' -import { ConsoleTransporter } from '../Transporters/ConsoleTransporter' +import { defaultMapper } from './defaultMapper' -let mapper = new LogMapper( - [new ContextFormatter('Log')], - [new ConsoleTransporter('stdout')], -) +let mapper = defaultMapper export function Log( message: any, - formatterOpts?: any, - transporterOpts?: any, + formatterOpts: any = {}, + transporterOpts: any = {}, ): void { + formatterOpts.context = 'Log' + mapper.resolve(message, formatterOpts, transporterOpts) } diff --git a/src/Logger/Logger.ts b/src/Logger/Logger.ts index ae692ed..235e291 100644 --- a/src/Logger/Logger.ts +++ b/src/Logger/Logger.ts @@ -1,8 +1,6 @@ import { Color } from '../utils/Color' import { LogMapper } from './LogMapper' -import { ContextFormatter } from '../Formatters/ContextFormatter' -import { FileTransporter } from '../Transporters/FileTransporter' -import { ConsoleTransporter } from '../Transporters/ConsoleTransporter' +import { defaultMapper } from './defaultMapper' export class Logger { private readonly context: string @@ -10,12 +8,7 @@ export class Logger { constructor(context = Logger.name, mapper?: LogMapper) { this.context = context - this.mapper = - mapper || - new LogMapper( - [new ContextFormatter(context)], - [new ConsoleTransporter(), new FileTransporter()], - ) + this.mapper = mapper || defaultMapper } info(message: any, formatterOpts: any = {}, transporterOpts: any = {}) { @@ -24,7 +17,6 @@ export class Logger { formatterOpts.context = formatterOpts.context || this.context transporterOpts.streamType = 'stdout' - this.mapper.removeTransporter(FileTransporter) this.mapper.resolve(message, formatterOpts, transporterOpts) } diff --git a/src/Logger/defaultMapper.ts b/src/Logger/defaultMapper.ts new file mode 100644 index 0000000..e564851 --- /dev/null +++ b/src/Logger/defaultMapper.ts @@ -0,0 +1,8 @@ +import { LogMapper } from './LogMapper' +import { ContextFormatter } from '../Formatters/ContextFormatter' +import { ConsoleTransporter } from '../Transporters/ConsoleTransporter' + +export const defaultMapper = new LogMapper( + [new ContextFormatter()], + [new ConsoleTransporter()], +)