Skip to content

Commit

Permalink
test and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Sep 26, 2023
1 parent 560bc45 commit 32a13d4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]"
}
},
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-lib/src/lib/notify/notify.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/src/app/aas-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
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 @@ -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) {
Expand All @@ -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') {
Expand All @@ -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') {
Expand All @@ -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) {
Expand Down
10 changes: 2 additions & 8 deletions projects/aas-server/src/app/logging/logger-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -40,10 +36,8 @@ export class LoggerFactory {
}),
new winston.transports.Console({
format: winston.format.simple(),
})],
})]
});

return logger;
}

private deleteLogFiles(): void {
Expand Down
8 changes: 4 additions & 4 deletions projects/aas-server/src/app/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/src/app/ws-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
})
}

Expand Down

0 comments on commit 32a13d4

Please sign in to comment.