Skip to content

Commit

Permalink
fix: update Logger implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Aug 10, 2024
1 parent 4ad7b9d commit dc3cdf9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]",
}
},
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.aas-server
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions projects/aas-server/src/app/auth/user-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,35 @@ export abstract class UserStorage {
public abstract deleteAsync(userId: string): Promise<boolean>;

/**
* 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<boolean>;

/**
* Gets the value of a cookie.
* @param userId The user identification.
* @param name The cookie name.
*/
public abstract getCookieAsync(userId: string, name: string): Promise<Cookie | undefined>;

/**
* Gets all cookies for the user with the specified ID.
* @param userId The user identification.
*/
public abstract getCookiesAsync(userId: string): Promise<Cookie[]>;

/**
* Sets a new cookie value.
* @param userId The user identification.
* @param name The cookie name.
* @param data
*/
public abstract setCookieAsync(userId: string, name: string, data: string): Promise<void>;

/**
* Deletes a cookie.
* @param userId The user identification.
* @param name The cookie name.
*/
Expand Down
27 changes: 27 additions & 0 deletions projects/aas-server/src/app/logging/console-transport.ts
Original file line number Diff line number Diff line change
@@ -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();
}
};
}
8 changes: 4 additions & 4 deletions projects/aas-server/src/app/logging/file-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -104,7 +104,7 @@ export class FileLogger extends Logger {
}

if (text) {
this.logger.debug(text);
this.logger.log('debug', text);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions projects/aas-server/src/app/logging/logger-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand All @@ -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(),
}),
],
});
}
Expand Down

0 comments on commit dc3cdf9

Please sign in to comment.