Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
nvtd4000
Contributor III
Contributor III

How to log request (to log file - log4j2) with tRestRequest

I am using tRestRequest for developing a webservice. I also using log4j2 for logging purpose.

How to log the the request (to log file) from client to service ?

I goto "project setting"/log4j and choose log4j2 and also update the log4j template:. But I when i check log file, i can see other information that i logged but not see incoming request.

 

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="warn">

  <Properties>

    <Property name="basePath">c:/log</Property>

  </Properties>

 

  <Appenders>

    <RollingFile name="fileLogger" fileName="${basePath}/app-info.log" filePattern="${basePath}/app-info-%d{yyyy-MM-dd}.log">

      <PatternLayout>

        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n</pattern>

      </PatternLayout>

      <Policies>

        <TimeBasedTriggeringPolicy interval="1" modulate="true" />

      </Policies>

    </RollingFile>

    <RollingFile name="rootLogger" fileName="${basePath}/root-info.log" filePattern="${basePath}/root-info-%d{yyyy-MM-dd}.log">

      <PatternLayout>

        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n</pattern>

      </PatternLayout>

      <Policies>

        <TimeBasedTriggeringPolicy interval="1" modulate="true" />

      </Policies>

    </RollingFile>

    <!-- <Console name="console" target="SYSTEM_OUT">

      <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />

    </Console> -->

  </Appenders>

  <Loggers>

    <Logger name="....job name ...." level="debug" additivity="true">

      <appender-ref ref="fileLogger" level="debug" />

    </Logger>

    <Root level="debug" additivity="false">

      <appender-ref ref="rootLogger" />

    </Root>

  </Loggers>

</Configuration>

3 Replies
Anonymous
Not applicable

I have had a play around with this scenario and it appears that the message body is not displayed in its entirety automatically. I am not sure if this is by design (for data protection) or something that needs to be investigated. I shall check. However, I have a workaround for you.

 

My example service looks like this....

 

0695b00000HsqqZAAR.pngAs you can see it is very basic. I have configured the tRestRequest component to receive POST messages. I have configured its schema to hold the POST data as a column called "body". The data I am receiving is JSON.

 

You will notice there is a tJavaFlex. You can just use a tLogRow component there, but the tJavaFlex allows you to send the log data to just your log files and not to the System.out (which the tLogRow will do). In the tJavaFlex I have the following code....

 

org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass());

logger.info(body.body);

 

I am logging as "info" here, but you can change this to whatever you wish.

 

I hope this helps.

nvtd4000
Contributor III
Contributor III
Author

Thanks. This way works. I can see the request in log file.

But I still prefer if Talend can have a patch for all tRest and tSoap (request and response) that makes them able to log request and response to log file in a beautiful format.

I am java dev. When I use cxf, there is a way to do that. But when i use Talend, i don't see that option.

Anonymous
Not applicable

I am glad it works for you. I have just finished submitting this as a bug for our R&D to resolve.