From dc3cdf9f12bb1859ada374c07c1ce0b918d3f523 Mon Sep 17 00:00:00 2001 From: Ralf Aron Date: Sat, 10 Aug 2024 07:04:31 +0200 Subject: [PATCH] fix: update Logger implementation --- .gitlab-ci.yml | 4 +-- .vscode/launch.json | 3 ++- Dockerfile | 4 +-- Dockerfile.aas-server | 1 + .../aas-server/src/app/auth/user-storage.ts | 5 ++++ .../src/app/logging/console-transport.ts | 27 +++++++++++++++++++ .../aas-server/src/app/logging/file-logger.ts | 8 +++--- .../src/app/logging/logger-factory.ts | 5 ++-- 8 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 projects/aas-server/src/app/logging/console-transport.ts diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 255d3fcf..a2806bb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,9 +39,9 @@ test: paths: - reports/aas-portal.xml - reports/aas-server.xml - - reports/common.xml + - reports/aas-core.xml reports: - junit: [reports/aas-portal.xml, reports/aas-server.xml, reports/common.xml] + junit: [reports/aas-portal.xml, reports/aas-server.xml, reports/aas-core.xml] coverage_report: coverage_format: cobertura path: reports/**/cobertura-coverage.xml diff --git a/.vscode/launch.json b/.vscode/launch.json index c2e6488c..4f4ecb49 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -30,8 +30,9 @@ "WEB_ROOT": "projects/aas-portal/dist", "ASSETS": "projects/aas-server/src/assets", // "USER_STORAGE": "mongodb://localhost:27017/aasportal-users", + "USER_STORAGE": "mongodb://172.16.160.178:27017/aasportal-users", // "TEMPLATE_STORAGE": "http://localhost:8080/templates", - // "AAS_INDEX": "mysql://localhost:3306", + // "AAS_INDEX": "mysql://172.16.160.171:3306", "ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\"]", } }, diff --git a/Dockerfile b/Dockerfile index 0a68ecb3..66d30b00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,8 @@ COPY package.json package.json COPY projects/aas-server/package.json projects/aas-server/package.json COPY --from=build /usr/src/app/projects/aas-server/dist/ /usr/src/app/ COPY --from=build /usr/src/app/projects/aas-server/app-info.json /usr/src/app/app-info.json -COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/common/dist/ -COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/common/package.json +COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/aas-core/dist/ +COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/aas-core/package.json COPY --from=build /usr/src/app/projects/aas-portal/dist/browser/ /usr/src/app/wwwroot/ RUN npm install -w=aas-server --omit=dev COPY projects/aas-server/src/assets assets/ diff --git a/Dockerfile.aas-server b/Dockerfile.aas-server index b5a0c53a..9d0f6d3d 100644 --- a/Dockerfile.aas-server +++ b/Dockerfile.aas-server @@ -21,6 +21,7 @@ COPY projects/aas-server/src/assets assets/ ENV NODE_LOG=./log/debug.log ENV NODE_SERVER_PORT=1337 ENV USER_STORAGE=mongodb://172.16.160.178:27017/aasportal-users +ENV AAS_INDEX=mysql://172.16.160.171:3306 ENV ENDPOINTS=["\"file:///endpoints/samples?name=Samples\""] ENV NODE_ENV=production diff --git a/projects/aas-server/src/app/auth/user-storage.ts b/projects/aas-server/src/app/auth/user-storage.ts index 3fc78c7f..e2432adb 100644 --- a/projects/aas-server/src/app/auth/user-storage.ts +++ b/projects/aas-server/src/app/auth/user-storage.ts @@ -39,23 +39,27 @@ export abstract class UserStorage { public abstract deleteAsync(userId: string): Promise; /** + * Determines whether a cookie with the specified name exists. * @param userId The user identification. * @param name The cookie name. */ public abstract checkCookieAsync(userId: string, name: string): Promise; /** + * Gets the value of a cookie. * @param userId The user identification. * @param name The cookie name. */ public abstract getCookieAsync(userId: string, name: string): Promise; /** + * Gets all cookies for the user with the specified ID. * @param userId The user identification. */ public abstract getCookiesAsync(userId: string): Promise; /** + * Sets a new cookie value. * @param userId The user identification. * @param name The cookie name. * @param data @@ -63,6 +67,7 @@ export abstract class UserStorage { public abstract setCookieAsync(userId: string, name: string, data: string): Promise; /** + * Deletes a cookie. * @param userId The user identification. * @param name The cookie name. */ diff --git a/projects/aas-server/src/app/logging/console-transport.ts b/projects/aas-server/src/app/logging/console-transport.ts new file mode 100644 index 00000000..c96272b4 --- /dev/null +++ b/projects/aas-server/src/app/logging/console-transport.ts @@ -0,0 +1,27 @@ +/****************************************************************************** + * + * Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, + * eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft + * zur Foerderung der angewandten Forschung e.V. + * + *****************************************************************************/ + +import Transport from 'winston-transport'; + +export class ConsoleTransport extends Transport { + public override log = (info: { level: string; message: string }, callback: () => void) => { + setImmediate(() => this.emit('logged', info)); + + if (info.level === 'error') { + console.error(info.message); + } else if (info.level === 'warn') { + console.warn(info.message); + } else { + console.info(info.message); + } + + if (callback) { + callback(); + } + }; +} diff --git a/projects/aas-server/src/app/logging/file-logger.ts b/projects/aas-server/src/app/logging/file-logger.ts index ab23f283..701c27b1 100644 --- a/projects/aas-server/src/app/logging/file-logger.ts +++ b/projects/aas-server/src/app/logging/file-logger.ts @@ -50,7 +50,7 @@ export class FileLogger extends Logger { if (text) { if (!this.record.errors.has(text)) { - this.logger.error(text); + this.logger.log('error', text); } this.record.errors.set(text, Date.now()); @@ -67,7 +67,7 @@ export class FileLogger extends Logger { if (text) { if (!this.record.warnings.has(text)) { - this.logger.warn(text); + this.logger.log('warn', text); } this.record.warnings.set(text, Date.now()); @@ -84,7 +84,7 @@ export class FileLogger extends Logger { if (text) { if (!this.record.messages.has(text)) { - this.logger.info(text); + this.logger.log('info', text); } this.record.messages.set(text, Date.now()); @@ -104,7 +104,7 @@ export class FileLogger extends Logger { } if (text) { - this.logger.debug(text); + this.logger.log('debug', text); } } } diff --git a/projects/aas-server/src/app/logging/logger-factory.ts b/projects/aas-server/src/app/logging/logger-factory.ts index 781d7e02..8060bb31 100644 --- a/projects/aas-server/src/app/logging/logger-factory.ts +++ b/projects/aas-server/src/app/logging/logger-factory.ts @@ -12,6 +12,7 @@ import winston from 'winston'; import DailyRotateFile from 'winston-daily-rotate-file'; import { isMainThread } from 'worker_threads'; import { noop } from 'aas-core'; +import { ConsoleTransport } from './console-transport.js'; /* istanbul ignore next */ export class LoggerFactory { @@ -24,6 +25,7 @@ export class LoggerFactory { return winston.createLogger({ level: process.env.NODE_ENV === 'production' ? 'info' : 'debug', transports: [ + new ConsoleTransport(), new DailyRotateFile({ filename: filename, datePattern: 'YYYY-MM-DD', @@ -32,9 +34,6 @@ export class LoggerFactory { maxFiles: '2d', format: winston.format.combine(winston.format.timestamp(), winston.format.json()), }), - new winston.transports.Console({ - format: winston.format.simple(), - }), ], }); }