• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can we pass a parameter to log4j..?

 
SirishKumar Nukkala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai guys..

Comming to the point.I've got a major problem in log4j i.e to send a parameter to log4j so that it could generate random files( Using file appender ).

My problem is : -

I've got a user of id 47.He sends a file "Blah.xls".The file tracking Id for that ("Blah.xls") file is "EFG123".So, inorder to track the file status i need to log a log file using log4j ("I'm thinking like to create a new log file using file appender") like user-id_file-Tracking-ID.log.

Similarly for another user of id 48 I need to create a different log with his user-id and file-Tracking-ID("randomly generated - don't bother").

So,can i pass any parameter to log4j.xml and create logs dynamically instead of using java code.

I'm pasting the java as well as log4j.xml.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss.SSS} %m%n "/>
</layout>
</appender>

<appender name="fileAppender1" class="org.apache.log4j.FileAppender">
<param name="File" value="${i}\info.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%r %m%n "/>
</layout>
</appender>

<root>
<priority value ="debug" />
<appender-ref ref="ConsoleAppender"/>
</root>

</log4j:configuration>

Can i pass parameter in ${i} through java.

Can any one please find the solution for my problem.

Your helpness will be appreciated
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please do not post the same question to multiple forums, and take care to post in a forum that's relevant to the question (log4j ha snothing to do with Web services): CarefullyChooseOneForum

Let's continue the discussion in this duplicate thread, where you have an answer already.
 
SirishKumar Nukkala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops..!

I'm sorry.I don't know these things.

Thanks for u'r advice Satou kurinosuke
 
SirishKumar Nukkala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry once again Ulf Dittmer.

Misspelled u'r name ..


Bye..!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!