Logging

C4J comes with a logging mechanism which enables you to log class invariant, post, and pre condition checks. A logger class must implement the interface Logger and can then be registered via ContractBase.addLogger(Logger logger).

Here is an example:

public class ContractLogger implements Logger {
    void classInvariantCheck(String className) {
        System.out.println("Verifying class invariant of: " + className);
    }
    
    void postConditionCheck(String className, String method, Object[] parameters) {
        System.out.println("Verifying post condition of method" + method + " in class " + className);
    }
	
    void preConditionCheck(String className, String method, Object[] parameters) {
        System.out.println("Verifying pre condition of method" + method + " in class " + className);
    }
}

public class SomeContract extends ContractBase<Some> {
    public void SomeContract(Some target) {
        super(target);
        addLogger(new ContractLogger());
    }
	
    ...
}