1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-11-15 07:11:04 +00:00
nodelogging/src/index.ts
2019-03-25 21:50:26 -04:00

55 lines
1.5 KiB
TypeScript

import { LoggingBase, LoggingBaseOptions } from "./base";
import { LoggingFiles } from "./filewriter";
export { Colors } from "./base";
export { Adapter, LoggingTypes, Message } from "./types";
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;
}
}
export class LoggingExtended extends LoggingBase {
constructor(config: Partial<LoggingOptions> | string = {}) {
super(config);
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 {
let name = this.name ? "." + this.name : "";
logfile = `./logs/all${name}.log`;
errorfile = `./logs/error${name}.log`;
}
if (logfile) {
this.addAdapter(new LoggingFiles(logfile));
}
if (errorfile) {
this.addAdapter(new LoggingFiles(errorfile, true));
}
}
}
}
export let Logging: LoggingExtended = undefined;
if (process.env.LOGGING_NO_DEFAULT !== "true") {
Logging = new LoggingExtended();
}
export default Logging;