2018-01-28 03:31:06 +00:00
|
|
|
import * as plugins from "./smartlog.plugins";
|
|
|
|
|
|
|
|
export type TLogLevel =
|
|
|
|
| "error"
|
|
|
|
| "warn"
|
|
|
|
| "info"
|
|
|
|
| "verbose"
|
|
|
|
| "debug"
|
|
|
|
| "silly";
|
|
|
|
|
|
|
|
export class Smartlog {
|
|
|
|
private winstonInstance = new plugins.winston.createLogger({
|
2018-01-28 03:31:44 +00:00
|
|
|
level: "silly",
|
2018-01-28 03:31:06 +00:00
|
|
|
format: plugins.winston.format.json()
|
2018-01-28 03:31:44 +00:00
|
|
|
});
|
2018-01-28 03:31:06 +00:00
|
|
|
|
|
|
|
// ============
|
|
|
|
// Logger Setup
|
|
|
|
// ============
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enables console logging
|
|
|
|
*/
|
|
|
|
enableConsole() {
|
|
|
|
this.winstonInstance.add(new plugins.winston.transports.Console());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set a minimum serverity level to log
|
2018-01-28 03:31:44 +00:00
|
|
|
* @param levelArg
|
2018-01-28 03:31:06 +00:00
|
|
|
*/
|
2018-01-28 03:31:44 +00:00
|
|
|
level(levelArg: TLogLevel) {
|
2018-01-28 03:31:06 +00:00
|
|
|
this.winstonInstance.level(levelArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// =============
|
|
|
|
// log functions
|
|
|
|
// =============
|
|
|
|
/**
|
|
|
|
* log stuff
|
|
|
|
* @param logLevelArg
|
2018-01-28 03:31:44 +00:00
|
|
|
* @param logMessageArg
|
2018-01-28 03:31:06 +00:00
|
|
|
*/
|
|
|
|
log(logLevelArg: TLogLevel, logMessageArg: string) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.winstonInstance.log(logLevelArg, logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
silly(logMessageArg: string) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.log("silly", logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug(logMessageArg) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.log("debug", logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info(logMessageArg: string) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.log("info", logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
warn(logMessageArg) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.log("warn", logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error(logMessageArg) {
|
2018-01-28 03:31:44 +00:00
|
|
|
this.log("error", logMessageArg);
|
2018-01-28 03:31:06 +00:00
|
|
|
}
|
|
|
|
}
|