use of com.continuuity.weave.api.logging.LogEntry in project weave by continuuity.
the class LogEntryDecoder method deserialize.
@Override
public LogEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
final String name = JsonUtils.getAsString(jsonObj, "name");
final String host = JsonUtils.getAsString(jsonObj, "host");
final long timestamp = JsonUtils.getAsLong(jsonObj, "timestamp", 0);
LogEntry.Level l;
try {
l = LogEntry.Level.valueOf(JsonUtils.getAsString(jsonObj, "level"));
} catch (Exception e) {
l = LogEntry.Level.FATAL;
}
final LogEntry.Level logLevel = l;
final String className = JsonUtils.getAsString(jsonObj, "className");
final String method = JsonUtils.getAsString(jsonObj, "method");
final String file = JsonUtils.getAsString(jsonObj, "file");
final String line = JsonUtils.getAsString(jsonObj, "line");
final String thread = JsonUtils.getAsString(jsonObj, "thread");
final String message = JsonUtils.getAsString(jsonObj, "message");
final StackTraceElement[] stackTraces = context.deserialize(jsonObj.get("stackTraces").getAsJsonArray(), StackTraceElement[].class);
return new LogEntry() {
@Override
public String getLoggerName() {
return name;
}
@Override
public String getHost() {
return host;
}
@Override
public long getTimestamp() {
return timestamp;
}
@Override
public Level getLogLevel() {
return logLevel;
}
@Override
public String getSourceClassName() {
return className;
}
@Override
public String getSourceMethodName() {
return method;
}
@Override
public String getFileName() {
return file;
}
@Override
public int getLineNumber() {
if (line.equals("?")) {
return -1;
} else {
return Integer.parseInt(line);
}
}
@Override
public String getThreadName() {
return thread;
}
@Override
public String getMessage() {
return message;
}
@Override
public StackTraceElement[] getStackTraces() {
return stackTraces;
}
};
}
Aggregations