chore(backend): Switch console naar logger

Maak gebruik van custom logger
This commit is contained in:
Tibo De Peuter 2025-03-02 15:14:26 +01:00
parent f82668148c
commit c2e3886f3f
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
6 changed files with 29 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import {
} from '../services/learningObjects.js';
import { FALLBACK_LANG } from '../config.js';
import { FilteredLearningObject } from '../interfaces/learningPath';
import { getLogger } from '../logging/initalize';
export async function getAllLearningObjects(
req: Request,
@ -33,7 +34,7 @@ export async function getAllLearningObjects(
res.json(learningObjects);
} catch (error) {
console.error('Error fetching learning objects:', error);
getLogger().error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
@ -54,7 +55,7 @@ export async function getLearningObject(
const learningObject = await getLearningObjectById(hruid, language);
res.json(learningObject);
} catch (error) {
console.error('Error fetching learning object:', error);
getLogger().error('Error fetching learning object:', error);
res.status(500).json({ error: 'Internal server error' });
}
}

View file

@ -5,6 +5,7 @@ import {
fetchLearningPaths,
searchLearningPaths,
} from '../services/learningPaths.js';
import { getLogger } from '../logging/initalize.js';
/**
* Fetch learning paths based on query parameters.
*/
@ -56,7 +57,7 @@ export async function getLearningPaths(
);
res.json(learningPaths.data);
} catch (error) {
console.error('❌ Unexpected error fetching learning paths:', error);
getLogger().error('❌ Unexpected error fetching learning paths:', error);
res.status(500).json({ error: 'Internal server error' });
}
}

View file

@ -1,9 +1,13 @@
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import { Logger } from 'winston';
import { Request, Response } from 'express';
import { themes } from '../data/themes.js';
import { FALLBACK_LANG } from '../config.js';
import { getLogger } from '../logging/initalize.js';
const logger: Logger = getLogger();
interface Translations {
curricula_page: {
@ -17,10 +21,10 @@ function loadTranslations(language: string): Translations {
const yamlFile = fs.readFileSync(filePath, 'utf8');
return yaml.load(yamlFile) as Translations;
} catch (error) {
console.error(
logger.error(
`Cannot load translation for: ${language}, fallen back to Dutch`
);
console.error(error);
logger.error(error);
const fallbackPath = path.join(process.cwd(), '_i18n', 'nl.yml');
return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as Translations;
}