logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xinjian Xue <xinjian....@peregrine.com>
Subject RE: How to use SMTPAppender
Date Thu, 13 Jun 2002 14:53:40 GMT
Prblem solved. I forgot to call sa.activateOptions();
I have added thisi line in the code.

-------------------------------------------------------------
Xinjian Jack Xue, Phone: 317 554 7622


-----Original Message-----
From: Xinjian Xue [mailto:xinjian.xue@peregrine.com]
Sent: Thursday, June 13, 2002 9:33 AM
To: log4j-dev@jakarta.apache.org; log4j-user@jakarta.apache.org
Subject: How to use SMTPAppender


Hi,
This is my first time to try the SMTPAppender. BY running the following
code, I got all logs in a file. But no email and an error message pops up:
log4j:ERROR Message object not configured.
What that means? Thanks.
Yours Jack
 
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
import org.apache.log4j.net.*;
 
import java.util.*;
 
public class SmtpTest {
 
  static Category cat = Category.getInstance(SmtpTest.class.getName());
  
  public static void main(String[] args) throws java.io.IOException
  {
    
    PatternLayout pl = new PatternLayout("%d %-5p %x [%t] %c{9} - %m%n");
    FileAppender fa = new FileAppender((Layout) pl, "smtptest.log", true);
    SMTPAppender sa = new SMTPAppender();
    sa.setSMTPHost("mozart");
    sa.setFrom(" Log4J@peregrine.com <mailto:Log4J@peregrine.com> ");
    sa.setTo(" jack.xue@peregrine.com <mailto:jack.xue@peregrine.com> ");
    sa.setSubject("Test email");
    sa.setBufferSize(1);
    sa.setLayout((Layout) pl);            
    sa.activateOptions();

    cat.addAppender(fa);
    cat.addAppender(sa);
 
    cat.info("Testing SMTPAppender...");
    
    cat.debug("Some debug log written here...");
    cat.error("Some error log written here...");
    cat.fatal("Some fatal log written here...");
 
    cat.info("Finished.");
    fa.close();
    sa.close();
    System.exit(0);
  }
 
}

------------------------------------------------------------- 
Xinjian Jack Xue, Phone: 317 554 7622 

 

--
To unsubscribe, e-mail:   <mailto:log4j-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-dev-help@jakarta.apache.org>


Mime
View raw message