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";
|
2019-03-23 15:50:12 +00:00
|
|
|
|
2017-08-23 14:45:03 +00:00
|
|
|
|
2019-03-26 01:50:26 +00:00
|
|
|
export interface LoggingOptions extends LoggingBaseOptions {
|
2019-03-23 15:50:12 +00:00
|
|
|
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);
|
2018-10-05 11:16:49 +00:00
|
|
|
|
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;
|
2019-03-23 15:50:12 +00:00
|
|
|
} 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`;
|
2018-09-01 14:57:21 +00:00
|
|
|
}
|
2018-10-05 11:16:49 +00:00
|
|
|
|
2019-03-26 01:50:26 +00:00
|
|
|
if (logfile) {
|
|
|
|
this.addAdapter(new LoggingFiles(logfile));
|
2019-03-23 15:50:12 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 01:50:26 +00:00
|
|
|
if (errorfile) {
|
|
|
|
this.addAdapter(new LoggingFiles(errorfile, true));
|
2019-03-23 15:50:12 +00:00
|
|
|
}
|
2018-10-05 11:16:49 +00:00
|
|
|
}
|
2017-08-23 14:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-20 17:38:55 +00:00
|
|
|
|
2019-03-26 01:50:26 +00:00
|
|
|
export let Logging: LoggingExtended = undefined;
|
2018-09-20 17:38:55 +00:00
|
|
|
if (process.env.LOGGING_NO_DEFAULT !== "true") {
|
2019-03-26 01:50:26 +00:00
|
|
|
Logging = new LoggingExtended();
|
2018-09-20 17:38:55 +00:00
|
|
|
}
|
2018-05-12 16:46:47 +00:00
|
|
|
export default Logging;
|
|
|
|
|
2018-02-18 15:00:16 +00:00
|
|
|
|
|
|
|
|