Need help in log4j configuration file

Discussions

Web tier: servlets, JSP, Web frameworks: Need help in log4j configuration file

  1. Need help in log4j configuration file (3 messages)

    Hello guys,
      I am using log4j for my web tier log system and feedback. I have this appender

        <appender name="EMAIL" class="org.apache.log4j.net.SMTPAppender">
            <param name="BufferSize" value="1" />
            <param name="From" value="admin at commercehub dot com" />
            <param name="To" value="hpathak at commercehub dot com" />
            <param name="Subject" value="Feedback" />
            <param name="SMTPHost" value="mail.commercehub.com" />
            <param name="LocationInfo" value="true" />
            <param name="EvaluatorClass" value="com.commercehub.log.CtiEmailEvaluator" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                       value="%d %p (%F:%L) - %m%n"/>
            </layout>
        </appender>

    Now for the parameter "Subject" I want to change its value dynamically. Right now for emails I get subject line "Feedback". I want some dynamic value to add to subject line... so it will be "Feedback -- abcdzyx".

    Is that possible ?? Can I change its value dynamically ?

    Please somebody help me.. thanks.
  2. import com.commercehub.log.CtiEmailEvaluator;

          Logger _logger = Logger.getRootLogger();
          _logger.removeAllAppenders();

          CtiEmailEvaluator _eval = new CtiEmailEvaluator();
          
          SMTPAppender _smtp = new SMTPAppender(_eval);
          _eval.setSMTPAppender(_smtp);
          _smtp.setFrom("admin at commercehub dot com");
          _smtp.setTo("hpathak at commercehub dot com");
          _smtp.setSMTPHost("mail.commercehub.com");
          _smtp.setSubject("Feedback");
          _smtp.setLayout(new SimpleLayout()); //here use your PatternLayout
          _smtp.activateOptions();

          _logger.addAppender(_smtp);
          _logger.setLevel(Level.DEBUG);
          _logger.error("error");
          _logger.warn("warning");
          _logger.error("error");
  3. Or just:

          import com.commercehub.log.CtiEmailEvaluator;

          Logger _logger = Logger.getRootLogger();
          SMTPAppender _smtp =
              (SMTPAppender) _logger.getAppender("EMAIL");

          _smtp.setSubject("Feedback");
          _smtp.activateOptions();

          _logger.removeAppender("EMAIL");
          _logger.addAppender(_smtp);
  4. Its working great[ Go to top ]

    Thanks a lot.. Its working great.