Add API logging functionality and enhance scheduler service
Introduced ApiLog model and integrated logging for scheduled tasks in the SchedulerService. Updated server.js to include request logging middleware and new API log routes. Enhanced frontend navigation by adding a link to system logs for admin users. Adjusted session check interval in App.vue for improved performance. This update improves monitoring and debugging capabilities across the application.
This commit is contained in:
68
backend/controllers/apiLogController.js
Normal file
68
backend/controllers/apiLogController.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import apiLogService from '../services/apiLogService.js';
|
||||
import HttpError from '../exceptions/HttpError.js';
|
||||
|
||||
class ApiLogController {
|
||||
/**
|
||||
* GET /api/logs
|
||||
* Get API logs with optional filters
|
||||
*/
|
||||
async getLogs(req, res, next) {
|
||||
try {
|
||||
const {
|
||||
userId,
|
||||
logType,
|
||||
method,
|
||||
path,
|
||||
statusCode,
|
||||
startDate,
|
||||
endDate,
|
||||
limit = 100,
|
||||
offset = 0
|
||||
} = req.query;
|
||||
|
||||
const result = await apiLogService.getLogs({
|
||||
userId: userId ? parseInt(userId) : null,
|
||||
logType,
|
||||
method,
|
||||
path,
|
||||
statusCode: statusCode ? parseInt(statusCode) : null,
|
||||
startDate,
|
||||
endDate,
|
||||
limit: parseInt(limit),
|
||||
offset: parseInt(offset)
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: result
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/logs/:id
|
||||
* Get a single log entry by ID
|
||||
*/
|
||||
async getLogById(req, res, next) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const log = await apiLogService.getLogById(parseInt(id));
|
||||
|
||||
if (!log) {
|
||||
throw new HttpError(404, 'Log entry not found');
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: log
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new ApiLogController();
|
||||
|
||||
Reference in New Issue
Block a user