Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Logging disable on certain Environments #79

Copy link
Copy link

Description

@vjhurani
Issue body actions

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

}

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.