views:

3165

answers:

5

Hi All,

I am trying to configure my Quartz scheduler to support logging. I had tried doing following:

Added log4j.xml in classes folder of my app. The code for the same is:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=
    %d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout

Added following statements in my scheduler class:

static Logger logger = Logger.getLogger("QuartzReport.class");
logger.info("Info");

However, the console displays the following message with start up:

log4j:WARN No appenders could be found for logger 
    (org.quartz.simpl.SimpleThreadPool).
log4j:WARN Please initialize the log4j system properly.

Please tell me whether I am missing somthing.

Regards, Ibu

+2  A: 

Hi,

You're missing essentialy two points:

  1. Your configuration file is a properties file, not an XML. So you should save it as 'log4j.properties';
  2. Make sure the file mentioned in the item 1 is in the application's classpath (assuming a recent log4j implementation is being used).

Good luck,

Douglas

DouglasJose
Thanks Douglas, I took care of both points. please refer to my next answer segment for detailed comments.Regards, Ibu
A: 

Also try updating your log4j config with this line

log4j.logger.org.quartz=debug, stdout

Tried adding ur code in log4j.properties.Gotthefollowing error on deployment. However, the messages in the log file are printed as they were getting before. Plzrefermynextanswer.log4j:ERROR Could not find value for key log4j.appender.stdoutlog4j:ERROR Could not instantiate appender named "stdout".
+1  A: 

Thanks for the reply, I mistyped the file name. Actually it is log4j.properties. An update regarding the issue. I managed to get my logger messages in a file using the following code in my java class:

public class QuartzReport {
  static Logger log = Logger.getLogger("QuartzReport");

  public static void main(String[] args) {
        try {
              DateFormat format3 = new SimpleDateFormat( "MM_dd_yyyy_HH_mm" );
      Date dateToday = new Date();   
      String strToday= format3.format(dateToday); 

      BasicConfigurator.configure();
      PatternLayout pattern = new PatternLayout("%r [%t] %-5p %c %x - %m%n");
      FileAppender fileappender = new FileAppender(pattern,"log\\CenoplexScheduler_"+strToday+".txt");

      log.addAppender(fileappender);
      log.info("QuartzReport; main(): [** Starting scheduler services **]");
        }
  }
}

However, the issue now I am facing is my logger is printing so much of data that I dont need.I am pasting a portion of my logger below:

7068384 [DefaultQuartzScheduler_Worker-2] INFO  QuartzReport  - SchedulerJob; execute(): [** Calling  doJob() of BackgroundProcessANIParsing **]
7068384 [DefaultQuartzScheduler_Worker-2] INFO  QuartzReport  - BackgroundProcessANIParsing; doJob(): [Background process for ANI parsing begins]
7068384 [DefaultQuartzScheduler_Worker-2] INFO  QuartzReport  - BackgroundProcessANIParsing; doJob(): [Getting all campaigns from campaign table to parse]
7068384 [DefaultQuartzScheduler_Worker-2] INFO  QuartzReport  - BackgroundProcessANIParsing; doJob(): [No campaign ANI record found to parse]
7068384 [DefaultQuartzScheduler_Worker-2] INFO  QuartzReport  - BackgroundProcessANIParsing; doJob(): [Background process for ANI parsing ends]
7128387 [DefaultQuartzScheduler_Worker-4] INFO  QuartzReport  - SchedulerJob; execute(): [** Calling  doJob() of BackgroundProcessANIParsing **]
7

Also, here is my log4j.properties file contents:

# STDOUT appender
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %p [%t] %C{1} - %m\n

# use the STDOUT appender. set the level to INFO.
log4j.category.com.devdaily.log4jdemo.Log4JDemo=INFO, STDOUT

The problem seems to be with my properties file itself.

Regards, Ibu

A: 

Hello,

You can configure you code either programatically (as in the main method of your QuartzReport class), either with a configuration file (your properties file).

Newer versions of Log4j will try to load a file named log4j.properties from you classpath and use it to configure you logger automatically.

In your case, the BasicConfigurator.configure() call will override any definitions in you properties file (i.e., you properties file is being ignored). And the output displayed by the log respects the pattern you provided in the PatternLayout constructor. More details on how to define such pattern can be found in the PatternLayout class documentation.

DouglasJose
A: 

My Qurtz schedular did not triggered one job. I am not able to trace it in my allpication log files.

Is there any log maintained by Quartz scedular internally. If yes then its location?

Also if there is an option to switch on the logging by quartz schedular then where is that option?

Thanks, Rupesh

rupesh