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

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-04-03 13:51:23 +00:00
export { LoggingFiles } from "./filewriter";
2019-03-26 01:50:26 +00:00
import { LoggingFiles } from "./filewriter";
2019-04-02 23:59:29 +00:00
import { LoggingBase as LoggingBaseOriginal, 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.
*
* If not wanted pass null
*/
logfile?: string | null;
/**
* Filename/path of the logfile. Skip if generated with name.
*
* If not wanted pass null
*/
errorfile?: string | null;
}
2018-08-09 17:52:01 +00:00
}
2017-08-23 14:45:03 +00:00
2019-04-02 23:59:29 +00:00
export class LoggingBase extends LoggingBaseOriginal {
2019-03-26 01:50:26 +00:00
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;
}
let name = this.name ? "." + this.name : "";
if (!logfile && logfile !== null)
2019-03-26 01:50:26 +00:00
logfile = `./logs/all${name}.log`;
if (!errorfile && errorfile !== null)
2019-03-26 01:50:26 +00:00
errorfile = `./logs/error${name}.log`;
if (logfile)
2019-03-26 01:50:26 +00:00
this.addAdapter(new LoggingFiles(logfile));
if (errorfile)
2019-03-26 01:50:26 +00:00
this.addAdapter(new LoggingFiles(errorfile, true));
}
2017-08-23 14:45:03 +00:00
}
}
2019-04-02 23:59:29 +00:00
export let Logging: LoggingBase = undefined;
if (process.env.LOGGING_NO_DEFAULT !== "true") {
2019-04-02 23:59:29 +00:00
Logging = new LoggingBase();
}
export default Logging;
2018-02-18 15:00:16 +00:00