Add log file and skeleton code for visualization data

This commit is contained in:
2019-01-23 13:52:48 -08:00
parent cc3ebca12f
commit ba275b98fc
5 changed files with 75 additions and 5 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
/.meghanada/
*.csv
/config/config.properties
/logs/viz.log

View File

@ -41,6 +41,13 @@ run {
}
}
task runViz(type: JavaExec) {
dependsOn classes
systemProperty 'logback.configurationFile', 'src/main/resources/logback.xml'
classpath sourceSets.main.runtimeClasspath
main = 'Viz'
}
testlogger {
theme 'standard'
showStandardStreams true

View File

@ -21,7 +21,8 @@ import ats.plugin.OHLCPlugInViewFactory;
public class EsperProcessor implements TickProcessor {
final Logger log = LoggerFactory.getLogger(EsperProcessor.class);
static final Logger log = LoggerFactory.getLogger(EsperProcessor.class);
static final Logger viz = LoggerFactory.getLogger(Viz.LOG_NAME);
EPServiceProvider engine;
TradingManager trader;
@ -49,6 +50,7 @@ public class EsperProcessor implements TickProcessor {
// addLogStatement("TickEvent");
addVizDataStreamHandler();
addLogStreamHandler();
// respond to long entry events
@ -161,6 +163,17 @@ public class EsperProcessor implements TickProcessor {
return statement;
}
/**
* Add a simple EPL statement to the Esper engine that logs any
* event that matches the event name.
*/
private EPStatement addVizDataStreamHandler() {
return addStatement("select * from VizDataStream",
(newData, oldData) -> {
viz.info(newData[0].get("event").toString());
});
}
/**
* Add a simple EPL statement to the Esper engine that logs any
* event that matches the event name.

34
src/main/java/Viz.java Normal file
View File

@ -0,0 +1,34 @@
import java.util.StringJoiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Viz converts visualization log data into a graphical
* representation.
*/
public class Viz {
public static final String LOG_NAME = "viz-data";
static final Logger log = LoggerFactory.getLogger("Viz");
static final Logger viz = LoggerFactory.getLogger(LOG_NAME);
/**
* Run the converter.
*/
public static void main(String[] args) {
}
/**
* Convert event data to our preferred format. This format can be
* placed into a log, which we can later read back in.
*/
public static String eventString(Object... objects) {
StringJoiner sj = new StringJoiner(", ");
for (Object o : objects) {
sj.add(o != null ? o.toString() : "null");
}
return sj.toString();
}
}

View File

@ -16,6 +16,7 @@
</encoder>
</appender>
<!-- The primary log file. For all runtime messages. -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/run.log</file>
<append>false</append>
@ -24,6 +25,20 @@
</encoder>
</appender>
<!-- Log file for visualization data. Read by the Viz app. -->
<appender name="VIZ-FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/viz.log</file>
<append>false</append>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<!-- additivity=false ensures viz data only goes to the viz log -->
<logger name="viz-data" level="DEBUG" additivity="false">
<appender-ref ref="VIZ-FILE"/>
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />