1 Reply Latest reply: Jan 7, 2008 3:10 PM by 807601 RSS

    use syslog with log4j

    807601
      Hi,

      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.

      Thanks.
        • 1. Re: use syslog with log4j
          807601
          Hello,

          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.addAppender(appender);
                  logger.setLevel((Level) Level.DEBUG);
          
                  logger.info("********************");
              }
          }
          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.

          -Sam