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

@Loggable not work #237

Open
baimingzhang opened this issue Dec 2, 2016 · 15 comments
Open

@Loggable not work #237

baimingzhang opened this issue Dec 2, 2016 · 15 comments

Comments

@baimingzhang
Copy link

baimingzhang commented Dec 2, 2016

After run the code, nothing happened.

My code is:

public static void main(String[] args) {
		power(3, 5);
	}

	@Loggable(Loggable.DEBUG)
	public static int power(int x, int p) {
		return (int) Math.pow(x, p);
	}

my log4j.properties is

log4j.properties:
log4j.rootLogger=INFO, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.file=/log/applicationLog.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n

my pom.xml is :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>simple</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>test</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.jcabi</groupId>
			<artifactId>jcabi-aspects</artifactId>
			<version>0.22.5</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.8.9</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.20</version>
		</dependency>
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
				<!--This plugin's configuration is used to store Eclipse m2e settings 
					only. It has no influence on the Maven build itself. -->
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>com.jcabi</groupId>
										<artifactId>jcabi-maven-plugin</artifactId>
										<versionRange>[0.0,)</versionRange>
										<goals>
											<goal>ajc</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<execute />
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>com.jcabi</groupId>
				<artifactId>jcabi-maven-plugin</artifactId>
				<version>0.14.1</version>
				<executions>
					<execution>
						<goals>
							<goal>ajc</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
@dmarkov
Copy link

dmarkov commented Dec 5, 2016

@yegor256 take a look at this issue please and dispatch it somehow, see par.21

@yegor256
Copy link
Member

@baimingzhang it seems to be correct. Do you have directory target/unwoven after the build?

@baimingzhang
Copy link
Author

@yegor256 yes, there is a directory target/unwoven after the build

@trusharusa
Copy link

trusharusa commented Jan 8, 2017

I am trying to weave on java8 and spring boot project, and I am getting nullpointer, please help.

here is what I have added in my pom.xml

 <plugin>
	        <groupId>com.jcabi</groupId>
	        <artifactId>jcabi-maven-plugin</artifactId>
	        <version>0.14.1</version>
	         <configuration>
            <source>1.8</source>
            <target>1.8</target>
         </configuration>
	        <executions>
	          <execution>
	          	<id>default-prepare-agent</id>
			   <phase>prepare-package</phase>
	            <goals>
	              <goal>ajc</goal>
	            </goals>
	          </execution>
	        </executions>
	        <dependencies>
            
         </dependencies>
	      </plugin>

and

<dependency>
			  <groupId>com.jcabi</groupId>
			  <artifactId>jcabi-aspects</artifactId>
			  <version>0.22.5</version>
			</dependency>
			<dependency>
			  <groupId>org.aspectj</groupId>
			  <artifactId>aspectjrt</artifactId>
			  <version>1.6.12</version>
			  <scope>runtime</scope>
			</dependency>

This is what I got

jcabi-aspects 0.18/55a5c13 started new daemon thread jcabi-loggable for watching of @Loggable annotated methods
[INFO] jcabi-aspects 0.18/55a5c13 started new daemon thread jcabi-cacheable for automated cleaning of expired @Cacheable values
[ERROR] #classpath(): thrown java.lang.NullPointerException out of com.jcabi.maven.plugin.AjcMojo#dependencies[403] in 167ms
[ERROR] #execute(): thrown java.lang.NullPointerException out of com.jcabi.maven.plugin.AjcMojo#dependencies[403] in 242ms

@trusharusa
Copy link

trusharusa commented Jan 8, 2017

<dependency>
			  <groupId>com.jcabi</groupId>
			  <artifactId>jcabi-aspects</artifactId>
			  <version>0.22.5</version>
			</dependency>
			<dependency>
			  <groupId>org.aspectj</groupId>
			  <artifactId>aspectjrt</artifactId>
			  <version>1.6.12</version>
			  <scope>runtime</scope>
			</dependency>



<plugin>
	        <groupId>com.jcabi</groupId>
	        <artifactId>jcabi-maven-plugin</artifactId>
	        <version>0.14.1</version>
	         <configuration>
            <source>1.8</source>
            <target>1.8</target>
         </configuration>
	        <executions>
	          <execution>
	          	<id>default-prepare-agent</id>
			   <phase>prepare-package</phase>
	            <goals>
	              <goal>ajc</goal>
	            </goals>
	          </execution>
	        </executions>
	        <dependencies>
            
         </dependencies>
	      </plugin>

@trusharusa
Copy link

trusharusa commented Jan 9, 2017

<dependency>
			<groupId>com.jcabi</groupId>
			<artifactId>jcabi-aspects</artifactId>
			<version>0.22.5</version>
		</dependency>

doesn't support java8 and spring aspects...can't woven

@yegor256
Copy link
Member

@trusharusa this is strange, since in this project we use Java8 and jcabi-aspects, without any issues: https://github.com/yegor256/jare

@Lovegiver
Copy link

Lovegiver commented Mar 8, 2017

Hi @yegor256

is there one unique place where I could find the way to install all the stuff needed to make "Loggable" annotation works ?
I've spent many hours yet but nothing works.
I've read the blog and many posts on Stackoverflow, but I'm surely missing something.

My app uses Spring.
My logs are managed with Logback and also use a bridge logging from JCL to SLF4J.

Here are all the packages I've installed for AOP :

	<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjrt</artifactId>
		<version>${aspectj.version}</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>${aspectj.version}</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-aspects -->
	<dependency>
		<groupId>com.jcabi</groupId>
		<artifactId>jcabi-aspects</artifactId>
		<version>0.22</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-log -->
	<dependency>
		<groupId>com.jcabi</groupId>
		<artifactId>jcabi-log</artifactId>
		<version>0.17.2</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-maven-plugin -->
	<dependency>
		<groupId>com.jcabi</groupId>
		<artifactId>jcabi-maven-plugin</artifactId>
		<version>0.14.1</version>
	</dependency>

I also added these lines as specified :

	<plugins>
		<plugin>
			<groupId>com.jcabi</groupId>
			<artifactId>jcabi-maven-plugin</artifactId>
			<executions>
				<execution>
					<goals>
						<goal>ajc</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>

But there's an error : Plugin execution not covered by lifecycle configuration: com.jcabi:jcabi-maven-plugin:0.14.1:ajc (execution: default, phase: process-classes)

When I run my test classes, nothing with the "Loggable" annotation generates any logs in the console.

I have a message telling me :

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Fr%c3%a9d%c3%a9ric/.m2/repository/ch/qos/logback/logback
-classic/1.1.6/logback-classic-1.1.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Fr%c3%a9d%c3%a9ric/.m2/repository/com/jcabi/jcabi-maven-
slf4j/0.9/jcabi-maven-slf4j-0.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

@jasonmg
Copy link

jasonmg commented Mar 14, 2017

@trusharusa, @yegor256 Hi, regarding the issue not working under java8 and spring environment, do you have any solution yet? cause i face the exactly problem as you posted above.

@bemnet4u
Copy link

Any update on this? I am also seeing this in a non spring environment.

@Lovegiver
Copy link

Hi,
no answer yet, as if this thread was completely inactive.
I think I gonna use Lombock, not as simple as a single "loggable" annotation but not so far ^^

++

@lazy-ninja
Copy link

Facing the same issue

@HadrienMP
Copy link

Hi, same issue here. I tried with the smallest program possible and only the dependencies listed on the jcabi-aspects site.

Have any of you found a solution yet ?

@Maze-fr
Copy link

Maze-fr commented Jun 19, 2018

Same as #256 and #246

@hyiger
Copy link

hyiger commented Dec 12, 2018

To get this to work I ditched the jcabi-maven-plugin and used the aspectj-maven-plugin instead. This will also resolve eclipse issues since this plugin is covered by the m2e maven eclipse integration framework.

The POM file can be setup as follows:

  1. First the dependencies:
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.9.2</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.9.2</version>
		</dependency>
		<dependency>
			<groupId>com.jcabi</groupId>
			<artifactId>jcabi-aspects</artifactId>
			<version>0.22.6</version>
		</dependency>
  1. Next setup the aspectj-maven-plugin note the weaveDependencies section
	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>aspectj-maven-plugin</artifactId>
				<version>1.11</version>
				<configuration>
					<complianceLevel>1.8</complianceLevel>
					<source>1.8</source>
					<target>1.8</target>
					<showWeaveInfo>true</showWeaveInfo>
					<verbose>true</verbose>
					<Xlint>ignore</Xlint>
					<encoding>UTF-8 </encoding>
					<weaveDependencies>
						<weaveDependency>
							<groupId>com.jcabi</groupId>
							<artifactId>jcabi-aspects</artifactId>
						</weaveDependency>
					</weaveDependencies>
				</configuration>
				<executions>
					<execution>
						<goals>
							<!-- use this goal to weave all your main classes -->
							<goal>compile</goal>
							<!-- use this goal to weave all your test classes -->
							<goal>test-compile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
  1. Add @loggable annotation to methods you wish to trace
@Loggable(Loggable.DEBUG)
public double foo(double x, double y) {
    return x * y;
}
  1. Optional: install eclipse AspectJ Development Tools from the Eclipse Marketplace

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