public void setConfiguration(Configuration cfg) throws ConfigurationException {
   timeout = cfg.getInt("timeout");
   if (pool == null) pool = new ThreadPool(1, cfg.getInt("poolsize", 10));
   muxName = cfg.get("destination-mux", null);
   channelName = cfg.get("destination-channel", null);
   delay = cfg.get("delay", "0");
   if (muxName == null && channelName == null) {
     throw new ConfigurationException("Neither destination mux nor channel were specified.");
   }
 }
示例#2
0
 public void setConfiguration(Configuration cfg) throws ConfigurationException {
   this.cfg = cfg;
   try {
     socket = new DatagramSocket();
     port = cfg.getInt("port", SYSLOG_PORT);
     host = InetAddress.getByName(cfg.get("host", "localhost"));
     defaultFacility = cfg.getInt("facility", LOG_USER);
     defaultSeverity = cfg.getInt("severity", PRI_INFO);
     tags = cfg.get("tags", "audit, syslog");
     prefix = cfg.get("prefix", null);
   } catch (Exception e) {
     throw new ConfigurationException(e);
   }
 }
示例#3
0
  /**
   * Configure this RotateLogListener<br>
   * Properties:<br>
   *
   * <ul>
   *   <li>file base log filename
   *   <li>[window] in seconds (default 0 - never rotate)
   *   <li>[count] number of copies (default 0 == single copy)
   *   <li>[maxsize] max log size in bytes (aprox)
   * </ul>
   *
   * @param cfg Configuration
   * @throws ConfigurationException
   */
  public void setConfiguration(Configuration cfg) throws ConfigurationException {
    maxCopies = cfg.getInt("copies");
    sleepTime = cfg.getInt("window") * 1000;
    logName = cfg.get("file");
    maxSize = cfg.getLong("maxsize");
    maxSize = maxSize <= 0 ? DEFAULT_MAXSIZE : maxSize;

    try {
      openLogFile();
    } catch (IOException e) {
      throw new ConfigurationException(e);
    }
    Timer timer = DefaultTimer.getTimer();
    if (sleepTime != 0) timer.schedule(rotate = new Rotate(), sleepTime, sleepTime);
  }
示例#4
0
  public synchronized LogEvent log(LogEvent ev) {
    if (socket != null && ev.getTag() != null && tags.contains(ev.getTag())) {
      int facility = cfg.getInt(ev.getTag() + ".facility", defaultFacility);
      int severity = cfg.getInt(ev.getTag() + ".severity", defaultSeverity);
      int priority = (facility << 3) | severity;

      StringBuilder sb = new StringBuilder();
      sb.append('<');
      sb.append(Integer.toString(priority));
      sb.append('>');
      if (prefix != null) {
        sb.append(prefix);
        sb.append(' ');
      }
      sb.append(ev.getRealm());
      sb.append(' ');
      sb.append(ev.getTag());
      sb.append(" - ");
      synchronized (ev.getPayLoad()) {
        Iterator iter = ev.getPayLoad().iterator();
        for (int i = 0; iter.hasNext(); i++) {
          if (i > 0) sb.append(' ');
          sb.append(iter.next().toString());
        }
      }
      byte[] b = sb.toString().getBytes();
      DatagramPacket packet = new DatagramPacket(b, Math.min(b.length, 1024), host, port);
      try {
        socket.send(packet);
      } catch (IOException e) {
        ev.addMessage("--- SysLogListener error ---");
        ev.addMessage(e);
      }
    }
    return ev;
  }