JsonExtractor { protected Optional<LogData> mapToLogData(Map<String, String> map, DateFormat dateParser) { LogDataBuilder builder = new LogDataBuilder(); builder.withLevel(i18nLevelParser.parse(map.get(propertyLevel).trim())); final Optional<String> dateString = Optional.ofNullable(map.get(propertyDate)); String message = map.getOrDefault(propertyMessage, ""); if (map.containsKey(propertyException)) { message = message + "\n" + map.get(propertyException); } builder = builder .withDate(dateString.map(d -> parse(dateParser, d)).orElse(new Date())) .withMessage(message) .withThread(map.getOrDefault(propertyThread, "")) .withLoggerName(map.getOrDefault(propertyLogger, "")) .withClass(map.getOrDefault(propertyClass, "")) .withMethod(map.getOrDefault(propertyMethod, "")) .withLineNumber(map.getOrDefault(propertyLine, "")) .withFile(map.getOrDefault(propertyFile, "")) .withNote(new Note(map.getOrDefault(propertyNote, ""))) .withNdc(map.getOrDefault(propertyNdc, "")) ; final String color = map.getOrDefault(propertyMarkerColor, ""); if (isNotBlank(color)) { builder = builder .withMarkerColors(MarkerColors.fromString(color)) .withMarked(true); } final Map<String, String> mdc = extractMdc(map, this.propertyKeysToMdc); builder = builder.withProperties(mdc); return Optional.of(builder.build()); }  void init(Properties properties); DateFormat createDateFormatter(); List<String> extractFieldValues(String json, String field); static Map<String, String> toMap(JSONObject j); static final String LEVEL; static final String MESSAGE; static final String DATE; static final String DATE_FORMAT; static final String THREAD; static final String FILE; static final String CLASS; static final String METHOD; static final String LINE; static final String LOGGER; static final String NDC; static final String NOTE; static final String MDC_KEYS; static final String[] KEYS; }
@Test public void testMapToLogData() { final JsonExtractor extractor = new JsonExtractor(); extractor.init(new Properties()); DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS"); df.setTimeZone(TimeZone.getTimeZone("UTC")); System.out.println(df.format(new Date(1L))); Map<String, String> map = ImmutableMap.<String, String>builder() .put(JsonExtractor.MESSAGE, "log message") .put(JsonExtractor.LEVEL, "") .put(JsonExtractor.DATE, "1970-01-01 00:00:00,001") .build(); final Optional<LogData> logData = extractor.mapToLogData(map, df); Assert.assertTrue(logData.isPresent()); Assert.assertEquals(logData.get().getDate().getTime(), 1L); Assert.assertEquals(logData.get().getMessage(), "log message"); }