Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging disable on certain Environments #79

Open
vjhurani opened this issue Jan 17, 2019 · 0 comments
Open

Logging disable on certain Environments #79

vjhurani opened this issue Jan 17, 2019 · 0 comments

Comments

@vjhurani
Copy link

vjhurani commented Jan 17, 2019

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'  );
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant