1 Reply Latest reply on Jan 7, 2008 9:10 PM by 807601

    use syslog with log4j


      I need to know how to configure and use log4j, to send log messages to a syslog daemon.

      I have read documentation but there is only a few examples to console. I will appreciate a resource or example to achieve this.

        • 1. Re: use syslog with log4j

          Here is a small template for an instance of log4j, and should be enough to get you started:
          import org.apache.log4j.*;
          public class Main {
              static Logger logger = Logger.getLogger(Main.class);
              public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
                  PatternLayout layout = new PatternLayout("%d %-5p %c - %m%n");
                  FileAppender appender = new FileAppender(layout, "./logs/output.html", true);
                  logger.setLevel((Level) Level.DEBUG);
          To use the logger in other classes, this line must be included:
          static Logger logger = Logger.getLogger(myproj.Main.class);
          That should get you started, as for appending to console, looking up documentation for org.apache.log4j.ConsoleAppender and
          org.apache.log4j.net.SyslogAppender will be helpful.