Join us on May 14-15, 2019 at Forrester Digital Transformation & Innovation 2019 in Chicago, USA.

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

While using BeanShell, if we need to log the messages (info, error, warning) properly in joget.log file, we can use the joget LogUtil api. It is a very handy feature.

Code Block
// logging message - info"ClassName","Message");

// logging message - warn

// logging message - error

Sample Code

Code Block
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;
import org.joget.commons.util.LogUtil;

try {
    con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "root", "");
        String sql = "INSERT INTO table(col1,col2) VALUES(?,?)";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1, "coffee");
        ps.setString(2, "coffee");
        // Loggin the info message that record has been inserted"","("+AppUtil.getCurrentAppDefinition().getAppId()+") - Record Insert Successfully.");
    } else {
       // Loggin the warning message the cant connect to database
        LogUtil.warn("","("+AppUtil.getCurrentAppDefinition().getAppId()+") - Datebase connection is not open");
} catch (InstantiationException ex) {
    LogUtil.error("",ex,"("+AppUtil.getCurrentAppDefinition().getAppId()+") - can not create the instance of database driver.");
} catch (IllegalAccessException ex) {
    LogUtil.error("",ex,"("+AppUtil.getCurrentAppDefinition().getAppId()+") - IllegalAccessException OR Custom Exception message");
} catch (ClassNotFoundException ex) {
    LogUtil.error("",ex,"("+AppUtil.getCurrentAppDefinition().getAppId()+") - ClassNotFoundException - Database Driver not found");
} catch (SQLException ex) {
    LogUtil.error("",ex,"("+AppUtil.getCurrentAppDefinition().getAppId()+") - SQL Exception :- "+ex.toString());

You can also refer here.