jcabi / jcabi-aspects

Collection of AspectJ Java Aspects to facilitate aspect-oriented programming patterns: logging, caching, validating, etc.
https://aspects.jcabi.com
Other
531 stars 150 forks source link

Do not see the logs(using log4j) using @Loggable #179

Open kumarvijaypt opened 9 years ago

kumarvijaypt commented 9 years ago

Hi @yegor256 ,

I was trying to follow the link http://www.yegor256.com/2014/06/01/aop-aspectj-java-method-logging.html. However I was unable to find any logs.

Running with JavaSE-1.6 Details: Project structure:

image

Pom:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.source-target.version>1.6</java.source-target.version>
    <aspectj.version>1.8.5</aspectj.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${aspectj.version}</version>
    </dependency>

    <dependency>
        <groupId>com.jcabi</groupId>
        <artifactId>jcabi-aspects</artifactId>
        <version>0.22</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>${java.source-target.version}</source>
          <target>${java.source-target.version}</target>
          <!-- IMPORTANT -->
          <useIncrementalCompilation>false</useIncrementalCompilation>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.7</version>
        <configuration>
          <source>${java.source-target.version}</source>
          <target>${java.source-target.version}</target>
          <Xlint>ignore</Xlint>
          <complianceLevel>${java.source-target.version}</complianceLevel>
          <encoding>${project.build.sourceEncoding}</encoding>
          <!--<verbose>true</verbose> -->
          <!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn> -->
        </configuration>
        <executions>
          <execution>
            <!-- IMPORTANT -->
            <phase>process-sources</phase>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

log4j.properties file in resource directory:

log4j.rootLogger=INFO, file, CONSOLE
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=jcabi.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%-5p}] %c: %m%n

Loggable class:

package com.amadeus.logging.samplelogging;

import com.jcabi.aspects.Loggable;

@Loggable(Loggable.INFO)
public class Flight {

  private int flightID;

  public void setFlightID(int flightID) {
    this.flightID = flightID;
  }

  public int getFlightID() {
    return flightID;
  }

}

Caller class:

package com.amadeus.logging.samplelogging;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        Flight f = new Flight();
        f.setFlightID(0);
    }
}
kumarvijaypt commented 9 years ago

I updated the pom. It started working

image

kumarvijaypt commented 9 years ago

@yegor256 Thanks for great lib. I loved it!

yegor256 commented 9 years ago

@kumarvijaypt please close the ticket if everything is fine now. thanks for using the lib :)

paramitanit commented 7 years ago

i have problem, logs are not writing for me too. i used the class files, pom.xml as above, but the pom xml showing error.I m attaching the error and also the pom.xml file..please help me asap pom pom.txt

paramitanit commented 7 years ago

@kumarvijaypt please share ur complete pom.xml file, if u have, its really urgent