@shipengine/connect
Version:
The official developer tooling for building ShipEngine connect apps
39 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildLogger = void 0;
const winston_1 = require("winston");
const serialize_error_1 = require("serialize-error");
const buildLogger = () => {
function print(msg) {
if (typeof msg === 'string') {
return msg;
}
else if (msg instanceof Error) {
}
else if (msg && Object.keys(msg).length > 0) {
/*
* We run serializeError on arbitrary objects here because we can't tell the
* difference between SDK errors and other objects, and the serializer is a
* pass-through for objects that aren't errors.
*/
return JSON.stringify((0, serialize_error_1.serializeError)(msg));
}
return '';
}
const debugPrint = (info) => {
const metadata = info.metadata;
const transactionId = info.transactionId?.slice(0, 8) ?? '';
const timestamp = metadata?.timestamp.slice(11) ?? '';
const metadataCopy = { ...metadata };
delete metadataCopy.timestamp;
return `${timestamp} ${transactionId} ${info.level}: ${print(info.message)} ${print(metadataCopy)}`;
};
const consoleOptions = {
format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp(), winston_1.format.metadata(), winston_1.format.printf(debugPrint)),
level: process.env.LOG_LEVEL || 'debug',
transports: [new winston_1.transports.Console()],
};
return (0, winston_1.createLogger)(consoleOptions);
};
exports.buildLogger = buildLogger;
//# sourceMappingURL=build-logger.js.map