1 var fs = require("fs");
2 var path = require("path");
3 import { Logger as JsliLogger, LogLevel } from '@calzoneman/jsli';
4 import jsli from '@calzoneman/jsli';
6 function getTimeString() {
8 return d.toDateString() + " " + d.toTimeString().split(" ")[0];
11 var Logger = function(filename) {
12 this.filename = filename;
13 this.writer = fs.createWriteStream(filename, {
19 Logger.prototype.log = function () {
21 for(var i in arguments)
28 var str = "[" + getTimeString() + "] " + msg + "\n";
30 this.writer.write(str);
32 errlog.log("WARNING: Attempted logwrite failed: " + this.filename);
33 errlog.log("Message was: " + msg);
38 Logger.prototype.close = function () {
42 errlog.log("Log close failed: " + this.filename);
46 function makeConsoleLogger(filename) {
47 /* eslint no-console: off */
48 var log = new Logger(filename);
50 log.log = function () {
51 console.log.apply(console, arguments);
52 this._log.apply(this, arguments);
57 var errlog = makeConsoleLogger(path.join(__dirname, "..", "error.log"));
58 var syslog = makeConsoleLogger(path.join(__dirname, "..", "sys.log"));
59 var eventlog = makeConsoleLogger(path.join(__dirname, "..", "events.log"));
61 exports.Logger = Logger;
62 exports.errlog = errlog;
63 exports.syslog = syslog;
64 exports.eventlog = eventlog;
66 class LegacyLogger extends JsliLogger {
67 constructor(loggerName, level) {
68 super(loggerName, level);
71 emitMessage(level, message) {
72 var output = `[${level.name}] ${this.loggerName}: ${message}`;
73 if (level.shouldLogAtLevel(LogLevel.ERROR)) {
81 // TODO: allow reconfiguration of log level at runtime
82 const level = process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO;
84 jsli.setLogBackend((loggerName) => {
85 return new LegacyLogger(loggerName, level);