From 096c5910c3a9b9735c432df691f7212edd5d9a6a Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 3 Apr 2019 20:53:28 -0400 Subject: [PATCH] making files in config nullabel to disable --- package.json | 2 +- src/index.ts | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f15ae14..a165668 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/nodelogging", - "version": "1.6.0", + "version": "1.6.1", "description": "", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 2825e91..25acb3e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,13 +5,17 @@ import { LoggingBase as LoggingBaseOriginal, LoggingBaseOptions } from "@hibas12 export interface LoggingOptions extends LoggingBaseOptions { files: boolean | { /** - * Filename/path of the logfile. Skip if generated with name + * Filename/path of the logfile. Skip if generated with name. + * + * If not wanted pass null */ - logfile: string; + logfile?: string | null; /** - * Filename/path of the logfile. Skip if generated with name + * Filename/path of the logfile. Skip if generated with name. + * + * If not wanted pass null */ - errorfile: string; + errorfile?: string | null; } } @@ -25,19 +29,20 @@ export class LoggingBase extends LoggingBaseOriginal { if (typeof config !== "string" && typeof config.files === "object") { logfile = config.files.logfile; errorfile = config.files.errorfile; - } else { - let name = this.name ? "." + this.name : ""; + } + + let name = this.name ? "." + this.name : ""; + if (!logfile && logfile !== null) logfile = `./logs/all${name}.log`; + if (!errorfile && errorfile !== null) errorfile = `./logs/error${name}.log`; - } - if (logfile) { + if (logfile) this.addAdapter(new LoggingFiles(logfile)); - } - if (errorfile) { + + if (errorfile) this.addAdapter(new LoggingFiles(errorfile, true)); - } } } }