how to do log4j properties file as a common file for all modules in java

Hi Experts,
I have 10 modules in my project.
Each module having separate log4j properties file
log4j properties file name along with path configured context params of web.xml file

Log level:
info ,debug,trace

any specific module i want to see all the logs i can change log level to trace
log4j.rootLogger=TRACE, stdout, file
then i can able to see all the logs.

instead of creating 10 or 15 log4j properties file names
i want to make a common log4j.properties file
then i want to see all the logs
is it possible?
if it is possible i have a problem here
now i want to see a specific module log level upto trace
trace will print all the logs like info,debug,trace if it prints all the logs
and my log file size going upto max size level immediately.

here i need a solutiion like from the common log4j properties file
for specific if i want to print trace i have get trace level logs only for specific module
rest of the modules has to show info level.

some one can suggest me how to do
Thanks,
LVL 2
srikoteshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
theres no reason why you cannot have a single log4j file.
If all the modules are deployed together, the log4j file just needs to be on the classpath.


And then in the log4j.properties file put something like
log4j.logger.com.myproject.mymodule1=trace

where com.myproject.mymodule1 is the package for a particular module.
0
CEHJCommented:
I have 10 modules in my project.

Java doesn't (yet) support 'modules'. What do you mean by that?
0
gurpsbassiCommented:
intellij modules perhaps.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

srikoteshAuthor Commented:
hi gurpbassi,

how to can i provide project name ?
module name means i can add war name as module name.
some where i have to configure these module name and project name right.

hi cehj,
Consider i have 10 wars in my tomcat webapps.
0
gurpsbassiCommented:
If they are 10 different wars i.e 10 different projects then I would configure the logging at the application server and not try to bundle log4j.properties in your deployables.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
some where i have to configure these module name and project name right.

What gurpsbassi was talking about with log4j.logger.com.myproject.mymodule1=trace, that "myproject" and "mymodule" are just components of the package name. So the example he gave is assuming all the code for one of the modules has the Java package name "com.myproject.mymodule1" (or some sub-package of that) and that the code in the other modules have different package names.

You do have a good package name hierarchy, don't you? One that would make it easy to differentiate the code in the different modules?
0
CEHJCommented:
What is your motivation?
0
srikoteshAuthor Commented:
Hi CEHJ,

I Want to see all the logs in single log file.
I Want to restrict the log level whenever i want, i mean to see info or debug or trace.

Hi gurpsbassi,
I am using Tomcat server in which file we can see the log restriction.
logging.properties file is the one to modify the log levels?
0
gurpsbassiCommented:
I Want to see all the logs in single log file.

Do you really think that is wise?

You are going to end up with a big log file with logging from a mixture of apps, with log statements interleaving.
It will end up being a nightmare to try and troubleshoot the application.
0
CEHJCommented:
I Want to see all the logs in single log file.
That could easily be achieved with a shell script, without interleaving everything.
0
srikoteshAuthor Commented:
yes gurpsbassi you are correct making all applications into single log file will be difficult for trouble shooting.
0
srikoteshAuthor Commented:
Hi Cehj,

can you explain how to achieve single log file thru shell script.
0
CEHJCommented:
#!/bin/bash
ROOT=$CATALINA_HOME/apps
OUTPUT_FILE=onelog.log
find $ROOT -type f -name log4j.log -exec cat '{}' >>$OUTPUT_FILE \;

Open in new window


should do it
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.