private void handleWriter(final LogEvent event, CachedWriter writer) throws IOException {
   boolean isTruncated = writer.size() > limit && limit != -1;
   StringBuilder payload = new StringBuilder();
   writer.writeCacheTo(payload, limit);
   event.setPayload(payload.toString());
   event.setTruncated(isTruncated);
   event.setFullContentFile(writer.getTempFile());
 }
 private void handleOutputStream(final LogEvent event, Message message, CachedOutputStream cos)
     throws IOException {
   String encoding = (String) message.get(Message.ENCODING);
   if (StringUtils.isEmpty(encoding)) {
     encoding = "UTF-8";
   }
   StringBuilder payload = new StringBuilder();
   cos.writeCacheTo(payload, encoding, limit);
   cos.close();
   event.setPayload(payload.toString());
   boolean isTruncated = cos.size() > limit && limit != -1;
   event.setTruncated(isTruncated);
   event.setFullContentFile(cos.getTempFile());
 }
예제 #3
0
 public void close() throws IOException {
   final LogEvent event = new DefaultLogEventMapper().map(message);
   StringWriter w2 = out2;
   if (w2 == null) {
     w2 = (StringWriter) out;
   }
   String ct = (String) message.get(Message.CONTENT_TYPE);
   StringBuilder payload = new StringBuilder();
   try {
     writePayload(payload, w2, ct);
   } catch (Exception ex) {
     // ignore
   }
   event.setPayload(payload.toString());
   sender.send(event);
   message.setContent(Writer.class, out);
   super.close();
 }
예제 #4
0
    public void onClose(CachedOutputStream cos) {
      final LogEvent event = new DefaultLogEventMapper().map(message);
      try {
        String encoding = (String) message.get(Message.ENCODING);
        StringBuilder payload = new StringBuilder();
        writePayload(payload, cos, encoding, event.getContentType());
        event.setPayload(payload.toString());
      } catch (Exception ex) {
        // ignore
      }

      sender.send(event);
      try {
        // empty out the cache
        cos.lockOutputStream();
        cos.resetOut(null, false);
      } catch (Exception ex) {
        // ignore
      }
      message.setContent(OutputStream.class, origStream);
    }