[NO ISSUE] Tracer improvements
Log traces to their own log with custom level,
as well as make the emitted log work with the
chrome tracer without modification
Change-Id: I81c158fcd17927d65e7b501345fdbc98001ba86a
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3064
Reviewed-by: Ian Maxon <imaxon@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/main/resources/log4j2.xml b/asterixdb/asterix-app/src/main/resources/log4j2.xml
index 2ea8d4a..e54a424 100644
--- a/asterixdb/asterix-app/src/main/resources/log4j2.xml
+++ b/asterixdb/asterix-app/src/main/resources/log4j2.xml
@@ -19,6 +19,7 @@
<Configuration status="WARN">
<CustomLevels>
<CustomLevel name="ACCESS" intLevel="550" />
+ <CustomLevel name="TRACER" intLevel="570" />
</CustomLevels>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
@@ -27,6 +28,12 @@
<Console name="AccessLog" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
+ <Console name="TracerLog" target="SYSTEM_OUT">
+ <PatternLayout pattern="%m%n"/>
+ </Console>
+ <File name="TracerLogFile" fileName="target/tracer.log">
+ <PatternLayout pattern="%m,%n" header="[" footer="]"/>
+ </File>
</Appenders>
<Loggers>
<Root level="WARN">
@@ -36,5 +43,9 @@
<Logger name="org.apache.hyracks.http.server.CLFLogger" level="ACCESS" additivity="false">
<AppenderRef ref="AccessLog"/>
</Logger>
+ <Logger name="org.apache.hyracks.util.trace.Tracer.Traces" level="TRACER" additivity="false">
+ <AppenderRef ref="TracerLog"/>
+ <AppenderRef ref="TracerLogFile"/>
+ </Logger>
</Loggers>
</Configuration>
\ No newline at end of file
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCLogConfigurationFactory.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCLogConfigurationFactory.java
index 41f8e7b..24c3dee 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCLogConfigurationFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCLogConfigurationFactory.java
@@ -51,10 +51,12 @@
ComponentBuilder triggeringPolicy = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy").addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size", "50M"));
- AppenderComponentBuilder defaultRoll = builder.newAppender("default", "RollingFile")
- .addAttribute("fileName", FileUtil.joinPath(logDir, "nc-" + nodeId + ".log"))
- .addAttribute("filePattern", FileUtil.joinPath(logDir, "nc-" + nodeId + "-%d{MM-dd-yy}.log.gz"))
- .add(defaultLayout).addComponent(triggeringPolicy);
+ AppenderComponentBuilder defaultRoll =
+ builder.newAppender("default", "RollingFile")
+ .addAttribute("fileName", FileUtil.joinPath(logDir, "nc-" + nodeId + ".log"))
+ .addAttribute("filePattern",
+ FileUtil.joinPath(logDir, "nc-" + nodeId + "-%d{MM-dd-yy-ss}.log.gz"))
+ .add(defaultLayout).addComponent(triggeringPolicy);
builder.add(defaultRoll);
// create the new logger
@@ -65,12 +67,22 @@
builder.newAppender("access", "RollingFile")
.addAttribute("fileName", FileUtil.joinPath(logDir, "access-" + nodeId + ".log"))
.addAttribute("filePattern",
- FileUtil.joinPath(logDir, "access-" + nodeId + "-%d{MM-dd-yy}.log.gz"))
+ FileUtil.joinPath(logDir, "access-" + nodeId + "-%d{MM-dd-yy-ss}.log.gz"))
.add(accessLayout).addComponent(triggeringPolicy);
builder.add(accessRoll);
builder.add(builder.newLogger("org.apache.hyracks.http.server.CLFLogger", Level.forName("ACCESS", 550))
.add(builder.newAppenderRef("access")).addAttribute("additivity", false));
+ LayoutComponentBuilder traceLayout = builder.newLayout("PatternLayout").addAttribute("pattern", "%m,%n")
+ .addAttribute("header", "[").addAttribute("footer", "]");
+ AppenderComponentBuilder traceRoll = builder.newAppender("trace", "RollingFile")
+ .addAttribute("fileName", logDir + "trace-" + nodeId + ".log")
+ .addAttribute("filePattern", logDir + "trace-" + nodeId + "-%d{MM-dd-yy-ss}.log.gz").add(traceLayout)
+ .addComponent(triggeringPolicy);
+ builder.add(traceRoll);
+ builder.add(builder.newLogger("org.apache.hyracks.util.trace.Tracer.Traces", Level.forName("TRACER", 570))
+ .add(builder.newAppenderRef("trace")).addAttribute("additivity", false));
+
return builder.build();
}
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
index 3edba21..b5fe3d3 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
@@ -77,7 +77,11 @@
sb.append(",\"s\":\"").append(scope).append("\"");
}
if (args != null) {
- sb.append(",\"args\":").append(args);
+ if (args.isEmpty()) {
+ sb.append(",\"args\":").append("\"\"");
+ } else {
+ sb.append(",\"args\":").append(args);
+ }
}
sb.append("}");
return sb;
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
index 1e8af75..9019fdf 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
@@ -34,20 +34,20 @@
*/
public class Tracer implements ITracer {
- public static final Logger LOGGER = LogManager.getLogger();
+ private static final Logger LOGGER = LogManager.getLogger();
- protected static final Level TRACE_LOG_LEVEL = Level.INFO;
- protected static final ThreadLocal<DateFormat> DATE_FORMAT =
+ private static final Level TRACE_LOG_LEVEL = Level.forName("TRACER", 570);
+ private static final ThreadLocal<DateFormat> DATE_FORMAT =
ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
- protected final Logger traceLog;
- protected long categories;
- protected TraceCategoryRegistry registry;
+ private final Logger traceLog;
+ private long categories;
+ private final TraceCategoryRegistry registry;
- protected static final int pid = PidHelper.getPid();
+ private static final int pid = PidHelper.getPid();
public Tracer(String name, long categories, TraceCategoryRegistry registry) {
- final String traceLoggerName = Tracer.class.getName() + "@" + name;
+ final String traceLoggerName = Tracer.class.getName() + ".Traces." + name;
LOGGER.info("Initialize Tracer " + traceLoggerName);
this.traceLog = LogManager.getLogger(traceLoggerName);
this.categories = categories;