/** * Create JSON formatter and conditionally format with newline * * @param newLine * apply newline formatting to JSON */ public JSONFormatter(boolean newLine) { newLineFormat = newLine; initTags(); }
/** * Create a file based sink based on given filename, append flag. * * @param filename * for generating a sink instance * @param append * append to the underlying destination */ public FileSink(String filename, boolean append) { this(filename, append, new DefaultFormatter()); }
/** * 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); }
/** * {@inheritDoc} */ @Override protected void _log(Snapshot snapshot) throws IOException { writeFormattedMsg(formatter.format(snapshot)); }
@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(); }
protected Collection<Property> getProperties(Snapshot snap) { Collection<Property> pList = snap.getSnapshot(); return getSortedCollection(pList, getPropertyComparator()); }
@Override public EventSink getEventSink(String name, Properties props) { return getEventSink(name, props, new JSONFormatter(false)); }
@Override public String format(long ttl, Source src, OpLevel level, String msg, Object... args) { String formatted = super.format(ttl, src, level, msg, args); Throwable error = Utils.getThrowable(args); if (error != null) { formatted += "\nThrowable {\n" + Utils.printThrowable(error) + "}"; } return formatted; }
/** * 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)); }
@Override public int compare(Snapshot s1, Snapshot s2) { String s1Path = getSnapName(s1); String s2Path = getSnapName(s2); return s1Path.compareTo(s2Path); } };
@Override public String format(Snapshot snap) { StringBuilder msg = new StringBuilder(1024); return format(msg, snap).toString(); }
/** * {@inheritDoc} */ @Override protected void _log(long ttl, Source src, OpLevel sev, String msg, Object... args) throws IOException { writeFormattedMsg(formatter.format(ttl, src, msg, args)); }
@Override public EventSink getEventSink(String name, Properties props) { return getEventSink(name, props, new DefaultFormatter(FORMAT_PATTERN)); }
/** * 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); }
/** * {@inheritDoc} */ @Override protected void _log(TrackingEvent event) throws IOException { writeFormattedMsg(formatter.format(event)); }
/** * {@inheritDoc} */ @Override protected void _write(Object msg, Object... args) throws IOException, InterruptedException { writeFormattedMsg(formatter.format(msg, args)); }
/** * {@inheritDoc} */ @Override protected void _log(TrackingActivity activity) throws IOException { writeFormattedMsg(formatter.format(activity)); }
@Override protected void _log(long ttl, Source src, OpLevel sev, String msg, Object... args) throws IOException { writeLine(getEventFormatter().format(ttl, src, sev, msg, args)); }
@Override protected void _write(Object msg, Object... args) throws IOException, InterruptedException { _writeLog(getEventFormatter().format(msg, args)); }
@Override protected void _log(TrackingActivity activity) throws IOException { writeLine(getEventFormatter().format(activity)); }