Beispiel #1
0
 @Override
 public void logged(LogEntry entry) {
   if (enabled)
     doLog(
         entry.getBundle(),
         entry.getServiceReference(),
         entry.getLevel(),
         entry.getMessage(),
         entry.getException());
 }
  @Override
  @AllowRemoteAccess
  public List<SerializableLogEntry> getLog() {
    List<SerializableLogEntry> entries = new LinkedList<SerializableLogEntry>();
    @SuppressWarnings("unchecked")
    Enumeration<LogEntry> retrievedEntries = osgiLogReaderService.getLog();

    while (retrievedEntries.hasMoreElements()) {
      LogEntry entry = retrievedEntries.nextElement();

      if (entry.getLevel() != LogService.LOG_DEBUG) {
        String exceptionString = "";
        if (entry.getException() != null) {
          exceptionString = entry.getException().toString();
        }
        entries.add(
            entries.size(),
            new SerializableLogEntry(
                entry.getBundle().getSymbolicName(),
                entry.getLevel(),
                entry.getMessage().replaceAll("\n", SerializableLogEntry.RCE_SEPARATOR),
                entry.getTime(),
                exceptionString));
      }
    }
    return entries;
  }
    @Override
    public void logged(final LogEntry entry) {

      if (entry.getLevel() == LogService.LOG_DEBUG) {
        return;
      }
      orderedExecutionQueue.enqueue(
          new Runnable() {

            @Override
            @TaskDescription(ASYNC_TASK_DESCRIPTION)
            public void run() {
              try {
                String exceptionString = "";
                if (entry.getException() != null) {
                  exceptionString = entry.getException().toString();
                }
                externalListener.logged(
                    new SerializableLogEntry(
                        entry.getBundle().getSymbolicName(),
                        entry.getLevel(),
                        entry.getMessage().replaceAll("\n", SerializableLogEntry.RCE_SEPARATOR),
                        entry.getTime(),
                        exceptionString));
              } catch (RemoteOperationException e) {
                final Log localLog = LogFactory.getLog(getClass());
                localLog.error(
                    "Error while forwarding log event to listener "
                        + "(delivery of log events to this receiver will be cancelled): "
                        + e.toString());
                // TODO >7.0.0: these lines should be equivalent, but aren't; investigate why -
                // misc_ro, Nov 2015
                // orderedExecutionQueue.cancelAsync();
                throw new RuntimeException(
                    "Error while forwarding log event to listener"); // workaround to restore
                // behavior
              }
              // the @TaskDescription is not forwarded by AsyncOrderedExecutionQueue, so count a
              // stats event for monitoring - misc_ro
              StatsCounter.count(
                  AsyncOrderedExecutionQueue.STATS_COUNTER_SHARED_CATEGORY_NAME,
                  ASYNC_TASK_DESCRIPTION);
            }
          });
    }
Beispiel #4
0
  @Override
  public void logged(LogEntry entry) {
    try {

      // try to get a writer
      Writer writer = getWriter();
      if (writer == null) {
        // silently fail, ELK service might just not be running
        return;
      }

      // prepare a exception string if the log contains an exception
      String exception =
          entry.getException() == null ? "" : " " + entry.getException().getMessage();

      // format time of log
      Instant dateTimeInstant = new Date(entry.getTime()).toInstant();
      LocalDateTime dateTime = LocalDateTime.ofInstant(dateTimeInstant, ZoneId.of("GMT"));

      // concatenate log string
      String log =
          m_formatter.format(dateTime)
              + " "
              + m_hostname
              + " "
              + m_frameworkUUID
              + " "
              + entry.getBundle().getSymbolicName()
              + " "
              + getLogLevel(entry.getLevel())
              + " "
              + entry.getMessage()
              + exception;

      // write log string to logstash
      writer.write(log + "\n");
      writer.flush();
    } catch (Exception e) {
      // silently fail, ELK service might just not be running
      cleanup();
    }
  }
 @Override
 public void logged(LogEntry entry) {
   System.out.println(entry.getMessage());
 }