@Override public EventSink getEventSink(String name, Properties props) { return configureSink(new SocketEventSink(name, hostName, port, new JSONFormatter(false), getLogSink(name, props, new JSONFormatter()))); }
/** * Create JSON formatter and conditionally format with newline * * @param newLine * apply newline formatting to JSON */ public JSONFormatter(boolean newLine) { newLineFormat = newLine; initTags(); }
/** * Checks whether provided {@code value} is special numeric value and if formatter is configured to enquote these * values. * * @param value * value to check * @return {@code true} if value is special and should be enquoted, {@code false} - otherwise */ protected boolean isSpecialEnquote(Object value) { return specialNumbersHandling == SpecNumbersHandling.ENQUOTE && isSpecial(value); }
jsonString.append(JSON_SOURCE_LABEL).append(ATTR_SEP); Utils.quote(StringEscapeUtils.escapeJson(source.getName()), jsonString).append(ATTR_JSON); String ssn = getSSN(source); if (!Utils.isEmpty(ssn)) { jsonString.append(ATTR_JSON); jsonString.append(JSON_PROPERTIES_LABEL).append(ATTR_SEP).append(ARRAY_START_JSON) .append(itemsToJSON(snap.getSnapshot())).append(ARRAY_END);
if (isSpecialSuppress(value)) { return EMPTY_STR; if (isNoNeedToQuote(value)) { jsonString.append(propValueToString(value)); } else { Utils.quote(StringEscapeUtils.escapeJson(propValueToString(value)), jsonString);
String itemJSON; if (item instanceof TrackingEvent) { itemJSON = format((TrackingEvent) item); } else if (item instanceof TrackingActivity) { itemJSON = format((TrackingActivity) item); } else if (item instanceof Snapshot) { itemJSON = format((Snapshot) item); } else if (item instanceof Property) { itemJSON = format((Property) item); } else { addDelimiterOnDemand(jsonString, ATTR_JSON); jsonString.append(itemJSON);
@Override public String format(Object obj, Object... args) { if (obj instanceof TrackingActivity) { return format((TrackingActivity) obj); } else if (obj instanceof TrackingEvent) { return format((TrackingEvent) obj); } else if (obj instanceof Snapshot) { return format((Snapshot) obj); } else if (obj instanceof Property) { return format((Property) obj); } else { StringBuilder jsonString = new StringBuilder(1024); jsonString.append(START_JSON); jsonString.append(JSON_TIME_USEC_LABEL).append(ATTR_SEP).append(Useconds.CURRENT.get()).append(ATTR_JSON); String msgText = StringEscapeUtils.escapeJson(Utils.format(Utils.toString(obj), args)); // escape double // quote chars jsonString.append(JSON_MSG_TEXT_LABEL).append(ATTR_SEP); Utils.quote(msgText, jsonString); jsonString.append(END_JSON); return jsonString.toString(); } }
/** * Checks whether provided {@code value} can be un-quoted in produced JSON. * * @param value * value to check * @return {@code true} if value is one of: {@code null}, boolean, number, date, timestamp, {@code false} - * otherwise * * @see #isSpecialSuppress(Object) */ protected boolean isNoNeedToQuote(Object value) { return value == null || value instanceof Boolean || value instanceof Date || value instanceof UsecTimestamp || (value instanceof Number && !isSpecialEnquote(value)); }
jsonString.append(JSON_SOURCE_LABEL).append(ATTR_SEP); Utils.quote(StringEscapeUtils.escapeJson(source.getName()), jsonString).append(ATTR_JSON); String ssn = getSSN(source); if (!Utils.isEmpty(ssn)) {
String ssn = getSSN(activity.getSource()); if (!Utils.isEmpty(ssn)) { jsonString.append(ATTR_JSON); jsonString.append(JSON_CORR_ID_LABEL).append(ATTR_SEP).append(ARRAY_START_JSON) .append(itemsToJSON(activity.getCorrelator())).append(ARRAY_END); .append(itemsToJSON(activity.getIds())).append(ARRAY_END); .append(itemsToJSON(activity.getProperties())).append(ARRAY_END); .append(itemsToJSON(activity.getSnapshots())).append(ARRAY_END);
@Override public String format(Snapshot snapshot) { if (level == 9) { return super.format(snapshot);
@Override public EventSink getEventSink(String name, Properties props) { return getEventSink(name, props, new JSONFormatter(false)); }
String ssn = getSSN(event.getSource()); if (!Utils.isEmpty(ssn)) { jsonString.append(ATTR_JSON); jsonString.append(JSON_CORR_ID_LABEL).append(ATTR_SEP).append(ARRAY_START_JSON) .append(itemsToJSON(event.getCorrelator())).append(ARRAY_END); .append(itemsToJSON(event.getTag())).append(ARRAY_END); .append(itemsToJSON(event.getOperation().getProperties())).append(ARRAY_END); .append(itemsToJSON(event.getOperation().getSnapshots())).append(ARRAY_END);
@Override public String format(TrackingActivity activity) { if (level == 9) { return super.format(activity);
@Override public void setConfiguration(Map<String, ?> settings) { config = settings; newLineFormat = Utils.getBoolean("Newline", settings, newLineFormat); defOpName = Utils.getString("OpName", settings, defOpName); String specNumbers = Utils.getString("SpecNumbersHandling", settings, SpecNumbersHandling.SUPPRESS.name()); try { specialNumbersHandling = SpecNumbersHandling.valueOf(specNumbers.toUpperCase()); } catch (IllegalArgumentException exc) { specialNumbersHandling = SpecNumbersHandling.SUPPRESS; } initTags(); }
/** * Checks whether provided {@code value} is special numeric value and if formatter is configured to suppress these * values. * * @param value * value to check * @return {@code true} if value is special and should be suppressed, {@code false} - otherwise * * @see #isSpecial(Object) */ protected boolean isSpecialSuppress(Object value) { return specialNumbersHandling == SpecNumbersHandling.SUPPRESS && isSpecial(value); }
@Override public EventSink getEventSink(String name, Properties props) { return getEventSink(name, props, new JSONFormatter(false)); }
@Override public String format(Property prop) { if (level == 9) { return super.format(prop); } if (prop == null || prop.isTransient()) { return EMPTY_STR; } Object value = prop.getValue(); if (isSpecialSuppress(value)) { return EMPTY_STR; } StringBuilder jsonString = new StringBuilder(256); jsonString.append(Utils.quote(StringEscapeUtils.escapeJson(getKeyStr(prop.getKey())))).append(ATTR_SEP); if (isNoNeedToQuote(value)) { jsonString.append(propValueToString(value)); } else { Utils.quote(StringEscapeUtils.escapeJson(propValueToString(value)), jsonString); } return jsonString.toString(); }
@Override public EventSink getEventSink(String name, Properties props) { return getEventSink(name, props, new JSONFormatter(false)); }
@Override public String format(TrackingEvent event) { if (level == 9) { return super.format(event);