0

Using Log4j iam trying to write logged in user level logs.

suppose using 'X' user i logged in to a machine, i need to get the user name in Log4J properties file. So, i can write my logs to : /Desktop/X/final.log
similarly, if Y user then it should write to : /Desktop/Y/final.log

i tried using ${user} but not working.

log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=/Desktop/${user}/final.log

Any help is appreciated !

Raj
  • 537
  • 4
  • 9
  • 18

1 Answers1

0

A way of doing this is by injecting a system property in the program that uses log4j. For example if you're running some java program you can pass in the user property with -Duser=<your_user>.

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/Desktop/${user}/final.log

Even better, you could parametrize the whole log filename if you want. There's a similar question with a detailed answer here.

Community
  • 1
  • 1
Andrei T.
  • 2,455
  • 1
  • 13
  • 28