Skip to content

Commit

Permalink
Annotation transformer - add TRACE logging
Browse files Browse the repository at this point in the history
- so that it's possible to find out which transformer performed a
transformation of a particular target
  • Loading branch information
mkouba committed Nov 22, 2022
1 parent 3c5e064 commit b603f0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/src/main/asciidoc/cdi-integration.adoc
Expand Up @@ -208,6 +208,18 @@ void queryAnnotations(TransformedAnnotationsBuildItem transformedAnnotations, Bu

NOTE: There are other build items specialized in transformation: <<additional_interceptor_bindings>> and <<injection_point_transformation>>.

=== How to Enable Trace Logging for Annotation Transformers

You can set the `TRACE` level for the category `io.quarkus.arc.processor` and try to analyze the log output afterwards.

.`application.properties` Example
[source,properties]
----
quarkus.log.category."io.quarkus.arc.processor".min-level=TRACE <1>
quarkus.log.category."io.quarkus.arc.processor".level=TRACE
----
<1> You also need to adjust the minimum log level for the relevant category.

[[inspect_beans]]
== Use Case - Inspect Beans, Observers and Injection Points

Expand Down
@@ -1,20 +1,23 @@
package io.quarkus.arc.processor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;

import io.quarkus.arc.processor.AnnotationsTransformer.TransformationContext;
import io.quarkus.arc.processor.BuildExtension.BuildContext;
Expand Down Expand Up @@ -138,13 +141,23 @@ private List<AnnotationsTransformer> initTransformers(Kind kind, Collection<Anno
static class TransformationContextImpl extends AnnotationsTransformationContext<Collection<AnnotationInstance>>
implements TransformationContext {

private static final Logger LOG = Logger.getLogger(TransformationContextImpl.class);

public TransformationContextImpl(BuildContext buildContext, AnnotationTarget target,
Collection<AnnotationInstance> annotations) {
super(buildContext, target, annotations);
}

@Override
public Transformation transform() {
if (LOG.isTraceEnabled()) {
String stack = Arrays.stream(Thread.currentThread().getStackTrace())
.skip(2)
.limit(7)
.map(se -> "\n\t" + se.toString())
.collect(Collectors.joining());
LOG.tracef("Transforming annotations of %s %s\n\t...", target, stack);
}
return new Transformation(new ArrayList<>(getAnnotations()), getTarget(), this::setAnnotations);
}

Expand Down
Expand Up @@ -4,6 +4,7 @@

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.logging.Logger;

import io.quarkus.arc.processor.BuildExtension.BuildContext;
import io.quarkus.arc.processor.BuildExtension.Key;
Expand All @@ -13,6 +14,8 @@
*/
abstract class AnnotationsTransformationContext<C extends Collection<AnnotationInstance>> implements BuildContext {

private static final Logger LOG = Logger.getLogger(AnnotationsTransformationContext.class);

protected final BuildContext buildContext;
protected final AnnotationTarget target;
private C annotations;
Expand Down Expand Up @@ -49,6 +52,7 @@ public C getAnnotations() {
}

void setAnnotations(C annotations) {
LOG.tracef("Annotations of %s transformed: %s", target, annotations);
this.annotations = annotations;
}

Expand Down

0 comments on commit b603f0b

Please sign in to comment.