Managing Log Files

Logs are essential in efficiently managing and maintaining applications in Joget. They provide a real-time record of events in chronological order, which helps developers and administrators understand the behavior of applications, diagnose errors, and ensure optimal performance. Analyzing log files is the best way to trace the root cause of issues that may not be apparent through direct observation of the application's operation. This is particularly useful when multiple applications and plugins interact dynamically in an environment.

The following sections will describe good practices when managing your log files.

Write to the correct log

To write into the log files correctly, use the LogUtil utility class, as in the following example:

LogUtil.info(EmailTool.class.getName(), "EmailTool: Sending email from=" + email.getFromAddress().toString() + ", to=" + to + "cc=" + cc + ", bcc=" + bcc + ", subject=" + email.getSubject());
LogUtil.info(EmailTool.class.getName(), "EmailTool: Sending email completed for subject=" + email.getSubject());
LogUtil.error(EmailTool.class.getName(), ex, "");

You can check out some code samples used in their Email Tool.

Do not use the following to print out logs.
System.out.println("Execution is successful");

This line of message would appear in catalina.out but not in Joget's default log file joget.log.

Separate log files by origin

A log file named email.log as Email Tool and related plugins are written into this specific file by default. You can consider this approach to break down the number of lines written into a single log file for better troubleshooting.

Navigate to the [JogetFolder]\apache-tomcat-8.5.72\webapps\jw\WEB-INF\classes\log4j2.xml configuration file and check out the use of EMAIL rolling files to see how EmailToolUserNotificationAuditTrail, and ExportFormEmailTool are written into the email.log file, as In the example below.

<RollingFile
    name="EMAIL"
    fileName="${LOGDIR}/email.log"
    filePattern="${LOGDIR}/email.log.%d{yyyyMMdd}.gz"
    ignoreExceptions="false">
    <PatternLayout>
        <Pattern>%-5p %d{dd MMM yyyy HH:mm:ss} %-50c - %m%throwable{0}%n</Pattern>
    </PatternLayout>
    <Policies>
        <OnStartupTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="10MB" />
        <TimeBasedTriggeringPolicy interval="1"/>
    </Policies>
    <DefaultRolloverStrategy max="5" />
</RollingFile>  
 
 
<!-- Email log file -->
<Logger name="org.joget.apps.app.lib.EmailTool" level="debug" additivity="true">
    <AppenderRef ref="EMAIL"/>
</Logger>
<Logger name="org.joget.apps.app.lib.UserNotificationAuditTrail" level="debug" additivity="true">
    <AppenderRef ref="EMAIL"/>
</Logger>
<Logger name="org.joget.plugin.enterprise.ExportFormEmailTool" level="debug" additivity="true">
    <AppenderRef ref="EMAIL"/>
</Logger>

Identify app origin in log files

When too many apps run in the same copy of Joget, sometimes it traces certain lines of messages to the origin of Joget apps that trigger them. See the following example:

ERROR 17 Jun 2019 17:29:39 org.joget.apps.app.lib.EmailTool  - org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.outlook.comtest:587
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.outlook.comtest:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
    at org.apache.commons.mail.Email.send(Email.java:1448)
    at org.joget.apps.app.lib.EmailTool$1.run(EmailTool.java:239)
    at java.lang.Thread.run(Thread.java:748)
    at org.joget.commons.util.PluginThread.run(PluginThread.java:22)

There is no way to tell from which Joget app the EmailTool is triggered. However, you can obtain the appDef object containing the Joget app information using the execute method of a Process Tool. See the following example:

public Object execute(Map properties) {
     
    AppDefinition appDef = (AppDefinition) properties.get("appDef");
    String appInfoAndMessage = appDef.toString() + "- Something happened";
    LogUtil.error(EmailTool.class.getName(), ex, appInfoAndMessage);
     
}

This way, you can trace to the app that triggers and write the message line in the log file.

The appDef object is available in the following types of plugins.

  • Form Post Submission Processing Tool
  • Process Tool

You can obtain the appDef object in other plugin types using the following code.

import org.joget.apps.app.service.AppUtil;
 
AppDefinition appDef = AppUtil.getCurrentAppDefinition();

Large catalina.out File

For large catalina.out files, you can consider to LogRotate the log files. See the following for more details:

As for joget.log, it already uses Log4J for rotation, as seen in the log4j.properties file snippet in the Separate log files by origin section.

Created by Marcos Last modified by Aadrian on Dec 13, 2024