rex-server
Version:
Rex Server is a Node.js-based reverse proxy server available as an npm package. It allows you to handle HTTP and HTTPS traffic, route requests to upstream servers, and manage worker processes efficiently. With its CLI interface, Rex makes it easy to confi
93 lines (92 loc) • 3.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__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.logger = void 0;
exports.formatObjects = formatObjects;
const conf_1 = __importDefault(require("../conf/conf"));
const winston_1 = __importStar(require("winston"));
/**
* The logger instance for the Rex server.
*
* This logger is configured using the `winston` library and writes log messages to a file specified
* in the configuration. It includes timestamps and formats log messages for better readability.
*
* - Log Level: `debug`
* - Log File: Defined by `conf.LOG_FILE_PATH`
* - Format:
* - Timestamp: UTC format
* - Message: Includes timestamp, log level, and the log message
*
* @example
* logger.info("This is an info message");
* logger.error("This is an error message");
*/
exports.logger = winston_1.default.createLogger({
transports: [
new winston_1.transports.File({
filename: conf_1.default.LOG_FILE_PATH,
level: "debug",
format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), winston_1.format.printf((type) => `\n[${type.timestamp}] \n${type.level}: ${type.message}`)),
}),
]
});
/**
* Formats objects or arrays into a JSON string with indentation for readability.
*
* This utility function is useful for logging or debugging complex objects by converting them
* into a well-formatted JSON string.
*
* @param {Object | Array<any>} obj - The object or array to format.
* @returns {string} A stringified version of the input object or array with 2-space indentation.
*
* @example
* const data = { key: "value", list: [1, 2, 3] };
* console.log(formatObjects(data));
* // Output:
* // {
* // "key": "value",
* // "list": [
* // 1,
* // 2,
* // 3
* // ]
* // }
*/
function formatObjects(obj) {
return JSON.stringify(obj, null, 2);
}