fix: replace console.log/console.error with proper logging in monitoring and themes routes
- monitoring.js: Added log dependency, replaced console.log with log.warn - themes.js: Added log dependency, replaced console.error with log.error - src/app.js: Pass log to monitoringRoutes and themesRoutes This fixes error messages being lost to stdout instead of proper log files.
This commit is contained in:
@@ -7,9 +7,10 @@ const { success } = require('../response-helpers');
|
||||
* @param {Object} deps.resourceMonitor - Resource monitoring manager
|
||||
* @param {Object} deps.docker - Docker client wrapper
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ resourceMonitor, docker, asyncHandler }) {
|
||||
module.exports = function({ resourceMonitor, docker, asyncHandler, log }) {
|
||||
const router = express.Router();
|
||||
|
||||
// ===== RESOURCE MONITORING ENDPOINTS =====
|
||||
@@ -119,7 +120,7 @@ module.exports = function({ resourceMonitor, docker, asyncHandler }) {
|
||||
});
|
||||
} catch (e) {
|
||||
// Skip containers we can't get stats for
|
||||
console.log(`Could not get stats for ${containerInfo.Names[0]}:`, e.message);
|
||||
log.warn('monitoring', `Could not get stats for ${containerInfo.Names[0]}`, { error: e.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@ const { ValidationError, NotFoundError } = require('../errors');
|
||||
* Themes routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ asyncHandler }) {
|
||||
module.exports = function({ asyncHandler, log }) {
|
||||
const router = express.Router();
|
||||
const THEMES_DIR = process.env.THEMES_DIR || path.join(path.dirname(process.env.SERVICES_FILE || '/app/services.json'), 'themes');
|
||||
|
||||
@@ -29,7 +30,7 @@ module.exports = function({ asyncHandler }) {
|
||||
themes[slug] = data;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Themes] Failed to read themes:', e.message);
|
||||
log.error('themes', 'Failed to read themes', { error: e.message });
|
||||
}
|
||||
return themes;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,8 @@ async function createApp() {
|
||||
apiRouter.use(monitoringRoutes({
|
||||
resourceMonitor: ctx.resourceMonitor,
|
||||
docker: ctx.docker,
|
||||
asyncHandler: ctx.asyncHandler
|
||||
asyncHandler: ctx.asyncHandler,
|
||||
log: ctx.log
|
||||
}));
|
||||
apiRouter.use(updatesRoutes({
|
||||
updateManager: ctx.updateManager,
|
||||
@@ -420,7 +421,7 @@ async function createApp() {
|
||||
asyncHandler: ctx.asyncHandler
|
||||
}));
|
||||
apiRouter.use('/recipes', recipesRoutes(ctx));
|
||||
apiRouter.use(themesRoutes({ asyncHandler: ctx.asyncHandler }));
|
||||
apiRouter.use(themesRoutes({ asyncHandler: ctx.asyncHandler, log: ctx.log }));
|
||||
apiRouter.use('/docker', dockerResourcesRoutes({
|
||||
docker: ctx.docker,
|
||||
asyncHandler: ctx.asyncHandler
|
||||
|
||||
Reference in New Issue
Block a user