@Override
  public void eventAdded(KettleLoggingEvent event) {

    try {
      Object messageObject = event.getMessage();
      if (messageObject instanceof LogMessage) {
        boolean logToFile = false;

        if (logChannelId == null) {
          logToFile = true;
        } else {
          LogMessage message = (LogMessage) messageObject;
          // This should be fast enough cause cached.
          List<String> logChannelChildren =
              LoggingRegistry.getInstance().getLogChannelChildren(logChannelId);
          // This could be non-optimal, consider keeping the list sorted in the logging registry
          logToFile = Const.indexOfString(message.getLogChannelId(), logChannelChildren) >= 0;
        }

        if (logToFile) {
          String logText = layout.format(event);
          outputStream.write(logText.getBytes());
          outputStream.write(Const.CR.getBytes());
        }
      }
    } catch (Exception e) {
      exception =
          new KettleException("Unable to write to logging event to file '" + filename + "'", e);
    }
  }
  /**
   * Append the given message to this buffer, automatically evicting older messages until the
   * desired memory limit is achieved.
   */
  public synchronized void add(String messageText) {
    LogMessage message = new LogMessage(messageText, System.currentTimeMillis());

    usage += message.estimateHeapUsage();
    messages.add(message);
    while (usage > maxSizeBytes) {
      LogMessage removed = messages.remove();
      usage -= removed.estimateHeapUsage();
      assert usage >= 0;
    }
  }
示例#3
0
 @Override
 public void commit() throws IOException {
   synchronized (messages) {
     for (LogMessage message : messages) {
       log.info(
           "{} {} {}",
           System.currentTimeMillis(),
           message.getOperationCode(),
           message.getMessage());
     }
     messages.clear();
   }
 }
示例#4
0
 /**
  * Attach {@link java.io.OutputStream OutputStreams} to the {@link
  * com.spotify.docker.client.LogStream}.
  *
  * <p><b>Example usage:</b>
  *
  * <pre>{@code
  * dockerClient
  *     .attachContainer(containerId,
  *         AttachParameter.LOGS, AttachParameter.STDOUT,
  *         AttachParameter.STDERR, AttachParameter.STREAM)
  *     .attach(System.out, System.err);
  * }</pre>
  *
  * <p>Typically you use {@link java.io.PipedOutputStream PipedOutputStreams} connected to a {@link
  * java.io.PipedInputStream} which are read by - for example - an {@link
  * java.io.InputStreamReader} or a {@link java.util.Scanner}. For small inputs, the {@link
  * java.io.PipedOutputStream} just writes to the buffer of the {@link java.io.PipedInputStream},
  * but you actually want to read and write from separate threads, as it may deadlock the thread.
  *
  * <pre>{@code
  * final PipedInputStream stdout = new PipedInputStream();
  * final PipedInputStream stderr = new PipedInputStream();
  * final PipedOutputStream stdout_pipe = new PipedOutputStream(stdout);
  * final PipedOutputStream stderr_pipe = new PipedOutputStream(stderr);
  *
  * executor.submit(new Callable&lt;Void&gt;() {
  *   &#064;Override
  *   public Void call() throws Exception {
  *     dockerClient.attachContainer(containerId,
  *         AttachParameter.LOGS, AttachParameter.STDOUT,
  *         AttachParameter.STDERR, AttachParameter.STREAM
  *       .attach(stdout_pipe, stderr_pipe);
  *     return null;
  *   }
  * });
  *
  * try (Scanner sc_stdout = new Scanner(stdout); Scanner sc_stderr = new Scanner(stderr)) {
  *   // ... read here
  * }
  * }</pre>
  *
  * @param stdout OutputStream for the standard out.
  * @param stderr OutputStream for the standard err
  * @throws java.io.IOException if an I/O error occurs.
  * @see java.io.PipedInputStream
  * @see java.io.PipedOutputStream
  */
 public void attach(final OutputStream stdout, final OutputStream stderr) throws IOException {
   try (WritableByteChannel stdoutChannel = Channels.newChannel(stdout);
       WritableByteChannel stderrChannel = Channels.newChannel(stderr)) {
     for (LogMessage message; hasNext(); ) {
       message = next();
       switch (message.stream()) {
         case STDOUT:
           stdoutChannel.write(message.content());
           break;
         case STDERR:
           stderrChannel.write(message.content());
           break;
         case STDIN:
         default:
           break;
       }
     }
   }
 }
  @Override
  public void onLogMessage(final LogMessage message) {
    // Map LogLevel.WARN to Severity.WARNING so that we are consistent with the Severity
    // enumeration. Else, just use whatever
    // the LogLevel is (INFO and ERROR map directly and all others we will just accept as they are).
    final String bulletinLevel =
        message.getLevel() == LogLevel.WARN
            ? Severity.WARNING.name()
            : message.getLevel().toString();

    final Bulletin bulletin =
        BulletinFactory.createBulletin(
            null,
            taskNode.getIdentifier(),
            ComponentType.REPORTING_TASK,
            taskNode.getName(),
            "Log Message",
            bulletinLevel,
            message.getMessage());
    bulletinRepository.addBulletin(bulletin);
  }
示例#6
0
 public void info(final LogMessage message, final Throwable throwable) {
   if (logger.isInfoEnabled()) {
     logger.info(message.toString(), throwable);
   }
 }
示例#7
0
 public void info(final LogMessage message) {
   if (logger.isInfoEnabled()) {
     logger.info(message.toString());
   }
 }
示例#8
0
 public void error(final LogMessage message, final Throwable throwable) {
   if (logger.isErrorEnabled()) {
     logger.error(message.toString(), throwable);
   }
 }
示例#9
0
 public void error(final LogMessage message) {
   if (logger.isErrorEnabled()) {
     logger.error(message.toString());
   }
 }
示例#10
0
 public void debug(final LogMessage message, final Throwable throwable) {
   if (logger.isDebugEnabled()) {
     logger.debug(message.toString(), throwable);
   }
 }
示例#11
0
 public void warn(final LogMessage message) {
   if (logger.isWarnEnabled()) {
     logger.warn(message.toString());
   }
 }
 @Test
 public void isCorrectSetMessageAtStringForFile() {
   logMessage = new LogMessage("12.03.2012/Test message./" + LogStatus.success.toString(), "/");
   assertEquals(logMessage.toString(), "12.03.2012 > Test message. Status: success");
 }
 @Test
 public void isCorrectConvertToStringForFile() {
   logMessage = new LogMessage("12.03.2012", "Test message.", LogStatus.success);
   assertEquals(logMessage.toStringForFile("/"), "12.03.2012/Test message./success");
 }
 @Test
 public void isCorrectConvertToString() {
   logMessage = new LogMessage("12.03.2012", "Test message.", LogStatus.success);
   assertEquals(logMessage.toString(), "12.03.2012 > Test message. Status: success");
 }
示例#15
0
 public void trace(final LogMessage message) {
   if (logger.isTraceEnabled()) {
     logger.trace(message.toString());
   }
 }
示例#16
0
 public void trace(final LogMessage message, final Throwable throwable) {
   if (logger.isTraceEnabled()) {
     logger.trace(message.toString(), throwable);
   }
 }
示例#17
0
 public void addMessage(LogMessage msg) {
   if (!m_serviceID.equals(msg.getServiceID())) {
     throw new IllegalArgumentException(
         "ServiceID of log message does not match serviceID of ServiceCollector: " + m_serviceID);
   }
   if (msg.isCollectorBeginMessage()) {
     m_lastBegin = msg.getDate().getTime();
     // measure the time between collections
     if (m_lastEnd > 0) {
       m_totalBetweenTime += msg.getDate().getTime() - m_lastEnd;
       m_betweenCount++;
     }
     m_lastEnd = 0;
   }
   if (msg.isErrorMessage()) {
     m_lastErrorBegin = m_lastBegin;
   }
   if (msg.isCollectorEndMessage()) {
     long end = msg.getDate().getTime();
     m_lastEnd = msg.getDate().getTime();
     if (m_lastBegin > 0) {
       m_totalTime += end - m_lastBegin;
       m_collectionCount++;
     }
     m_lastBegin = 0;
     if (m_lastErrorBegin > 0) {
       m_errorTime += end - m_lastErrorBegin;
       m_errorCount++;
     }
     m_lastErrorBegin = 0;
   }
   if (msg.isPersistBeginMessage()) {
     m_lastPersistBegin = msg.getDate().getTime();
   }
   if (msg.isPersistEndMessage()) {
     long end = msg.getDate().getTime();
     msg.getDate().getTime();
     if (m_lastPersistBegin > 0) {
       m_totalPersistTime += end - m_lastPersistBegin;
       m_persistCount++;
     }
     m_lastPersistBegin = 0;
   }
 }
示例#18
0
 public void warn(final LogMessage message, final Throwable throwable) {
   if (logger.isWarnEnabled()) {
     logger.warn(message.toString(), throwable);
   }
 }
示例#19
0
 public void debug(final LogMessage message) {
   if (logger.isDebugEnabled()) {
     logger.debug(message.toString());
   }
 }