0

Basically,my requirement is that I have to log application related errors(let say log.error("") to a log file in my java application.

another log statements(let say log.warn("")) to SMTP mail server. Also the important thing is that, I have to to send email only once after the program execution completes. It should not be like for every log.warn().

I have very little knowledge on log4j.

can you please help me configure the log4j properties. I will be using SMTP server.

sample config file for this requirement exactly is really appreciated.

Thanks

mahesh
  • 1,523
  • 4
  • 23
  • 39
  • possible duplicate of : http://stackoverflow.com/questions/728295/creating-multiple-log-files-of-different-content-with-log4j – Some guy Feb 06 '14 at 08:50

1 Answers1

0

First of all you need to use a threshold for your appenders.

Please have a look at How to configure log4j to log different log levels to different files for the same logger and log different log levels to different files with log4j

Furthermore, for sending the email you can use SMTPAppender.

For some sample configs, please see : Multiple log files with log4j

And for a good tutorial, please see : http://www.tutorialspoint.com/log4j/log4j_logging_files.htm

Hope this helps.

Community
  • 1
  • 1
Gyan
  • 1,176
  • 1
  • 12
  • 26
  • Thanks, the links are showing for the same logger -> different log levels. But I want to two loggers each log to different file. – mahesh Feb 06 '14 at 18:29
  • also my main requirement is that, mail should be sent at the end of all the log statements finished and not for every log.xXX(). – mahesh Feb 06 '14 at 18:43
  • If by "the end of all log statements" you mean the end of execution of some program or function or class file, you need to have a custom log implementation. By default the logging appenders are invoked on each call. For custom behavior , you need a custom implementation. HTH – Gyan Feb 07 '14 at 05:12