From 32a13d47cd2da73bbab1d41a5431172b852a849e Mon Sep 17 00:00:00 2001 From: Ralf Aron Date: Tue, 26 Sep 2023 06:30:41 +0200 Subject: [PATCH] test and refactoring --- .vscode/launch.json | 1 + projects/aas-lib/src/lib/notify/notify.service.ts | 4 ++-- projects/aas-server/src/app/aas-server.ts | 2 +- projects/aas-server/src/app/logging/file-logger.ts | 8 ++++---- projects/aas-server/src/app/logging/logger-factory.ts | 10 ++-------- projects/aas-server/src/app/logging/logger.ts | 8 ++++---- projects/aas-server/src/app/ws-server.ts | 2 +- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ac098620..8ecae420 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,6 +28,7 @@ "CONTENT_ROOT": "projects/aas-server/build", "WEB_ROOT": "projects/aas-portal/dist", "ASSETS": "projects/aas-server/src/assets", + "USER_STORAGE": "mongodb://localhost:27017/aasportal-users", "ENDPOINTS": "[\"file:///samples?name=Samples\"]" } }, diff --git a/projects/aas-lib/src/lib/notify/notify.service.ts b/projects/aas-lib/src/lib/notify/notify.service.ts index de9ae4bb..2cfc609a 100644 --- a/projects/aas-lib/src/lib/notify/notify.service.ts +++ b/projects/aas-lib/src/lib/notify/notify.service.ts @@ -50,7 +50,7 @@ export class NotifyService { * Displays an information to the user. * @param message The message. */ - public info(message: string, ...args: any[]): void { + public info(message: string, ...args: unknown[]): void { if (message && !isElement(message)) { message = stringFormat(this.translate.instant(message), args); this.messages.push( @@ -84,7 +84,7 @@ export class NotifyService { * @param type The message type. * @param message The message. */ - public log(type: LogType, message: any): void { + public log(type: LogType, message: unknown): void { if (message) { switch (type) { case LogType.Error: diff --git a/projects/aas-server/src/app/aas-server.ts b/projects/aas-server/src/app/aas-server.ts index 3b417bde..2fa8afc4 100644 --- a/projects/aas-server/src/app/aas-server.ts +++ b/projects/aas-server/src/app/aas-server.ts @@ -21,7 +21,7 @@ container.registerInstance('USERS_DIR', './users'); container.registerType('Logger', FileLogger); container.register('CookieStorage', { useFactory: c => new CookieStorageFactory(c).create() }); container.register('UserStorage', { useFactory: c => new UserStorageFactory(c).create() }); -container.register('winston.Logger', { useFactory: c => new LoggerFactory(c).create() }); +container.register('winston.Logger', { useFactory: () => new LoggerFactory().create() }); container.register('TemplateStorage', { useFactory: c => new TemplateStorageFactory(c).create() }); container.afterResolution(AASProvider, (_, instance) => { diff --git a/projects/aas-server/src/app/logging/file-logger.ts b/projects/aas-server/src/app/logging/file-logger.ts index 7dda9a23..00985c6d 100644 --- a/projects/aas-server/src/app/logging/file-logger.ts +++ b/projects/aas-server/src/app/logging/file-logger.ts @@ -39,7 +39,7 @@ export class FileLogger extends Logger { super(); } - public override error(error: Error | string, ...args: any[]): void { + public override error(error: Error | string, ...args: unknown[]): void { if (this.logger.isErrorEnabled()) { let text: string | null = null; if (error) { @@ -60,7 +60,7 @@ export class FileLogger extends Logger { } } - public override warning(message: string, ...args: any[]): void { + public override warning(message: string, ...args: unknown[]): void { if (this.logger.isWarnEnabled()) { let text: string | null = null; if (typeof message === 'string') { @@ -77,7 +77,7 @@ export class FileLogger extends Logger { } } - public override info(message: string, ...args: any[]): void { + public override info(message: string, ...args: unknown[]): void { if (this.logger.isInfoEnabled()) { let text: string | null = null; if (typeof message === 'string') { @@ -94,7 +94,7 @@ export class FileLogger extends Logger { } } - public override debug(message: Error | string, ...args: any[]): void { + public override debug(message: Error | string, ...args: unknown[]): void { if (this.logger.isDebugEnabled()) { let text: string | null = null; if (message) { diff --git a/projects/aas-server/src/app/logging/logger-factory.ts b/projects/aas-server/src/app/logging/logger-factory.ts index d52f499b..1ef0b09c 100644 --- a/projects/aas-server/src/app/logging/logger-factory.ts +++ b/projects/aas-server/src/app/logging/logger-factory.ts @@ -12,20 +12,16 @@ import winston from 'winston'; import DailyRotateFile from 'winston-daily-rotate-file'; import { isMainThread } from 'worker_threads'; import { noop } from 'lodash-es'; -import { DependencyContainer } from 'tsyringe'; /* istanbul ignore next */ export class LoggerFactory { - constructor(private readonly container: DependencyContainer) { - } - public create(): winston.Logger { const filename = path.resolve('.', 'aas-server-%DATE%.log'); if (isMainThread) { this.deleteLogFiles(); } - const logger = winston.createLogger({ + return winston.createLogger({ level: process.env.NODE_ENV === 'production' ? 'info' : 'debug', transports: [ new DailyRotateFile({ @@ -40,10 +36,8 @@ export class LoggerFactory { }), new winston.transports.Console({ format: winston.format.simple(), - })], + })] }); - - return logger; } private deleteLogFiles(): void { diff --git a/projects/aas-server/src/app/logging/logger.ts b/projects/aas-server/src/app/logging/logger.ts index f91cf995..4affe40a 100644 --- a/projects/aas-server/src/app/logging/logger.ts +++ b/projects/aas-server/src/app/logging/logger.ts @@ -18,28 +18,28 @@ export abstract class Logger { * @param error * @param args Additional arguments. */ - public abstract error(error: Error | string, ...args: any[]): void; + public abstract error(error: Error | string, ...args: unknown[]): void; /** * Logs a warning. * @param message The message format. * @param args The format items. */ - public abstract warning(message: string, ...args: any[]): void; + public abstract warning(message: string, ...args: unknown[]): void; /** * Logs an information. * @param message The message format. * @param args The format items. */ - public abstract info(message: string, ...args: any[]): void; + public abstract info(message: string, ...args: unknown[]): void; /** * Logs a debug message. * @param message The message format. * @param args The format items. */ - public abstract debug(message: Error | string, ...args: any[]): void; + public abstract debug(message: Error | string, ...args: unknown[]): void; /** * Logs the specified message. diff --git a/projects/aas-server/src/app/ws-server.ts b/projects/aas-server/src/app/ws-server.ts index cb0bcd1b..7fdbc6f4 100644 --- a/projects/aas-server/src/app/ws-server.ts +++ b/projects/aas-server/src/app/ws-server.ts @@ -52,7 +52,7 @@ export class WSServer extends EventEmitter { public run(): void { this.server.listen(this.variable.NODE_SERVER_PORT, () => { - console.log(`AAS-Server listening on ${this.variable.NODE_SERVER_PORT}`); + this.logger.info(`AAS-Server listening on ${this.variable.NODE_SERVER_PORT}`); }) }