示例#1
0
  /** Logs a request using the current format. */
  public void log(HttpServletRequest req, HttpServletResponse res, ServletContext application)
      throws IOException {
    // server/1kk7
    CauchoRequest cRequest = (CauchoRequest) req;
    HttpServletResponseImpl responseImpl = (HttpServletResponseImpl) res;

    AbstractHttpRequest absRequest = cRequest.getAbstractHttpRequest();
    HttpServletRequestImpl request = absRequest.getRequestFacade();
    AbstractHttpResponse response = responseImpl.getAbstractHttpResponse();

    // skip excluded urls
    if (_excludes.length > 0) {
      byte[] data = absRequest.getUriBuffer();
      int sublen = absRequest.getUriLength();

      String uri = new String(data, 0, sublen);

      for (Pattern pattern : _excludes) {
        if (pattern.matcher(uri).find()) {
          return;
        }
      }
    }

    LogBuffer logBuffer = _logWriter.allocateBuffer();

    try {
      byte[] buffer = logBuffer.getBuffer();

      int length = log(request, responseImpl, response, buffer, 0, buffer.length);

      logBuffer.setLength(length);

      _logWriter.writeBuffer(logBuffer);
      logBuffer = null;
    } finally {
      if (logBuffer != null) _logWriter.freeBuffer(logBuffer);
    }
  }
示例#2
0
  /** Closes the log, flushing the results. */
  @Override
  public void destroy() throws IOException {
    super.destroy();

    _isActive = false;

    Alarm alarm = _alarm;
    _alarm = null;

    if (alarm != null) alarm.dequeue();

    flush();

    _logWriter.close();
  }
示例#3
0
  /** Initialize the log. */
  @PostConstruct
  public void init() throws ServletException, IOException {
    _isActive = true;

    if (_alarm != null) _alarm.queue(60000);

    if (_format == null) _format = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"";

    ArrayList<Segment> segments = parseFormat(_format);

    _segments = new Segment[segments.size()];
    segments.toArray(_segments);

    if (_timeFormat == null || _timeFormat.equals("")) {
      _timeFormat = "[%d/%b/%Y:%H:%M:%S %z]";
      _timeFormatSecondOffset = 0;
      _timeFormatMinuteOffset = 0;
    }

    _logWriter.init();
    // _sharedBufferLock = _logWriter.getBufferLock();

    if (_autoFlushTime > 0 && _alarm != null) _alarm.queue(_autoFlushTime);
  }
示例#4
0
 /** Flushes the log. */
 public void flush() {
   // server/0213, 021q
   _logWriter.flush();
   _logWriter.waitForFlush(5000L);
   _logWriter.rollover();
 }
示例#5
0
 /**
  * Sets how often the log rollover will be checked.
  *
  * @param period how often the log rollover will be checked.
  */
 public void setRolloverCheckTime(long period) {
   _logWriter.setRolloverCheckPeriod(period);
 }
示例#6
0
 /**
  * Sets the log rollover period, rounded up to the nearest hour.
  *
  * @param period the new rollover period in milliseconds.
  */
 public void setRolloverPeriod(Period period) {
   _logWriter.setRolloverPeriod(period);
 }
示例#7
0
 /**
  * Sets the log rollover size, rounded up to the megabyte.
  *
  * @param size maximum size of the log file
  */
 public void setRolloverSize(Bytes bytes) {
   _logWriter.setRolloverSize(bytes);
 }
示例#8
0
 /**
  * Sets the log rollover cron
  *
  * @param cron the cron string for rollover times
  */
 public void setRolloverCron(CronType cron) {
   _logWriter.setRolloverCron(cron);
 }
示例#9
0
 /**
  * Sets the maximum number of rolled logs.
  *
  * @param count maximum count of the log file
  */
 public void setRolloverCount(int count) {
   _logWriter.setRolloverCount(count);
 }
示例#10
0
 /** Sets the archive name format */
 public void setArchiveFormat(String format) {
   _logWriter.setArchiveFormat(format);
 }
示例#11
0
  /** Sets the formatted path. */
  public void setPathFormat(String pathFormat) throws ConfigException {
    super.setPathFormat(pathFormat);

    _logWriter.setPathFormat(pathFormat);
  }
示例#12
0
  /** Sets the log path */
  public void setPath(Path path) {
    super.setPath(path);

    _logWriter.setPath(path);
  }