mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-25 00:19:24 +00:00
Adding automatic logfile creation depending on name
This commit is contained in:
parent
4918fe9b17
commit
e973ab7e59
@ -41,6 +41,14 @@ class LoggingBase {
|
||||
this.events = new events_1.EventEmitter();
|
||||
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({
|
||||
name: undefined,
|
||||
console_out: true,
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hibas123/nodelogging",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"description": "",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
|
20
readme.md
20
readme.md
@ -25,13 +25,25 @@ All Logging types except the simple error take as many arguments as you want. Th
|
||||
|
||||
# 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
|
||||
|
||||
Logging.config(folder, stdout); //stdout can be true or false
|
||||
|
||||
const CustomLogging = new LoggingBase({
|
||||
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
|
||||
MIT
|
||||
|
||||
|
@ -59,6 +59,15 @@ export class LoggingBase {
|
||||
|
||||
constructor(options?: Partial<LoggingBaseOptions>) {
|
||||
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>{
|
||||
name: undefined,
|
||||
console_out: true,
|
||||
|
Loading…
Reference in New Issue
Block a user