|
Configuration
The behaviour of C4J like aktivating or deactivating contracts or how to react to a contract violation can be controled by its configuration.
The C4J configuration is done be means of four configuration files in the source folder src/main/resources:
Logging can be done on different levels:
The c4j-global.xml might look like this (complete listing):
<?xml version="1.0" encoding="UTF-8"?>
<c4j-global xmlns="http://c4j.vksi.de/c4j-global/">
<write-transformed-classes directory="c4j-classes">false</write-transformed-classes>
<contract-violation-action>
<default>
<log>false</log>
<throw-error>true</throw-error>
</default>
<package name="timeofday">
<log>false</log>
<throw-error>true</throw-error>
</package>
<class name="timeofday.TimeOfDay">
<log>false</log>
<throw-error>true</throw-error>
</class>
</contract-violation-action>
</c4j-global>
The c4j-local.xml might look like this (complete listing):
<?xml version="1.0" encoding="UTF-8"?>
<c4j-local xmlns="http://c4j.vksi.de/c4j-local/">
<configuration>
<root-package>timeofday</root-package>
<pure-validate>true</pure-validate>
<pure-registry-import>c4j-pure-registry.xml</pure-registry-import>
<contract-scan-package>timeofday</contract-scan-package></configuration>
</c4j-local>
The c4j-pure-registry.xml might look like this (complete listing):
<?xml version="1.0" encoding="UTF-8"?>
<c4j-pure-registry xmlns="http://c4j.vksi.de/c4j-pure-registry/">
<type name="java.lang.Boolean">
<pure-method signature="booleanValue()"/>
</type>
<type name="java.lang.Class">
<pure-method signature="getName()"/>
</type>
<type name="java.lang.Integer">
<pure-method signature="intValue()"/>
<pure-method signature="valueOf(int)"/>
</type>
<type name="java.lang.Object">
<pure-method signature="getClass()"/>
<pure-method signature="equals(java.lang.Object)"/>
<pure-method signature="hashCode()"/>
<pure-method signature="toString()"/>
</type>
<type name="java.lang.String">
<pure-method signature="valueOf(java.lang.Object)"/>
</type>
<type name="java.util.Collection">
<pure-method signature="size()"/>
<pure-method signature="isEmpty()"/>
</type>
<type name="java.util.List">
<pure-method signature="get(int)"/>
</type>
</c4j-pure-registry>
The log4j.properties might look like this (complete listing): log4j.rootLogger=INFO, ConsoleAppender log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.ConsoleAppender.layout.ConversionPattern=C4J %-5p - %m%n |