Pentaho Report Designer and Bean Shell Scripting – Output and Debug

I will continue with my previous post writing about how to obtain information from Pentaho Report Designer, PRD from now on, that may help you for example to debug Bean Shell Scripting functions.

Output and Debug

The main problem when you work with BSH Scripting is the lack of output. Its quite difficult to know when something is failing and the reason. For those who like me weren’t lucky by finding specific information about how PRD handles Bean Shell functions, what I did was to configure the PDR logging and read the PDR core source code from github.

The Pentaho Report-Designer ships with Log4J and therefore can be configured by placing a log4j.xml file into the $(PRD-Installation-Dir)/resources directory. In Pentaho Report-Designer 3.6, a properly configured log4j-configuration file exists already. Turning on logging will help a lot in debugging your code and understand the context.

In general if you didn’t change anything in your logging configuration you will be able to review the logs and look for errors, for example, lets modify from our last article the function AvgFriendsBSH:

 resultSet = runtime.getData();
 totalRows = resultSet.getRowCount();
 sumFriends = 0;
 for(rowIterator=0; rowIterator<totalRows;rowIterator++){
 sumFriends += runtime.getData().getValueAt(rowIterator,2) // I deleted the ';' 
 return sumFriends/totalRows;

This code will return an error:

2015-09-23 12:15:15,269 [26127610] WARN - org.pentaho.reporting.engine.classic.core.modules.misc.beanshell.BSHExpression - Unable to initialize the expression
Parse error at line 8, column 2.Encountered: }
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)

For those who use Unix based systems, there are two ways to obtain this output:

  • Reading the log file placed in $(Home dir)/.pentaho/log, for example using tail -f ~/.pentaho/log/prd.log
  • Opening the application from console, so all the output will be printed there.

Log4j configuration

As I mentioned before Log4j can be configured so you can specify the logging level, the output file, etc. I will show you an example of most common configurations but if you are interested in more specific details I really encourage you to read the Log4j documentation.

As general rule for increase the logging level we just need to change the value of root category as follow:

   <priority value="INFO"/>
   <appender-ref ref="CONSOLE"/>
   <priority value="DEBUG"/>
   <appender-ref ref="CONSOLE"/>


Notice that root is the top hierarchy category, so by default all non explicitly defined categories has the same logging leve as root category, in our example DEBUG. Each one can be configured with certain logging level ALL, TRACE, DEBUG, FATAL, ERROR, INFO and OFF. In case we are interested in increasing the logging info we just need to change the <priority_value> as shown before.

Some categories for logging:

  • org.pentaho
  • org.mortbay
  • org.pentaho.ui.xul
  • org.pentaho.reporting.libraries.base.util.LoggingStopWatch
  • org.pentaho.reporting.libraries.base.util.LoggingStopWatch.Detail
  • com.healthmarketscience.jackcess
  • org.apache.commons.httpclient
  • org.pentaho.reporting.engine.classic.core.layout.AbstractRenderer
  • org.pentaho.reporting.engine.classic.core.layout.SlottedLayoutBuilder
  • org.pentaho.reporting.libraries.base.util.ResourceBundleSupport
  • org.pentaho.reporting.engine.classic.core.layout

Finally, other option that could interest us is where print the log file. This is option is defined in the appender section. We just need to modify the path as follow:

<appender name="FILE" class="org.apache.log4j.RollingFileAppender"> 
   <param name="MaxFileSize" value="10Mb"/> 
   <param name="MaxBackupIndex" value="5"/> 
   <param name="file" value="${user.home}/.pentaho/logs/prd.log"/> 
   <layout class="org.apache.log4j.PatternLayout"> 
     <param name="ConversionPattern" value="%d [%7r] %6p - %-50c - %m%n"/> 
<appender name="FILE" class="org.apache.log4j.RollingFileAppender"> 
   <param name="MaxFileSize" value="10Mb"/> 
   <param name="MaxBackupIndex" value="5"/> 
   <param name="file" value="${user.home}/.pentaho/my-new-logs/pentaho-new-logs.log"/>
   <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d [%7r] %6p - %-50c - %m%n"/>
Till here the basics about Output and Debug, next time I will explain how to modify PDR charts by using Chart Post-Processing Script. Please I will be really glad to read your suggestions or comments about any errors or ways to improve this post.
Pentaho – BeanShell Data – with error.prpt

Share this:

3 Replies to “Pentaho Report Designer and Bean Shell Scripting – Output and Debug”

  1. First of all I would like to thank you for posting these two magnificent posts. They were really useful for me and opened a new world of possibilities.
    Do you know where can I find extended information or tutorials about Beanshell scripting from PRD, besides the links from your Resources section?
    In my tests, I found that a few standard Beanshell methods seem not to be working from PRD (for instance the .split() one), but I did not find any info in the Pentaho (now Hitachi Vantara) or github forums…
    Best regards,

  2. Hello Iván,
    thanks for your kind words; I’m glad the post was useful to you! But I’m afraid we don’t use Pentaho much these days and Beanshell even less, so we cannot provide any pointers.

Leave a Reply

Your email address will not be published. Required fields are marked *