@livy/util
Version:
Common utilities for the Livy logger
74 lines (73 loc) • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractSyncFormattingProcessingHandler = exports.AbstractFormattingProcessingHandler = void 0;
const abstract_level_bubble_handler_1 = require("./abstract-level-bubble-handler");
const formattable_handler_mixin_1 = require("./formattable-handler-mixin");
const processable_handler_mixin_1 = require("./processable-handler-mixin");
/**
* Base Handler class providing the Handler structure, including processors and formatters
* Classes extending it should (in most cases) only implement `write`
*/
class AbstractFormattingProcessingHandler extends (0, formattable_handler_mixin_1.FormattableHandlerMixin)((0, processable_handler_mixin_1.ProcessableHandlerMixin)(abstract_level_bubble_handler_1.AbstractLevelBubbleHandler)) {
/**
* @inheritdoc
*/
async handle(record) {
if (!this.isHandling(record.level)) {
return false;
}
record = this.processRecord(record);
const formatted = this.formatter.format(record);
await this.write(record, formatted);
return !this.bubble;
}
}
exports.AbstractFormattingProcessingHandler = AbstractFormattingProcessingHandler;
/**
* Base Handler class providing the Handler structure, including processors and formatters
* Classes extending it should (in most cases) only implement `writeSync` and possibly `write`
*/
class AbstractSyncFormattingProcessingHandler extends (0, formattable_handler_mixin_1.FormattableHandlerMixin)((0, processable_handler_mixin_1.ProcessableHandlerMixin)(abstract_level_bubble_handler_1.AbstractLevelBubbleHandler)) {
/**
* Invoke the `write`/`writeSync` method
*
* @param record The record to handle
* @param mode The mode in which to invoke the write
*/
doHandle(record, mode) {
if (!this.isHandling(record.level)) {
return false;
}
record = this.processRecord(record);
const formatted = this.formatter.format(record);
if (mode === 'async') {
return this.write(record, formatted).then(() => !this.bubble);
}
else {
this.writeSync(record, formatted);
return !this.bubble;
}
}
/**
* @inheritdoc
*/
async handle(record) {
return this.doHandle(record, 'async');
}
/**
* @inheritdoc
*/
handleSync(record) {
return this.doHandle(record, 'sync');
}
/**
* Write the record down to the log of the implementing handler
*
* @param record
* @param formatted
*/
write(record, formatted) {
return Promise.resolve(this.writeSync(record, formatted));
}
}
exports.AbstractSyncFormattingProcessingHandler = AbstractSyncFormattingProcessingHandler;