@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
57 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.log = exports.FlowrLogger = exports.expensiveTrace = void 0;
const tslog_1 = require("tslog");
const rotating_file_stream_1 = require("rotating-file-stream");
const expensiveTrace = (log, supplier) => {
if (log.settings.minLevel <= 1 /* LogLevel.Trace */) {
log.trace(supplier());
}
};
exports.expensiveTrace = expensiveTrace;
class FlowrLogger extends tslog_1.Logger {
/** by keeping track of all children we can propagate updates of the settings (e.g., in tests) */
childLoggers = [];
getSubLogger(settings, logObj) {
const newSubLogger = super.getSubLogger(settings, logObj);
this.childLoggers.push(newSubLogger);
return newSubLogger;
}
updateSettings(updater) {
updater(this);
this.childLoggers.forEach((child) => {
updater(child);
});
}
/**
* make the logger log to a file as well
*/
logToFile(filename = 'flowr.log', options = {
size: '10M',
interval: '1d',
compress: 'gzip',
}) {
const stream = (0, rotating_file_stream_1.createStream)(filename, options);
exports.log.attachTransport((logObj) => {
stream.write(`${JSON.stringify(logObj)}\n`);
});
}
}
exports.FlowrLogger = FlowrLogger;
function getActiveLog() {
return new FlowrLogger({
// set the default minimum level as Warn, and let all apps
// (like the REPL) update it to whatever they want it to be
minLevel: 4 /* LogLevel.Warn */,
type: 'pretty',
name: 'main',
stylePrettyLogs: true,
prettyLogStyles: {
logLevelName: {
'*': ['bold', 'black', 'dim']
}
}
});
}
exports.log = getActiveLog();
//# sourceMappingURL=log.js.map