Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
While using beanshell, if we need to log the messages (info, error, warn) properly in joget.log file, we can use the joget LogUtil api. Its a very handy feature.
// logging message - info LogUtil.info("ClassName","Message"); // logging message - warn LogUtil.warn("ClassName","Message"); // logging message - error LogUtil.error("ClassName",Exception,"Message");
Sample Code
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; import org.joget.apps.app.service.AppUtil; Class.forName("com.mysql.jdbc.Driver").newInstance(); try { con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "root", ""); if(!con.isClosed()){ String sql = "INSERT INTO table(col1,col2) VALUES(?,?)"; PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, "coffee"); ps.setString(2, "coffee"); ps.executeUpdate(); // Loggin the info message that record has been inserted LogUtil.info("","("+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 refer here also