Menu

#21 Facility to remove duplication from annotation

1.1.0
open
None
2016-07-17
2016-07-17
T X
No

Consider:

@Log(enterLevel=Level.NONE, exitLevel=Level.NONE, on=@Exceptions(level=Level.NONE))
public int methodA(String s){ ... }

@Log(enterLevel=Level.NONE, exitLevel=Level.NONE, on=@Exceptions(level=Level.NONE))
public String methodB(int i){ ... }

@Log(enterLevel=Level.NONE, exitLevel=Level.NONE, on=@Exceptions(level=Level.NONE))
public void methodB(int i){ ... }

The documentation should show how to configure aspect4log to remove the duplication:

@Log(enterLevel=Level.NONE, exitLevel=Level.NONE, on=@Exceptions(level=Level.NONE))

That is, it should be possible to configure the default logging behaviour for logged classes. For example:

@Log
public void methodB(int i){ ... }

Then:

<aspect4logConfiguration>
  <defaultAnnotations>
    <annotation>
      <enterLevel>Level.NONE</enterLevel>
      <exitLevel>Level.NONE</exitLevel>
      <on>@Exceptions(level=Level.NONE)</on>
    </annotation>
  <defaultAnnotations>
</aspect4logConfiguration>

This is simpler than defining custom aspects. The annotation scope could be refined:

<annotation> // all packages, all classes, all methods
<annotation package="java.lang"> // all classes & methods in java.lang
<annotation package="java.lang" class="String"> // all methods in String
<annotation package="java.lang" class="String" method="toString"> // specific
<annotation method="toString"> // all methods named toString
<annotation package="java.lang" method="get*"> // all get accessors
<annotation class="*Factory"> // all methods for all factory classes

Discussion


Log in to post a comment.