-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding objectTrace logger to output configurable fields to a new log …
…file from PickUpPlace (#530)
- Loading branch information
Showing
6 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/emissary/util/CustomRolloverLogbackAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package emissary.util; | ||
|
||
import emissary.config.ConfigUtil; | ||
import emissary.config.Configurator; | ||
|
||
import ch.qos.logback.core.rolling.RollingFileAppender; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
public class CustomRolloverLogbackAppender<E> extends RollingFileAppender<E> { | ||
private long start = System.currentTimeMillis(); | ||
private int rolloverTime = 15; | ||
private boolean isConfigured = false; | ||
|
||
protected static final Logger logger = LoggerFactory.getLogger(CustomRolloverLogbackAppender.class); | ||
|
||
public void configure() { | ||
try { | ||
Configurator configG = ConfigUtil.getConfigInfo(getClass()); | ||
rolloverTime = configG.findIntEntry("ROLLOVER_TIME_MINUTES", rolloverTime); | ||
} catch (IOException e) { | ||
logger.error("Could not read from the config for the CustomRolloverLogbackAppender ", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void rollover() { | ||
|
||
if (!isConfigured) { | ||
configure(); | ||
isConfigured = true; | ||
} | ||
|
||
long currentTime = System.currentTimeMillis(); | ||
int maxIntervalSinceLastLoggingInMillis = rolloverTime * 60 * 1000; | ||
|
||
if ((currentTime - start) >= maxIntervalSinceLastLoggingInMillis) { | ||
super.rollover(); | ||
start = System.currentTimeMillis(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package emissary.util; | ||
|
||
import emissary.core.IBaseDataObject; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static net.logstash.logback.marker.Markers.appendEntries; | ||
|
||
public class ObjectTracing { | ||
|
||
protected static Logger objectTraceLogger = LoggerFactory.getLogger("objectTrace");; | ||
|
||
public enum Stage { | ||
PickUp, DropOff | ||
} | ||
|
||
public ObjectTracing() {} | ||
|
||
public void emitLifecycleEvent(IBaseDataObject d, ObjectTracing.Stage stage) { | ||
|
||
Map<String, String> jsonMap = new HashMap<>(); | ||
|
||
// add our fields | ||
jsonMap.put("inputFileName", d.getFilename()); | ||
jsonMap.put("stage", String.valueOf(stage)); | ||
|
||
objectTraceLogger.info(appendEntries(jsonMap), ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/emissary/util/CustomRolloverLogbackAppender.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ROLLOVER_TIME_MINUTES = 15 |