Blackboard Building Block Development - Problem With Using log4j For Logging

We recently deployed a new Blackboard building block (B2) to our production system. After deployment I noticed that this new B2 was not writing log messages. This article explains how I solved that problem.

The B2 used the log4j library and worked correctly on our test server. Both our test and production Blackboard systems are Learn 9.1, Service Pack 9. The only difference between the test and production systems is that there are some B2s on the production system that are not on our test system. It may be that one or more of the B2s on the production system are preventing this new B2 from being able to write log messages using log4j. We have filed a support request with Blackboard and they are researching the issue.

To solve our immediate problem of no log messages in production I replaced log4j with the Simple Logging Facade for Java (slf4j) and logback libraries.

You can view/get an example B2 that demonstrates how to use slf4j and logback for building block logging at my GitHub repository: https://github.com/phillips1021/phillips_b2_examples/tree/master/B2_Servlet_Example_Part_Two

To use slf4j and logback for B2 logging, download the libraries from their websites. In your building block under the WEB-INF/lib folder place these jar files:

  1. logback-classic
  2. logback-core
  3. slf4j-api

Add to the B2's class path a logback.xml file that specifices the settings logback should use. Below are the contents of the example project's logback.xml



<?xml version="1.0" encoding="UTF-8"?>
<!--
Enable configuration scanning to automatically pick up changes
made to this file and reconfigure logging on the fly. Default
scan period is 1 minute.
-->

<configuration scan="true">

<!-- appender for connect -->
<appender name="PUBLISHERS" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--
The file path is relative to the service-wrapper bin directory
located at ${bb.root}/apps/service-wrapper/bin. The path below
maps to ${bb.root}/logs/custom/.
-->

<file>../../../logs/custom/b2servletexample2.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>../../../logs/custom/b2servletexample2.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 21 days' worth of history -->
<maxHistory>21</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%-5p[%d{yyyy-MM-dd HH:mm:ss}][%-24t] : %m%n</pattern>
</encoder>
</appender>

<logger name="edu.ku.it.si">
<level value="debug" />
</logger>

<root>
<level value="error"/>
<appender-ref ref="PUBLISHERS" />
</root>

</configuration>


Note that the logback configuration specifies writing the log messages to a file named b2servletexample2 in folder [Blackboard Home]/logs/custom.

You will also need to add a permission statement to the bb-mainifest.xml that will allow your building block to create files in the logs/custom folder.



<permission type="java.io.FilePermission" name="BB_HOME/logs/-"
actions="read,write,delete"/>


The above permission allows your Building Block to write to a log file that is in the logs folder or in a folder under the logs folder.

If you do not want/need to log to a separate log file you can simplify the above setup by just using slf4j. Put just these two files in WEB-INF/lib:

  1. slf4j-api
  2. slf4j-simple

You do not need a configuration file. By default slf4j-simple will log to standard out. So your B2's log messages will be written to the stdout-stderr log file in the Blackboard system.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact Blog Owner