UNPKG

logstack-zee

Version:

Complete Node.js logging solution with 6 integration methods, S3 bidirectional operations, advanced analytics, and multi-cloud storage support for enterprise-scale applications.

57 lines (56 loc) 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiLogModel = void 0; exports.getApiLogModel = getApiLogModel; const mongoose_1 = __importDefault(require("mongoose")); const apiLogSchema = new mongoose_1.default.Schema({ request_time: { type: Date, default: Date.now, index: true, // Index on timestamp for efficient querying }, response_time: { type: Date, default: Date.now, index: true, // Index on timestamp for efficient querying }, method: { type: String, required: true, }, path: { type: String, index: true, // Index on path for efficient querying }, requestBody: {}, requestHeaders: {}, responseStatus: {}, requestQuery: {}, requestParams: {}, client_ip: { type: String, default: "", }, client_agent: { type: String, default: "", }, responseBody: {}, }, { timestamps: true, }); exports.ApiLogModel = mongoose_1.default.model('ApiLog', apiLogSchema); // Dynamic model creation function for custom collection names function getApiLogModel(collectionName = 'apilogs') { try { // Check if model already exists return mongoose_1.default.model(collectionName); } catch (error) { // Model doesn't exist, create it return mongoose_1.default.model(collectionName, apiLogSchema, collectionName); } }