Reputation: 1
I am using log4j for the first time. According to a requirement, i want to display the name of the file in the log (same way as date is displayed) in the log file.
for example:
17:56:57,863 help INFO [STDOUT] PropertyHandler-If
where help
us the name of the file where PropertyHandler-If
is written in log.debug()
.
Also, I want different log file for all the exceptions pertaining to database. Is that possible?
Upvotes: 0
Views: 1220
Reputation: 8245
You can use the PatternLayout with the 'F' option: "Used to output the file name where the logging request was issued."
As @Peter Lawrey points out, you can use multiple appenders, in your case a specific FileAppender that logs for the database.
Upvotes: 1
Reputation: 533492
You can define multiple appenders (one for each file) and set different loggers to use different appenders. By using different Log objects, you have direct these to different files. e.g. a single component can have multiple Log
s
Upvotes: 1