Jump to content
We've recently updated our Privacy Statement, available here ×
  • Configuring Apache Commons Logging and Log4J in Jaspersoft Studio


    Massimo Rabbi
    • Features: Logging Product: Jaspersoft® Studio

    Problem

    It may appear tricky to configure logging for solutions like Apache Commons Logging or Log4J, in Jaspersoft Studio (Professional).

    Solution

    Here below we will see some steps that allows us to configure different output files when using Apache Commons Logging and Log4J. We also specified to have detailed information (log level ALL) when logging is performed by one of the BigData connectors.

    This is only one of the possible scenario. Different solutions can be taken, just modifying the JVM arguments passed or changing the configuration log files. 

    1. Locate the Jaspersoft Studio installation folder. For example: C:Program FilesJaspersoftJaspersoft Studio Professional-5.5.0.final

    2. Edit the Jaspersoft Studio Professional.ini file and add the following arguments:

      -Dlog4j.configuration=file:/C:/jsslog/config/log4j-config.properties
      -Dorg.apache.commons.logging.diagnostics.dest=C:/jsslog/outputs/commonsLoggingDiagOutput.log
      -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
      -Djava.util.logging.config.file=C:/jsslog/config/logging-config.properties
      

      • log4j.configuration specifies to use the dedicated file for loading Log4J configuration
      • org.apache.commons.logging.diagnostics.dest specifies the output file for logging diagnostic messages of the Apache Commons Logging
      • org.apache.commons.logging.Log specifies which Log implementation to use, in our case the one that wraps the standard JDK logging mechanisms
      • java.util.logging.config.file specifies to use the dedicated file for loading the Java Logging API configuration
    3. Create the log4j-config.properties as follow:

      log4j.debug = true
      log4j.appender.fileout = org.apache.log4j.RollingFileAppender
      log4j.appender.fileout.File = C:/jsslog/outputs/studioLOG4J.log
      log4j.appender.fileout.MaxBackupIndex = 5
      log4j.appender.fileout.MaxFileSize = 8192KB
      log4j.appender.fileout.layout = org.apache.log4j.PatternLayout
      log4j.appender.fileout.layout.conversionPattern = %d{ABSOLUTE} %5p %c{1},%t:%L - %m%n
      log4j.rootLogger = DEBUG, fileout
      

    4. Create the logging-config.properties as follow:

      # File Handler
      handlers = java.util.logging.FileHandler
      # Set the default logging level for the root logger
      .level = INFO
      # log level for the connectors
      com.jaspersoft.connectors.cassandra.level = ALL
      com.jaspersoft.connectors.hive.level = ALL
      com.jaspersoft.mongodb.level = ALL
      # Default formatter
      java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
      # Specify the location and name of the log file
      java.util.logging.FileHandler.pattern = C:/jsslog/outputs/studio-common.log
      

    5. If you use Studio Preferences to set the logging properties (Preferences > Jaspersoft Studio > Global Settings), make sure you comment out the FileHandler.level or it will override the other levels set for packages / classes. This is because by default it is set later on in the config file:

      # java.util.logging.FileHandler.level = INFO
      

    Additional notes

    • To debug queries generated by the report, try adding this to the logging-config.properties
      net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.level = FINE

    • You can also change the default level to off, if you want only your specific packages / classes to produce output in the log, for example: 

      .level = OFF

      That will produce a cleaner log file.

    • As for some other use case scenarios it can be useful to startup Jaspersoft Studio via command prompt in order to further investigate what is happening. For this reason you should locate the Jaspersoft Studio installation folder and rename the existing "eclipsec.exe" file to "Jaspersoft Studio Professionalc.exe".
    • Then you can start the Jaspersoft Studio application using the command "Jaspersoft Studio Professionalc.exe" -consoleLog
    • Verify that you have permissions to read/write in the folder specified for config/output files. 
    • We did not use the Log4JLogger implementation in the org.apache.commons.logging.Log property because we verified issues similar to those described in here, with a similar error:

      The log adapter 'org.apache.commons.logging.impl.Log4JLogger' is missing dependencies when loaded via classloader <....>

      We need to further investigate the problem. 

    Related articles


    User Feedback

    Recommended Comments

    I believe Log4j (as opposed to Commons Logging) works only if a class uses it explicitly?


    For example net.sf.jasperreports.engine.query.JRJdbcQueryExecuter does not work in debug in log4j-config.properties, but it worked for me when set in log.properties:


     


    net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.level = FINE


     


    Btw it only works if I comment out the FileHandler level, otherwise it stays everything at INFO level instead of FINE:


     


    # java.util.logging.FileHandler.level = INFO


    Link to comment
    Share on other sites



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...