/** * The marker to match in the event. * * @param markerStr */ public void setMarker(String markerStr) { if (markerStr != null) { this.markerToMatch = MarkerFactory.getMarker(markerStr); } } }
/** Returns Marker object for the specified name, or null if the name is null */ private Marker getMarkerOrNull(@Nullable String marker) { return marker != null ? MarkerFactory.getMarker(marker) : null; }
public GoConfigHolder migrate() { try { return upgrade(); } catch (Exception e) { e.printStackTrace(); System.err.println( "There are errors in the Cruise config file. Please read the error message and correct the errors.\n" + "Once fixed, please restart GoCD.\nError: " + e.getMessage()); LOGGER.error(MarkerFactory.getMarker("FATAL"), "There are errors in the Cruise config file. Please read the error message and correct the errors.\n" + "Once fixed, please restart GoCD.\nError: " + e.getMessage()); // Send exit signal in a separate thread otherwise it will deadlock jetty new Thread(() -> System.exit(1)).start(); } return null; }
protected void mapSupportLevel(String message, Throwable t) { Marker supportMarker = MarkerFactory.getMarker(SUPPORT); switch (getSupportLevel()) { case LOG_LEVEL_ERROR: LOGGER.error(supportMarker, message, t); break; case LOG_LEVEL_INFO: LOGGER.info(supportMarker, message, t); break; case LOG_LEVEL_DEBUG: LOGGER.debug(supportMarker, message, t); break; case LOG_LEVEL_TRACE: LOGGER.trace(supportMarker, message, t); break; default: LOGGER.warn(supportMarker, message, t); } }
Marker fatal = MarkerFactory.getMarker("FATAL"); LOG.error(fatal, "Prohibited String '{}' in line '{}'", aProhibited, lineFromFile);
@Test public void testAddSameMarker() { final String childMarkerName = CHILD_MAKER_NAME + "-ASM"; final String parentMakerName = PARENT_MARKER_NAME + "-ASM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j", childMarkerName, parentMakerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent)); assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J", childMarkerName, parentMakerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent)); }
@Test public void testAddMarker() { final String childMakerName = CHILD_MAKER_NAME + "-AM"; final String parentMarkerName = PARENT_MARKER_NAME + "-AM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMarkerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMarkerName); final Marker log4jMarker = MarkerManager.getMarker(childMakerName); assertTrue("Incorrect Marker class", slf4jMarker instanceof Log4jMarker); assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j", childMakerName, parentMarkerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent)); assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J", childMakerName, parentMarkerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent)); }
@Override public ScheduledReporter build(MetricRegistry registry) { final Slf4jReporter.Builder builder = Slf4jReporter.forRegistry(registry) .convertDurationsTo(getDurationUnit()) .convertRatesTo(getRateUnit()) .filter(getFilter()) .outputTo(getLogger()); if (markerName != null) { builder.markWith(MarkerFactory.getMarker(markerName)); } return builder.build(); } }
/** * The marker to match in the event. * * @param markerStr */ public void setMarker(String markerStr) { if(markerStr != null) { this.markerToMatch = MarkerFactory.getMarker(markerStr); } } }
@Test public void testEquals() { final String childMarkerName = CHILD_MAKER_NAME + "-ASM"; final String parentMakerName = PARENT_MARKER_NAME + "-ASM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jMarker2 = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); final Marker log4jMarker2 = MarkerManager.getMarker(childMarkerName); assertEquals(log4jParent, log4jParent); assertEquals(log4jMarker, log4jMarker); assertEquals(log4jMarker, log4jMarker2); assertEquals(slf4jMarker, slf4jMarker2); assertNotEquals(log4jParent, log4jMarker); assertNotEquals(log4jMarker, log4jParent); }
@Test public void testAddNullMarker() { final String childMarkerName = CHILD_MAKER_NAME + "-ANM"; final String parentMakerName = PARENT_MARKER_NAME + "-ANM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); final org.slf4j.Marker nullMarker = null; try { log4jSlf4jParent.add(nullMarker); fail("Expected " + IllegalArgumentException.class.getName()); } catch (final IllegalArgumentException e) { // expected } try { log4jSlf4jMarker.add(nullMarker); fail("Expected " + IllegalArgumentException.class.getName()); } catch (final IllegalArgumentException e) { // expected } }
@Test public void testRemoveNullMarker() { final String childMakerName = CHILD_MAKER_NAME + "-CM"; final String parentMakerName = PARENT_MARKER_NAME + "-CM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMakerName); final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); final org.slf4j.Marker nullMarker = null; Assert.assertFalse(log4jSlf4jParent.remove(nullMarker)); Assert.assertFalse(log4jSlf4jMarker.remove(nullMarker)); }
@Test public void testContainsNullString() { final String childMarkerName = CHILD_MAKER_NAME + "-CS"; final String parentMakerName = PARENT_MARKER_NAME + "-CS"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); final String nullStr = null; Assert.assertFalse(log4jSlf4jParent.contains(nullStr)); Assert.assertFalse(log4jSlf4jMarker.contains(nullStr)); }
@Test public void testContainsNullMarker() { final String childMarkerName = CHILD_MAKER_NAME + "-CM"; final String parentMakerName = PARENT_MARKER_NAME + "-CM"; final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); slf4jMarker.add(slf4jParent); final Marker log4jParent = MarkerManager.getMarker(parentMakerName); final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); final org.slf4j.Marker nullMarker = null; try { Assert.assertFalse(log4jSlf4jParent.contains(nullMarker)); fail("Expected " + IllegalArgumentException.class.getName()); } catch (final IllegalArgumentException e) { // expected } try { Assert.assertFalse(log4jSlf4jMarker.contains(nullMarker)); fail("Expected " + IllegalArgumentException.class.getName()); } catch (final IllegalArgumentException e) { // expected } }
public static void main(String[] args) throws Exception { try { FSBatchProcessCLI cli = new FSBatchProcessCLI(args); cli.execute(args); } catch (Throwable t) { t.printStackTrace(); LOG.error(MarkerFactory.getMarker("FATAL"), "Fatal exception from FSBatchProcessCLI: {}", t.getMessage(), t); System.exit(BatchProcessDriverCLI.PROCESS_NO_RESTART_EXIT_CODE); } }
private List<String> getAttributeTypesFromGlobalProperties(ATTR_VIEW_TYPE viewType, PERSON_TYPE personType) { List<String> result = new ArrayList<>(); if (viewType == ATTR_VIEW_TYPE.LISTING) { result = combineAttributes(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_LISTING_ATTRIBUTES, OpenmrsConstants.GLOBAL_PROPERTY_USER_LISTING_ATTRIBUTES, personType); } else if (viewType == ATTR_VIEW_TYPE.VIEWING) { result = combineAttributes(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES, OpenmrsConstants.GLOBAL_PROPERTY_USER_VIEWING_ATTRIBUTES, personType); } else if (viewType == ATTR_VIEW_TYPE.HEADER) { result = combineAttributes(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_HEADER_ATTRIBUTES, OpenmrsConstants.GLOBAL_PROPERTY_USER_HEADER_ATTRIBUTES, personType); } else { log.error(MarkerFactory.getMarker("FATAL"), "Should not be here."); } return result; }
private List<String> combineAttributes(String patientAttributeProperty, String userAttributeProperty, PERSON_TYPE personType) { List<String> result = new ArrayList<>(); if (personType == null || personType == PERSON_TYPE.PERSON) { result = getGlobalProperties(patientAttributeProperty, userAttributeProperty); } else if (personType == PERSON_TYPE.PATIENT) { result = getGlobalProperties(patientAttributeProperty); } else if (personType == PERSON_TYPE.USER) { result = getGlobalProperties(userAttributeProperty); } else { log.error(MarkerFactory.getMarker("FATAL"), "Should not be here."); } return result; }
@Override public void setCurrentRunNumber(int run) { if (m_runMarker != null) { m_threadMarker.remove(m_runMarker); MarkerFactory.getIMarkerFactory().detachMarker( m_runMarker.getName()); } if (run != -1) { m_runMarker = MarkerFactory.getMarker("run-" + run); m_threadMarker.add(m_runMarker); } m_runNumber = run; }
m_threadMarker = MarkerFactory.getMarker("thread-" + threadNumber);
@Override protected Slf4jReporter createInstance() { final Slf4jReporter.Builder reporter = Slf4jReporter.forRegistry(getMetricRegistry()); if (hasProperty(DURATION_UNIT)) { reporter.convertDurationsTo(getProperty(DURATION_UNIT, TimeUnit.class)); } if (hasProperty(RATE_UNIT)) { reporter.convertRatesTo(getProperty(RATE_UNIT, TimeUnit.class)); } reporter.filter(getMetricFilter()); reporter.prefixedWith(getPrefix()); if (hasProperty(MARKER)) { reporter.markWith(MarkerFactory.getMarker(getProperty(MARKER))); } if (hasProperty(LOGGER)) { reporter.outputTo(LoggerFactory.getLogger(getProperty(LOGGER))); } if (hasProperty(LEVEL)) { reporter.withLoggingLevel(getProperty(LEVEL, LoggingLevel.class)); } return reporter.build(); }