mgechev / mgechev/aspect.js

Logging disable on certain Environments

Open
#79 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
470
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Now I have added Wove to all the classes in the project. But I want the @before / @ after only work in DEV env and not Prod Env,

Can i configure it? Please guide.

import { Injectable } from '@angular/core';
import { LogService } from '../../shared/services/log.service';
import {
beforeMethod,
afterMethod,
Metadata,
} from 'aspect.js';

@Injectable()
export class LoggingAspect {

public static loggerService: LogService;

beforeMessage = '';
afterMessage = '';
constructor() {
}

@beforeMethod({
classNamePattern: /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/,
methodNamePattern: /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/
})
before(meta: Metadata) {
// tslint:disable-next-line:max-line-length
this.beforeMessage = 'Aspect Logger @BeforeMethod - ' + this.getMetaInformation(meta);
console.log(this.beforeMessage);
LoggingAspect.loggerService.postInfoMessage(this.beforeMessage);
}
@afterMethod({
classNamePattern: /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/,
methodNamePattern: /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/
})
after(meta: Metadata) {
// tslint:disable-next-line:max-line-length
this.afterMessage = 'Aspect Logger @AfterMethod - ' + this.getMetaInformation(meta);
console.log(this.afterMessage);
LoggingAspect.loggerService.postInfoMessage(this.afterMessage);
}

getMetaInformation(meta: Metadata): string {
return `Class : ${meta.className}, Method : ${meta.method.name}, Arguments ${this.getArgumentValues(meta.method.args)}`;
}

getArgumentValues(argumentsPassed: any[]) {
let values = 'No arguments';
if ( argumentsPassed !== null && argumentsPassed !== undefined && argumentsPassed.length > 0) {
values = '';

for ( let arg = 0; arg < argumentsPassed.length; ++ arg) {
const argument = argumentsPassed[arg];
if (Array.isArray(argument)) {
for (let i = 0; i < argument.length; ++ i) {
const element = argument[i];
values += `: ${this.getValues(element)} `;
}
} else {
values += `: ${this.getValues(argument)} `;
}

}
}
return values;
}

getValues(argument) {
if ( argument !== null && argument !== undefined) {
if ( this.checkIfObject(argument)) {
return Object.entries(argument);
} else if (this.checkIfPrimitive(argument)) {
}
return argument;
}
}

checkIfPrimitive(argument) {
return ( typeof(argument) === 'string' || 'number' || 'boolean' || 'undefined' );
}

checkIfObject(argument) {
return ( typeof(argument) === 'object' );
}

}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue centers on LoggingAspect and its @beforeMethod/@afterMethod decorators in the Angular/TypeScript example. Start by checking aspect.js decorator configuration and the project's environment handling; done means the hooks run in DEV but not PROD. No repository files or tests are named, so the implementation path and verification still need to be defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.