log-vault
Version:
A generator of Winston logger instance with pre-defined configurable transports and formats and extra functionality.
26 lines (25 loc) • 852 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatLoki = void 0;
const winston_1 = require("winston");
const __1 = require("..");
exports.formatLoki = (0, winston_1.format)((info) => {
const { timestamp, level, meta, message, extra } = info;
const { project, environment, ...otherLabels } = meta;
let content = message;
if (extra === null || extra === void 0 ? void 0 : extra.length)
content = [message, ...extra];
if (!["number", "string"].includes(typeof info.message))
content = JSON.stringify(info.message, null, 2);
const messageObj = {
meta: otherLabels,
content
};
return {
timestamp,
level,
labels: { project, environment },
message: messageObj,
[__1.MESSAGE]: JSON.stringify(messageObj)
};
});