forked from databricks/databricks-sql-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBSQLLogger.ts
More file actions
35 lines (30 loc) · 1.03 KB
/
DBSQLLogger.ts
File metadata and controls
35 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import winston, { Logger } from 'winston';
import IDBSQLLogger, { LoggerOptions, LogLevel } from './contracts/IDBSQLLogger';
export default class DBSQLLogger implements IDBSQLLogger {
logger: Logger;
transports: {
console: winston.transports.ConsoleTransportInstance;
file?: winston.transports.FileTransportInstance;
};
constructor({ level = LogLevel.info, filepath }: LoggerOptions = {}) {
this.transports = {
console: new winston.transports.Console({ handleExceptions: true, level }),
};
this.logger = winston.createLogger({
transports: [this.transports.console],
});
if (filepath) {
this.transports.file = new winston.transports.File({ filename: filepath, handleExceptions: true, level });
this.logger.add(this.transports.file);
}
}
async log(level: LogLevel, message: string) {
this.logger.log({ level, message });
}
setLevel(level: LogLevel) {
this.transports.console.level = level;
if (this.transports.file) {
this.transports.file.level = level;
}
}
}