zeebe-node
Version:
The Node.js client library for the Zeebe Workflow Automation Engine.
132 lines • 4.92 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZBLogger = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const stackTrace = __importStar(require("stack-trace"));
const typed_duration_1 = require("typed-duration");
const ConfigurationHydrator_1 = require("./ConfigurationHydrator");
class ZBLogger {
constructor({ loglevel, color, id, namespace, stdout, taskType, colorise, pollInterval, _tag, }) {
this._tag = _tag;
this.colorFn = color || (m => m);
this.taskType = taskType;
this.id = id;
if (Array.isArray(namespace)) {
namespace = namespace.join(' ');
}
this.namespace = namespace;
this.loglevel =
ConfigurationHydrator_1.ConfigurationHydrator.getLogLevelFromEnv() || loglevel || 'INFO';
this.stdout = stdout || console;
this.colorise = colorise !== false;
this.pollInterval = pollInterval
? typed_duration_1.Duration.milliseconds.from(pollInterval)
: pollInterval;
}
info(message, ...optionalParameters) {
if (this.loglevel === 'NONE' || this.loglevel === 'ERROR') {
return;
}
const frame = stackTrace.get()[1];
const msg = optionalParameters.length > 0
? this.makeMessage(frame, 30, message, optionalParameters)
: this.makeMessage(frame, 30, message);
this.stdout.info(msg);
}
error(message, ...optionalParameters) {
if (this.loglevel === 'NONE') {
return;
}
const frame = stackTrace.get()[1];
const msg = optionalParameters.length > 0
? this.makeMessage(frame, 50, message, optionalParameters)
: this.makeMessage(frame, 50, message);
this.stdout.error(msg);
}
debug(message, ...optionalParameters) {
if (this.loglevel !== 'DEBUG') {
return;
}
const frame = stackTrace.get()[1];
const msg = optionalParameters.length > 0
? this.makeMessage(frame, 20, message, optionalParameters)
: this.makeMessage(frame, 20, message);
if (this.stdout === console) {
this.stdout.info(this._colorise(msg));
}
else {
this.stdout.info(msg);
}
}
log(message, ...optionalParameters) {
if (this.loglevel === 'NONE' || this.loglevel === 'ERROR') {
return;
}
const frame = stackTrace.get()[1];
const msg = optionalParameters.length > 0
? this.makeMessage(frame, 30, message, optionalParameters)
: this.makeMessage(frame, 30, message);
this.stdout.info(msg);
}
makeMessage(frame, level, message, ...optionalParameters) {
// tslint:disable: object-literal-sort-keys
const msg = {
timestamp: new Date(),
context: `${frame.getFileName()}:${frame.getLineNumber()}`,
id: this.id,
level,
message,
time: (0, dayjs_1.default)().format('YYYY MMM-DD HH:mm:ssA'),
};
if (this.pollInterval) {
msg.pollInterval = this.pollInterval;
}
if (this.namespace) {
msg.namespace = this.namespace;
}
if (this.taskType) {
msg.taskType = this.taskType;
}
if (optionalParameters.length > 0) {
;
msg.data = optionalParameters;
}
return JSON.stringify(msg);
}
_colorise(message) {
if (this.colorise) {
// Only colorise console
if (this.colorFn && typeof this.colorFn === 'function') {
return this.colorFn(message);
}
else {
return message;
}
}
return message;
}
}
exports.ZBLogger = ZBLogger;
//# sourceMappingURL=ZBLogger.js.map