Spaces:
Sleeping
Sleeping
File size: 1,022 Bytes
e8c33fa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | const mongoose = require('mongoose');
const errorLogSchema = new mongoose.Schema(
{
timestamp: { type: Date, default: Date.now, index: true },
type: { type: String, default: 'Error', trim: true },
message: { type: String, required: true, trim: true },
stack: { type: String, default: '' },
code: { type: String, default: 'INTERNAL_SERVER_ERROR', trim: true },
statusCode: { type: Number, default: 500 },
request: {
url: { type: String, default: '' },
method: { type: String, default: '' },
ip: { type: String, default: '' },
userAgent: { type: String, default: '', maxlength: 300 },
bodyFields: { type: [String], default: [] },
},
userId: { type: String, default: '' },
env: { type: String, default: 'development' },
},
{ versionKey: false }
);
errorLogSchema.index({ timestamp: -1 });
errorLogSchema.index({ code: 1, timestamp: -1 });
module.exports = mongoose.model('ErrorLog', errorLogSchema);
|