Skip to content

Commit

Permalink
(2.14) alarms: modify logback encoding to show actual alarm type
Browse files Browse the repository at this point in the history
Motivation:

Logback pattern encoding allows for the display of marker names
using either '%marker' or '%markerSimpleName'.  The way Alarms currently
uses markers, however, is to chain the actual value of a sub-marker as
another sub-marker.

The current encoding thus merely displays the marker names, which is
not all that informative (and perhaps even annoying): e.g.,

17 Nov 2015 07:07:17 ALARM [ ALARM_TYPE ] (fndca3a.fnal.gov)(user-command)(<na>) This is a test alarm for OutOfMemory error reporting.

Modification:

Upon arrival of the event at the server, during the preprocessing of
the alarm for either email or the optional history file, the submarker
is accessed and added to the event's MDC property map.  The pattern
encoding is changed to display the new MDC property instead of the marker.

Result:

A more meaningful printout, e.g.,

17 Nov 2015 07:07:17 FATAL_JVM_ERROR (fndca3a.fnal.gov)(user-command)(<na>) This is a test alarm for OutOfMemory error reporting.

Target: 2.14
Require-book: no
Require-notes: yes
Acked-by: Gerd
Patch: https://rb.dcache.org/r/8781/
  • Loading branch information
alrossi committed Nov 18, 2015
1 parent 70048cd commit 3a7b359
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Expand Up @@ -74,13 +74,16 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

import org.dcache.alarms.AlarmMarkerFactory;
import org.dcache.alarms.AlarmPriority;
import org.dcache.alarms.AlarmPriorityMap;
import org.dcache.alarms.dao.LogEntry;
Expand All @@ -98,6 +101,8 @@ public class LogEntryHandler {
private static final Logger LOGGER
= LoggerFactory.getLogger(LogEntryHandler.class);

private static final String MDC_TYPE = "type";

/**
* Future runnable worker task.
*/
Expand All @@ -122,6 +127,7 @@ public void run() {
* service itself.
*/
if (historyEnabled && priority >= historyThreshold.ordinal()) {
setType(event);
historyAppender.doAppend(event);
}

Expand All @@ -130,6 +136,7 @@ public void run() {
* email.
*/
if (emailEnabled && priority >= emailThreshold.ordinal()) {
setType(event);
emailAppender.doAppend(event);
}

Expand Down Expand Up @@ -360,6 +367,19 @@ public void handle(ILoggingEvent eventObject) {
executor.execute(new LogEntryTask(eventObject));
}

private void setType(ILoggingEvent eventObject) {
if (eventObject.getMDCPropertyMap().containsKey(MDC_TYPE)) {
return;
}

Marker sub = AlarmMarkerFactory.getTypeSubmarker(eventObject.getMarker());
Iterator<Marker> it = sub.iterator();
if (it.hasNext()) {
String type = it.next().getName();
eventObject.getMDCPropertyMap().put(MDC_TYPE, type);
}
}

private void startEmailAppender() {
LoggerContext context
= (LoggerContext) LoggerFactory.getILoggerFactory();
Expand Down
4 changes: 2 additions & 2 deletions skel/share/defaults/alarms.properties
Expand Up @@ -165,15 +165,15 @@ alarms.email.buffer-size=1

# ---- Pattern to use to encode email alert.
#
alarms.email.encoding-pattern=%d{dd MMM yyyy HH:mm:ss} %marker \\(%X{host}\\)\\(%X{service}\\)\\(%X{domain}\\) %m%n
alarms.email.encoding-pattern=%d{dd MMM yyyy HH:mm:ss} %X{type} \\(%X{host}\\)\\(%X{service}\\)\\(%X{domain}\\) %m%n

# ---- Level of priority serving as threshold for logging history entry.
# All alerts at this level or above are logged to the history file.
(one-of?critical|high|medium|low)alarms.history.threshold=critical

# ---- Pattern to use to encode history log entry.
#
alarms.history.encoding-pattern=%d{dd MMM yyyy HH:mm:ss} %marker \\(%X{host}\\)\\(%X{service}\\)\\(%X{domain}\\) %m%n
alarms.history.encoding-pattern=%d{dd MMM yyyy HH:mm:ss} %X{type} \\(%X{host}\\)\\(%X{service}\\)\\(%X{domain}\\) %m%n

# ---- Path of history log file
#
Expand Down

0 comments on commit 3a7b359

Please sign in to comment.