1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-11-15 05:21:05 +00:00
nodelogging/src/index.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-03-26 01:50:26 +00:00
import { LoggingFiles } from "./filewriter";
2019-04-01 03:51:27 +00:00
import { LoggingBase, LoggingBaseOptions } from "@hibas123/logging";
2017-08-23 14:45:03 +00:00
2019-03-26 01:50:26 +00:00
export interface LoggingOptions extends LoggingBaseOptions {
files: boolean | {
/**
* Filename/path of the logfile. Skip if generated with name
*/
logfile: string;
/**
* Filename/path of the logfile. Skip if generated with name
*/
errorfile: string;
}
2018-08-09 17:52:01 +00:00
}
2017-08-23 14:45:03 +00:00
2019-03-26 01:50:26 +00:00
export class LoggingExtended extends LoggingBase {
constructor(config: Partial<LoggingOptions> | string = {}) {
super(config);
2019-03-26 01:50:26 +00:00
if (typeof config === "string" || config.files !== false) {
let logfile: string;
let errorfile: string;
if (typeof config !== "string" && typeof config.files === "object") {
logfile = config.files.logfile;
errorfile = config.files.errorfile;
} else {
2019-03-26 01:50:26 +00:00
let name = this.name ? "." + this.name : "";
logfile = `./logs/all${name}.log`;
errorfile = `./logs/error${name}.log`;
}
2019-03-26 01:50:26 +00:00
if (logfile) {
this.addAdapter(new LoggingFiles(logfile));
}
2019-03-26 01:50:26 +00:00
if (errorfile) {
this.addAdapter(new LoggingFiles(errorfile, true));
}
}
2017-08-23 14:45:03 +00:00
}
}
2019-03-26 01:50:26 +00:00
export let Logging: LoggingExtended = undefined;
if (process.env.LOGGING_NO_DEFAULT !== "true") {
2019-03-26 01:50:26 +00:00
Logging = new LoggingExtended();
}
export default Logging;
2018-02-18 15:00:16 +00:00