Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Chinese

Pagetitle
管理日志文件
管理日志文件

Table of Contents

Writing to the Correct Log

Chinese

写入正确的日志

Let's start with the basics first. In order to write into the log files correctly, we should make use of the LogUtil (Source code: https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-commons/src/main/java/org/joget/commons/util/LogUtil.java) utility class.

We should not use the following to print out log in writing our own plugins.

Chinese

让我们先从基础开始。为了正确写入日志文件,我们应该使用LogUtil (源代码: https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-commons/src/main/java/org/joget/commons/util/LogUtil.java)实用程序类。


在编写我们自己的插件时,我们不应使用以下内容打印日志。

Code Block
linenumberstrue
System.out.println("Execution is successful");

...

Instead, we should make use of these methods provided by LogUtil. Check out the some sample in the codes used by Email Tool (Source code: https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/app/lib/EmailTool.java#L227)

Chinese

这是因为此消息行将出现在catalina.out中,而不出现在默认的Joget日志文件joget.log中。

相反,我们应该利用LogUtil提供的这些方法。在Email Tool使用的代码中查看一些示例 (源代码: https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/app/lib/EmailTool.java#L227)

Code Block
linenumberstrue
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, "");

Separate Logs of Different Origin/Plugins into Different Log Files

Chinese

将不同来源/插件的日志分为不同的日志文件

You may have already noticed that by default, we have log file named as email.log as Email Tool and related plugins are writing into this specific file. We may also consider this approach in breaking down the number of lines being written into a single log file for better troubleshooting.

Navigate to the "[JogetFolder]\apache-tomcat-8.5.23\webapps\jw\WEB-INF\classes\log4j.properties" configuration file and check out the use of R2 tag to see how EmailTool, UserNotificationAuditTrail, and ExportFormEmailTool are writing into email.log file.

Chinese

您可能已经注意到默认情况下,由于电子邮件工具和相关插件正在写入此特定文件,因此我们将日志文件命名为email.log。我们还可以考虑使用这种方法来分解写入单个日志文件的行数,以更好地进行故障排除。

导航到“ [JogetFolder] \ apache-tomcat-8.5.23 \ webapps \ jw \ WEB-INF \ classes \ log4j.properties”配置文件,并检查R2标签的使用,以了解EmailToolUserNotificationAuditTrailExportFormEmailTool如何写入email.log文件。



Code Block
titlelog4j.properties
linenumberstrue
log4j.logger.org.joget.apps.app.lib.EmailTool=DEBUG, R2
log4j.logger.org.joget.apps.app.lib.UserNotificationAuditTrail=DEBUG, R2
log4j.logger.org.joget.plugin.enterprise.ExportFormEmailTool=DEBUG, R2

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p %d{dd MMM yyyy HH:mm:ss} %c %x - %m%n

# R is set to be DailyRollingFileAppender
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/joget.log
log4j.appender.R.DatePattern='.'yyyyMMdd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-5p %d{dd MMM yyyy HH:mm:ss} %c %x - %m%n

# R2 is set to be DailyRollingFileAppender
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=${catalina.home}/logs/email.log
log4j.appender.R2.DatePattern='.'yyyyMMdd
log4j.appender.R2.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.R2.layout.ConversionPattern=%-5p %d{dd MMM yyyy HH:mm:ss} %-50c - %m%throwable{0}%n


Identifying App Origin in Log Files

Chinese

在日志文件中识别应用程序来源

In the section above, we talked about using LogUtil to write into the log files and how to write into separate files too. When we have too many apps running in the same copy of Joget, sometimes it is trace certain line of messages to the origin of Joget apps that trigger them.

For example, let's look at these log messages.

Chinese

在上一节中,我们讨论了使用LogUtil写入日志文件以及如何写入单独的文件。当我们在同一个Joget副本中运行太多应用程序时,有时会将某些消息行追溯到触发它们的Joget应用程序的来源。

例如,让我们看一下这些日志消息。

Code Block
titleSample log messages
linenumberstrue
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 that we can tell from which Joget app the EmailTool is triggered. However, in a Process Tool's execute method, we can obtain the appDef object which contains the Joget app information. Check out the sample code below.

Chinese

我们无法确定从哪个Joget应用程序触发了EmailTool。但是,在Process Tool的execute方法中,我们可以获得包含Joget应用程序信息的appDef对象。

查看下面的示例代码。

Code Block
languagejava
linenumberstrue
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, we would be able to trace to the app that triggers and writes the line of message in the log file.

Chinese

这样,我们将能够跟踪到触发并在日志文件中写入消息行的应用程序。

Info
titleWhere / How to obtain App Definition?

The object "appDef" is available in the following type of plugins.

Chinese

以下类型的插件中提供了对象“ appDef”。

  • Form Post Submission Processing Tool

  • Process Tool

In other plugin types, we can try to obtain the App Definition object by using the following codes.

Chinese
在其他插件类型中,我们可以尝试使用以下代码来获取App Definition对象。
Code Block
linenumberstrue
import org.joget.apps.app.service.AppUtil;

AppDefinition appDef = AppUtil.getCurrentAppDefinition();


Large catalina.out File

Chinese

大catalina.out文件

We can consider to LogRotate the log files. Please see the following links:-

Chinese

我们可以考虑对日志文件进行LogRotate。请查看以下链接:

As for joget.log, we are already using Log4J for rotation as seen in the log4j.properties file snippet above.

Chinese

至于joget.log,我们已经使用Log4J进行旋转了,如上面的log4j.properties文件片段所示。