0

I have a Java JAR and a shell script which is using Log4j configured as below.

log4j.rootLogger=ERROR, file
log4j.logger.com.mypackage.pack=INFO
log4j.logger.PERFS=OFF

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=C:\TEMP\LogFolder\mylog.log
log4j.appender.file.append=true

log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n %M:%L

I migrated it to Log4j2 as below

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Appenders>
    <File name="A1" fileName="C:\TEMP\LogFolder\mylog.log" >
      <PatternLayout pattern="%t %-5p %c{2} - %m%n"/>
    </File>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n %M:%L"/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="org.apache.log4j.xml" level="info">
      <AppenderRef ref="A1"/>
    </Logger>
    <Root level="info">
      <AppenderRef ref="STDOUT"/>
    </Root>
  </Loggers>
</Configuration>

my shell script as below :

"$JAVA_HOME/bin/java" -Dlog4j.debug=true -Xmx256m -Xms64m -Dcom.mypackage.pack.conf=${myprog}/myconf.properties -Dlog4j.configuration=file:/${myprog}/log4jConf.xml   -cp ${myprog}/myjar-SNAPSHOT.jar com.mypackage.pack.MyJavaClass  ${paramjava} $@ >> $FicTrac  2>&1
Heu=`date +%H:%M:%S`
echo " " >> $FicTrac
echo " " >> $FicTrac

When I execute my shell script, I can't see the log file in this location: C:\LogFolder\mylog.log

how can i solve it ?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
lulu3131
  • 25
  • 9
  • Does this answer your question? [logback how to set destination folder for log files](https://stackoverflow.com/questions/27764071/logback-how-to-set-destination-folder-for-log-files) – Nora Na Nov 03 '21 at 10:20
  • You configured the Log4j 2.x logger to log to the console appender, instead of the file appender. – Piotr P. Karwasz Nov 04 '21 at 04:09
  • Hi @PiotrP.Karwasz , can you explain me with how can i configure file appender instead of console appender by example please – lulu3131 Nov 04 '21 at 09:55
  • hi @NoraNa , i use log4j2 and not logback. I want to send my log file to the specific folder as below my xml configuration – lulu3131 Nov 04 '21 at 09:57
  • @lulu3131: in your Log4j2 file you have ``. What you probably meant is ``, which corresponds exactly to `log4j.rootLogger=ERROR, file`. – Piotr P. Karwasz Nov 04 '21 at 11:09
  • @PiotrP.Karwasz, I do , but i doesn't get my log file in the folder, how can i do else ? – lulu3131 Nov 04 '21 at 13:12
  • Log4j 2 uses `log4j2.debug` instead of `log4j.debug` and `log4j.configurationFile` instead of `log4j.configuration` (see [this question](https://stackoverflow.com/q/69392539/11748454)). Correct them in your shell script. – Piotr P. Karwasz Nov 04 '21 at 14:32

0 Answers0