@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(LogEntry entry) { if (enabled) doLog( entry.getBundle(), entry.getServiceReference(), entry.getLevel(), entry.getMessage(), entry.getException()); }
@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(); } }