Includes just the basic get/send answers. No discord/google integration at the moment or other functionalities.
42 lines
907 B
JavaScript
42 lines
907 B
JavaScript
import fs from 'fs';
|
|
|
|
import { ENABLE_LOGGING, LOG_DIR } from './config';
|
|
|
|
export default class Logger {
|
|
constructor(filename) {
|
|
this.filename = filename;
|
|
this.logStream = null;
|
|
}
|
|
|
|
async open() {
|
|
return new Promise((resolve, reject) => {
|
|
if (ENABLE_LOGGING) {
|
|
this.logStream = fs.createWriteStream(`${LOG_DIR}${this.filename}`);
|
|
this.logStream.on('open', resolve(true));
|
|
this.logStream.on('error', reject);
|
|
} else {
|
|
resolve(true);
|
|
}
|
|
});
|
|
}
|
|
|
|
log(message, format = msg => msg) {
|
|
console.log(format(message));
|
|
this.logSilent(message);
|
|
};
|
|
|
|
logSilent(message) {
|
|
if (this.logStream) {
|
|
this.logStream.write(`${message}\r\n`);
|
|
}
|
|
}
|
|
|
|
close() {
|
|
if (this.logStream) {
|
|
this.logStream.end();
|
|
}
|
|
}
|
|
}
|
|
|
|
export const toUSD = money => money.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|