log messages aren't getting logged to the file when running via shell script

One Star

log messages aren't getting logged to the file when running via shell script

When I am running the Talend job from the open studio, it is creating a log files and printing the logger in the same. But when I build the job and execute the shell file, it doesn't create the log file. Following is the content of the log file -

 

    

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' >

<!--  CONSOLE appender  -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"  
            value="[%-5p]: %c - %m%n" />
    </layout>
</appender>

<!-- logstash appender -->
<!-- <appender name="LOGSTASH" class="org.apache.log4j.net.SocketAppender">
    <param name="RemoteHost" value="localhost"/>
    <param name="Port" value="8052"/>
</appender> -->

<appender name="APPENDER2" class="org.apache.log4j.DailyRollingFileAppender">
   <param name="File" value="D:\softwares\TOS_BD-20170510_1410-V6.4.0\workspace\logs\customlogs.txt" />
    <param name="MaxFileSize" value="1024KB"/>
    <param name="DatePattern" value="'.'yyyy_MM_dd_HH_mm"/>
   <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
   </layout>
</appender>

<logger name="m2c.entity_filter_copy_0_1">  
    <level value="debug" />  
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="APPENDER2"/>
</logger>

<!-- throwableRenderer <throwableRenderer class="org.apache.log4j.EnhancedThrowableRenderer"/>--> 

<!-- Root Logger -->  
<!--    <root>
    <priority value ="debug"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="APPENDER2"/>
     <appender-ref ref="LOGSTASH"/> 
  </root>-->
  </log4j:configuration> 

I have added DailyRollingFileAppender. And following is the content of the shell script -

 

    

#!/bin/sh
cd `dirname $0`

ROOT_PATH=`pwd` java -Dlog4jEnabled=true -Xms1024M -Xmx2048M -cp
.:$ROOT_PATH:$ROOT_PATH/../lib/routines.jar:$ROOT_PATH/../lib/advancedPersistentLookupLib-1.0.jar:$ROOT_PATH/../lib/cassandra-driver-core-3.0.0.jar:$ROOT_PATH/../lib/commons-collections-3.2.2.jar:$ROOT_PATH/../lib/dom4j-1.6.1.jar:$ROOT_PATH/../lib/guava-16.0.1.jar:$ROOT_PATH/../lib/jboss-serialization.jar:$ROOT_PATH/../lib/log4j-1.2.15.jar:$ROOT_PATH/../lib/log4j-1.2.16.jar:$ROOT_PATH/../lib/metrics-core-3.1.2.jar:$ROOT_PATH/../lib/mysql-connector-java-5.1.30-bin.jar:$ROOT_PATH/../lib/netty-buffer-4.0.33.Final.jar:$ROOT_PATH/../lib/netty-codec-4.0.33.Final.jar:$ROOT_PATH/../lib/netty-common-4.0.33.Final.jar:$ROOT_PATH/../lib/netty-handler-4.0.33.Final.jar:$ROOT_PATH/../lib/netty-transport-4.0.33.Final.jar:$ROOT_PATH/../lib/slf4j-api-1.7.7.jar:$ROOT_PATH/../lib/talend-cassandra-1.1.jar:$ROOT_PATH/../lib/talendcsv.jar:$ROOT_PATH/../lib/trove.jar:$ROOT_PATH/entity_filter_copy_0_1.jar:
m2c.entity_filter_copy_0_1.entity_filter_Copy --context=Default "$@"

I read somewhere that I need to pass -Dlog4jEnabled=true in the command line to enable log4j, but that didn't work. Does anyone know how to get this done?

 

Eight Stars

Re: log messages aren't getting logged to the file when running via shell script

Is your log4j.xml file present in same location as your main job jar file?

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.