5.6.2. Setting up Logging in The Desktop Client

For the desktop client, the log4j.xml file should be located in the source files directory of the project’s desktop module. When an application is built, it is packed into the corresponding JAR file and is accessible in CLASSPATH.

Make the following steps to set up logging for your project:

  • Create a new file, for example sample-log4j.xml, in the src directory of the desktop module, and copy the contents of cuba-log4j.xml to this new file. cuba-log4j.xml file is located in one of the platform’s JAR files and can be easily found using search in the IDE, given that the base projects are configured properly.

  • Define path to a log file in the File parameter of the FILE appender.

  • Add settings for category loggers in your project.

  • In the inheritor class of com.haulmont.cuba.desktop.App of your project, for example SampleApp, override the getDefaultLog4jConfig() method and use it to return the path to your log file relative to the CLASSPATH root. For example:

    public class SampleApp extends App {
    ...
        @Override
        protected String getDefaultLog4jConfig() {
            return "sample-log4j.xml";
        }
  • If necessary, you can override the location of the configuration file at application start using log4j.configuration system property.