本文整理匯總了Java中org.slf4j.MarkerFactory.getMarker方法的典型用法代碼示例。如果您正苦於以下問題:Java MarkerFactory.getMarker方法的具體用法?Java MarkerFactory.getMarker怎麽用?Java MarkerFactory.getMarker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.slf4j.MarkerFactory
的用法示例。
在下文中一共展示了MarkerFactory.getMarker方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMarker
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Test
public void testMarker() throws Exception {
String token = "markerToken";
String type = "markerType";
String loggerName = "markerTesting";
String markerKey = "marker";
String markerTestValue = "MyMarker";
int drainTimeout = 1;
String message1 = "Simple log line - "+random(5);
Marker marker = MarkerFactory.getMarker(markerTestValue);
Logger testLogger = createLogger(token, type, loggerName, drainTimeout, false, false, null);
testLogger.info(marker, message1);
sleepSeconds(2 * drainTimeout);
mockListener.assertNumberOfReceivedMsgs(1);
MockLogzioBulkListener.LogRequest logRequest = mockListener.assertLogReceivedByMessage(message1);
mockListener.assertLogReceivedIs(logRequest, token, type, loggerName, Level.INFO.levelStr);
assertThat(logRequest.getStringFieldOrNull(markerKey)).isEqualTo(markerTestValue);
}
示例2: testCategorties
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Test
public void testCategorties() {
logMsg = "Running testCategories()";
Marker cat0 = MarkerFactory.getMarker("cat0");
LOGGER.info(cat0, logMsg);
assertThat(getMessage(), is(logMsg));
assertThat(getField(Fields.COMPONENT_ID), is("-"));
assertThat(getField(Fields.COMPONENT_NAME), is("-"));
assertThat(getField(Fields.COMPONENT_INSTANCE), is("0"));
assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
assertThat(getList(Fields.CATEGORIES), contains(cat0.getName()));
Marker cat1 = MarkerFactory.getMarker("cat1");
cat1.add(cat0);
LOGGER.info(cat1, logMsg);
assertThat(getMessage(), is(logMsg));
assertThat(getField(Fields.COMPONENT_ID), is("-"));
assertThat(getField(Fields.COMPONENT_NAME), is("-"));
assertThat(getField(Fields.COMPONENT_INSTANCE), is("0"));
assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
assertThat(getList(Fields.CATEGORIES), contains(cat1.getName(), cat0.getName()));
}
示例3: init
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@PostConstruct
public void init() {
log.debug("Registering JVM gauges");
metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet());
if (jHipsterProperties.getMetrics().getJmx().isEnabled()) {
log.debug("Initializing Metrics JMX reporting");
JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
jmxReporter.start();
}
if (jHipsterProperties.getMetrics().getLogs().isEnabled()) {
log.info("Initializing Metrics Log reporting");
Marker metricsMarker = MarkerFactory.getMarker("metrics");
final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry)
.outputTo(LoggerFactory.getLogger("metrics"))
.markWith(metricsMarker)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS);
}
}
示例4: mapSupportLevel
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
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);
}
}
示例5: testComposite
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Test
public void testComposite() {
String compositeMarkerName = COMPOSITE;
Marker compositeMarker = MarkerFactory.getMarker(compositeMarkerName);
compositeMarker.add(totoMarker);
MarkerFilter mkt = new MarkerFilter();
mkt.setMarker(TOTO);
mkt.setOnMatch("ACCEPT");
mkt.setOnMismatch("DENY");
mkt.start();
assertTrue(mkt.isStarted());
assertEquals(FilterReply.DENY, mkt.decide(null, null, null, null, null, null));
assertEquals(FilterReply.ACCEPT, mkt.decide(totoMarker, null, null, null, null, null));
assertEquals(FilterReply.ACCEPT, mkt.decide(compositeMarker, null, null, null, null, null));
}
示例6: testIgnoreMarker
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Test
public void testIgnoreMarker() throws NullPointerException, EvaluationException, JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
jc.doConfigure(ClassicTestConstants.JORAN_INPUT_PREFIX + "ignore.xml");
Map evalMap = (Map) loggerContext.getObject(CoreConstants.EVALUATOR_MAP);
assertNotNull(evalMap);
Logger logger = loggerContext.getLogger("xx");
JaninoEventEvaluator evaluator = (JaninoEventEvaluator) evalMap.get("IGNORE_EVAL");
LoggingEvent event = new LoggingEvent("foo", logger, Level.DEBUG, "Hello world",null, null);
Marker ignoreMarker = MarkerFactory.getMarker("IGNORE");
event.setMarker(ignoreMarker);
assertTrue(evaluator.evaluate(event));
logger.debug("hello", new Exception("test"));
logger.debug(ignoreMarker, "hello ignore", new Exception("test"));
//logger.debug("hello", new Exception("test"));
//StatusPrinter.print(loggerContext.getStatusManager());
}
示例7: log
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
/**
* Logs a message.
*/
@Override
public void log(final int priority, final String tag, final String message) {
final Marker marker = MarkerFactory.getMarker(tag);
switch (priority) {
case AxolotlLogger.VERBOSE:
case AxolotlLogger.DEBUG:
LOGGER.debug(marker, message);
break;
case AxolotlLogger.INFO:
LOGGER.info(marker, message);
break;
case AxolotlLogger.WARN:
LOGGER.warn(marker, message);
break;
case AxolotlLogger.ERROR:
LOGGER.error(marker, message);
break;
case AxolotlLogger.ASSERT:
LOGGER.trace(marker, message);
break;
default:
LOGGER.error(marker, "## Unknown Loglevel Message: ##" + message);
}
}
示例8: logException
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
/**
* Logs the exception; on ERROR level when status is 5xx, otherwise on INFO level without stack
* trace, or DEBUG level with stack trace. The logger name is
* {@code cz.jirutka.spring.exhandler.handlers.RestExceptionHandler}.
*
* @param ex The exception to log.
* @param req The current web request.
*/
protected void logException(E ex, HttpServletRequest req) {
if (LOG.isErrorEnabled() && getStatus().value() >= 500 || LOG.isInfoEnabled()) {
Marker marker = MarkerFactory.getMarker(ex.getClass().getName());
String uri = req.getRequestURI();
if (req.getQueryString() != null) {
uri += '?' + req.getQueryString();
}
String msg = String.format("%s %s ~> %s", req.getMethod(), uri, getStatus());
if (getStatus().value() >= 500) {
LOG.error(marker, msg, ex);
} else if (LOG.isDebugEnabled()) {
LOG.debug(marker, msg, ex);
} else {
LOG.info(marker, msg);
}
}
}
示例9: resourceOffers
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Override
public void resourceOffers(final SchedulerDriver driver, final List<Offer> offers) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("> resourceOffers(driver : {}, offers : {})", driver, protoToString(offers));
}
for (final Offer offer : offers) {
final Marker marker = MarkerFactory.getMarker("offerId:" + offer.getId().getValue() + ",hostname:" + offer.getHostname());
final boolean offerUsed = evaluateOffer(driver, marker, offer);
if (!offerUsed) {
LOGGER.trace(marker, "Declining Offer: {}", offer.getId().getValue());
driver.declineOffer(offer.getId());
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("< resourceOffers(driver : {}, offers : {})", driver, protoToString(offers));
}
}
示例10: allResourcesAvailableBeforeLaunchingExecutor
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Test
public void allResourcesAvailableBeforeLaunchingExecutor() throws Exception {
cleanState();
final String role = "*";
final Protos.Offer offer = Protos.Offer.newBuilder()
.setFrameworkId(frameworkId)
.setHostname("localhost")
.setId(Protos.OfferID.newBuilder().setValue(randomID()))
.setSlaveId(Protos.SlaveID.newBuilder().setValue("slave_1"))
.addResources(cpu(0.1, role))
.addResources(mem(0.1, role))
.addResources(disk(0.1, role))
.addResources(ports(Lists.<Long>emptyList(), role))
.build();
final Marker marker = MarkerFactory.getMarker("offerId:" + offer.getId().getValue() + ",hostname:" + offer.getHostname());
assertThat(cluster._getTasksForOffer(marker, offer)).isNull();
}
示例11: getMarker
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
private org.slf4j.Marker getMarker(final Marker marker) {
if (marker == null) {
return null;
}
final org.slf4j.Marker slf4jMarker = MarkerFactory.getMarker(marker.getName());
final Marker[] parents = marker.getParents();
if (parents != null) {
for (final Marker parent : parents) {
final org.slf4j.Marker slf4jParent = getMarker(parent);
if (!slf4jMarker.contains(slf4jParent)) {
slf4jMarker.add(slf4jParent);
}
}
}
return slf4jMarker;
}
示例12: init
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@PostConstruct
public void init() {
log.debug("Registering JVM gauges");
metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet());
if (hikariDataSource != null) {
log.debug("Monitoring the datasource");
hikariDataSource.setMetricRegistry(metricRegistry);
}
if (jHipsterProperties.getMetrics().getJmx().isEnabled()) {
log.debug("Initializing Metrics JMX reporting");
JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
jmxReporter.start();
}
if (jHipsterProperties.getMetrics().getLogs().isEnabled()) {
log.info("Initializing Metrics Log reporting");
Marker metricsMarker = MarkerFactory.getMarker("metrics");
final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry)
.outputTo(LoggerFactory.getLogger("metrics"))
.markWith(metricsMarker)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS);
}
}
示例13: init
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@PostConstruct
public void init() {
log.debug("Registering JVM gauges");
metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet());
metricRegistry.register(PROP_METRIC_REG_JCACHE_STATISTICS, new JCacheGaugeSet());
if (hikariDataSource != null) {
log.debug("Monitoring the datasource");
hikariDataSource.setMetricRegistry(metricRegistry);
}
if (jHipsterProperties.getMetrics().getJmx().isEnabled()) {
log.debug("Initializing Metrics JMX reporting");
JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
jmxReporter.start();
}
if (jHipsterProperties.getMetrics().getLogs().isEnabled()) {
log.info("Initializing Metrics Log reporting");
Marker metricsMarker = MarkerFactory.getMarker("metrics");
final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry)
.outputTo(LoggerFactory.getLogger("metrics"))
.markWith(metricsMarker)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS);
}
}
示例14: write
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
public static void write(Class clazz, LogLevel logLevel, String message) {
Logger logger = LoggerFactory.getLogger(clazz);
switch (logLevel) {
case TRACE:
logger.trace(message);
break;
case DEBUG:
logger.debug(message);
break;
case INFO:
logger.info(message);
break;
case WARN:
logger.warn(message);
break;
case ERROR:
logger.error(message);
break;
case FATAL:
Marker marker = MarkerFactory.getMarker("FATAL");
logger.error(marker, message);
break;
default:
logger.warn("No suitable log level found");
break;
}
}
示例15: log
import org.slf4j.MarkerFactory; //導入方法依賴的package包/類
@Override
public void log(Class<?> clazz, String method, Level level, String message, Throwable ex) {
Trace LOGGER = TraceManager.getTrace(clazz);
//Mark all messages from ICF as ICF
Marker m = MarkerFactory.getMarker("ICF");
//Translate ICF logging into slf4j
// OK -> trace
// INFO -> debug
// WARN -> warn
// ERROR -> error
if (Level.OK.equals(level)) {
if (null == ex) {
LOGGER.trace(m, "method: {} msg:{}", method, message);
} else {
LOGGER.trace(m, "method: {} msg:{}", new Object[] { method, message }, ex);
}
} else if (Level.INFO.equals(level)) {
if (null == ex) {
LOGGER.debug(m, "method: {} msg:{}", method, message);
} else {
LOGGER.debug(m, "method: {} msg:{}", new Object[] { method, message }, ex);
}
} else if (Level.WARN.equals(level)) {
if (null == ex) {
LOGGER.warn(m, "method: {} msg:{}", method, message);
} else {
LOGGER.warn(m, "method: {} msg:{}", new Object[] { method, message }, ex);
}
} else if (Level.ERROR.equals(level)) {
if (null == ex) {
LOGGER.error(m, "method: {} msg:{}", method, message);
} else {
LOGGER.error(m, "method: {} msg:{}", new Object[] { method, message }, ex);
}
}
}