Adding automatic logfile creation depending on name

This commit is contained in:
Fabian Stamm 2018-09-01 16:57:21 +02:00
parent 4918fe9b17
commit e973ab7e59
5 changed files with 35 additions and 6 deletions

View File

@ -41,6 +41,14 @@ class LoggingBase {
this.events = new events_1.EventEmitter(); this.events = new events_1.EventEmitter();
if (!options) if (!options)
options = {}; options = {};
if (options.name) {
if (options.logfile === undefined) {
options.logfile = `./logs/all.${options.name}.log`;
}
if (options.errorfile === undefined) {
options.logfile = `./logs/error.${options.name}.log`;
}
}
this.config = Object.assign({ this.config = Object.assign({
name: undefined, name: undefined,
console_out: true, console_out: true,

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/nodelogging", "name": "@hibas123/nodelogging",
"version": "1.3.4", "version": "1.3.5",
"description": "", "description": "",
"main": "out/index.js", "main": "out/index.js",
"types": "out/index.d.ts", "types": "out/index.d.ts",

View File

@ -25,13 +25,25 @@ All Logging types except the simple error take as many arguments as you want. Th
# Setup # Setup
NodeLogging can work without any configuration, but it may be useful to change the log output folder or disable the terminal output. NodeLogging can work without any configuration, but it may be useful to change the log output folder.
Todo so you are capable of creating own instances of the LoggingBase class
``` javascript ``` javascript
const CustomLogging = new LoggingBase({
Logging.config(folder, stdout); //stdout can be true or false name: "custom",
logfile: "./logs/test.log",
errorfile: "/var/log/custom.err",
console_out: false
});
``` ```
The name property prefixes the console output with the name. Also if no logfile or errorfile is created the following standard values are used:
./logs/all.<name>.log
./logs/error.<name>.log
To not use any logfiles just set the values to null.
# License # License
MIT MIT

View File

@ -59,6 +59,15 @@ export class LoggingBase {
constructor(options?: Partial<LoggingBaseOptions>) { constructor(options?: Partial<LoggingBaseOptions>) {
if (!options) options = {}; if (!options) options = {};
if (options.name) {
if (options.logfile === undefined) {
options.logfile = `./logs/all.${options.name}.log`
}
if (options.errorfile === undefined) {
options.logfile = `./logs/error.${options.name}.log`
}
}
this.config = Object.assign(<LoggingBaseOptions>{ this.config = Object.assign(<LoggingBaseOptions>{
name: undefined, name: undefined,
console_out: true, console_out: true,