There are two methods.
1. The method that uses the filter function of LogBack
2. The method that uses the beginning of logger name as a login group name
The above methods can be used in WebPlatform Ver7.0 and later.
【Method 1】The method that uses the filter function of LogBack
This method uses the filter function of LogBack and the library of Janino, which come with WebPlatform Ver7.0 and later.
In short, the filter function of LogBack is a mechanism that changes the log output method based on some value.
Reference URL
http://logback.qos.ch/manual/filters.html
The following illustrates a simple example.
Refer to the attached file as well.
●Preparation
(1) Copy the log configuration file by the login group.
conf/log/login_group_for_default_logger.xml
conf/log/login_group_for_hoge_logger.xml
*The attached file is created for both “default” and “hoge” login groups.
Change the content appropriately.
(2) Copy the class of ServletFilter.
doc/imart/WEB-INF/classes/sample/MDCTestFilter.java
(3) Editing web.xml
Map the above ServletFilter onto all URLs.
web.xml setting example
<web-app>
・
・
・
<filter>
<filter-name>MDCTestFilter</filter-name>
<filter-class>sample.MDCTestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MDCTestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
・
・
・
<web-app>
(4) Download Janino from the following site and copy the library, “janino.jar,” to the following directory after decompression of Janino.
Directory <%im_path%>/lib/
Note that we confirm the operation of Janino Ver2.5.15.
https://janino-compiler.github.io/janino/ (English)
(5) Set <%im_path%>/conf/imart.xml as follows.
//----
<compiler>
<class>
<archive>
<file/>
</archive>
</class>
</compiler>
・・・
//----
//----
<compiler>
<class>
<archive>
<file/>
<directory>lib</directory>
</archive>
</class>
</compiler>
・・・
//----
---------------------
Description
---------------------
1. Through ServletFilter, “MDCTestFilter,” a login group id is set to MDC.
2. Through judgement of the login group set in the MDC, log output is judged.
(The above applies to the fifth line in login_group_for_default_logger.xml.)
By implementation based on the above sample, the filter function of LogBack can be set.
For details on the filter function of LogBack, refer to the following URL.
http://logback.qos.ch/manual/filters.html
【Method 2】The method that uses the beginning of logger name as a login group name
This method determines the naming convention of logger name in the application to be created.
For example, the beginning of logger name is set as the login group name.
----
var logingGroupName = AccessSecurityManager.getSessionInfo().loginGroup;
var logger = Logger.getLogger(logingGroupName + ".foo.bar");
logger.info("message");
----
Then, set the output destination in a setting file.
For example. If a login group “default” is output to another file, set a logger in a setting file as follows.
----
・
・
・
1: <logger name="default" additivity="false">
2: <level value="info" />
3: <appender-ref ref="LOGIN_GROUP_DEFAULT_FILE" />
4: </logger>
・
・
・
----
Next, define the appender of “LOGIN_GROUP_DEFAULT_FILE” specified in the third line of the above, and specify the output destination within the Appender.
Note that an output destination is changed in the same way as the above for a particular usage log of intra-mart (including a request.log).
In short, a particular naming convention is established, and an output destination is changed.
In order to grasp the concept, refer to conf/im_logger_request.xml as well.
-- Target ------------------------------------------------------------------------
iWP/Web System Construction Platform/WebPlatform/AppFramework
--------------------------------------------------------------------------------
FAQID:325