LogUtil { static String createLogPatternLayoutJsonString(final Props props, final String jobId) { final Map<String, String> layout = new HashMap<>(); layout.put("category", "%c{1}"); layout.put("level", "%p"); layout.put("message", "%m"); layout.put("projectname", props.getString(Constants.FlowProperties.AZKABAN_FLOW_PROJECT_NAME)); layout.put("flowid", props.getString(Constants.FlowProperties.AZKABAN_FLOW_FLOW_ID)); layout.put("jobid", jobId); layout .put("submituser", props.getString(Constants.FlowProperties.AZKABAN_FLOW_SUBMIT_USER)); layout.put("execid", props.getString(Constants.FlowProperties.AZKABAN_FLOW_EXEC_ID)); layout.put("projectversion", props.getString(Constants.FlowProperties.AZKABAN_FLOW_PROJECT_VERSION)); layout.put("logsource", "userJob"); final Gson gson = new Gson(); return gson.toJson(layout); }    }
@Test public void createLogPatternLayoutJsonObject() throws Exception { final String jobId = "jobId1"; final Props props = Props.of("azkaban.flow.projectname", "projectFoo", "azkaban.flow.flowid", "flowId1", "azkaban.flow.submituser", "submitUserFoo", "azkaban.flow.execid", "execId1", "azkaban.flow.projectversion", "projectV1"); final String expected = "{\"jobid\":\"jobId1\"," + "\"projectname\":\"projectFoo\"," + "\"level\":\"%p\"," + "\"submituser\":\"submitUserFoo\"," + "\"projectversion\":\"projectV1\"," + "\"category\":\"%c{1}\"," + "\"message\":\"%m\"," + "\"logsource\":\"userJob\"," + "\"flowid\":\"flowId1\"," + "\"execid\":\"execId1\"}"; final String result = LogUtil.createLogPatternLayoutJsonString(props, jobId); assertThat(result).isEqualToIgnoringWhitespace(expected); }