Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7437799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:27:17+00:00 2026-05-29T10:27:17+00:00

I am trying to do something very simple. I have a com.mypackage.Logger logger class

  • 0

I am trying to do something very simple. I have a com.mypackage.Logger logger class whose instantiation statement I would like to “insert” into every single class like so: private static Logger LOG = new Logger(Class.class). Then, I would like to log every single entry and exit instance for every single function in my project. Here is my aspect:

public aspect LoggingAspect pertypewithin(*) {

   private static Logger LOG;

   pointcut classes(): within(com.mypackage..*) && !within(com.mypackage.Logger) && !within(com.mypackage.LoggingAspect);
   pointcut functions(): classes() && (execution(* *(..)) || execution(new(..)));

   before(): staticinitialization(*) && classes() {
      LOG = new Logger(thisJoinPointStaticPart.getSignature().getDeclaringType());
   }

   before() : functions() {
      LOG.trace("ENTER " + thisJoinPoint.getSignature().toLongString());
   }


   after() returning(@SuppressWarnings("unused") Object ret) : functions() {
      LOG.trace("EXIT " + thisJoinPoint.getSignature().toLongString());
   }

Almost everything works properly. I am getting correct enter and exist log statements exactly as expected. The problem is that the logging class that is associated with each log entry is incorrect. I am using log4j, and each log entry is formatted like so:

[TRACE] (date and time stamp) (logging class name) (thread name) (some logging statement)

The problem is that the logging class used in Logger instantiation does not match the correct one that is indicated by thisJoinPoint.getSignature().getDeclaringTypeName().

I know that I am not doing something right with respect to the static Logger variable, so please help me. thank you for your time!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:27:17+00:00Added an answer on May 29, 2026 at 10:27 am

    It’s simple

    Your LOG attribute is defined as private static. Static means that’s a class attribute, not instance attribute.

    This is clearly contradicting the instanciation model of your aspect, which is pertypewithin (one instance of aspect created for each type).

    Try to remove the static modifier.

    By the way, defining pertypewithin()* is quite large, you can restrict down the matching with pertypewithin(classes())

    For the logging stuff, I’ve done some experimentations with AspectJ using instanciation model & inter-type declarations. I would advise the implementation using inter-type declaration because it is more memory-saving:

    Logger injection with perthis

    Logger injection with inter-type declaration

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do something which is probably very simple, I have a directory
I am really struggling trying to get something very simple achieved. Essentially, I have
I am trying something very simple, but for some reason it does not work.
I'm trying to do something very simple, yet I can't seem to find the
I am trying to accomplish something very simple, and I'm hoping someone can point
I am trying to do something very simple. I want to display an image
I have a very simple properties file test I am trying to get working:
I'm trying to do something very simple in C++/CLI, however I'm running into issues
I'm trying to do something that should be very simple, but it's causing this
Trying to do something with OpenLDAP that should be very simple, just can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.