org.jboss.logging.NDC Java Examples

The following examples show how to use org.jboss.logging.NDC. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JBossLoggingController.java    From tutorials with MIT License 6 votes vote down vote up
@RequestMapping(value = "/ndc/jboss-logging", method = RequestMethod.POST)
public ResponseEntity<Investment> postPayment(@RequestBody Investment investment) {
    // Add transactionId and owner to NDC
    NDC.push("tx.id=" + investment.getTransactionId());
    NDC.push("tx.owner=" + investment.getOwner());

    try {
        jbossLoggingBusinessService.transfer(investment.getAmount());
    } finally {
        // take out owner from the NDC stack
        NDC.pop();

        // take out transactionId from the NDC stack
        NDC.pop();

        NDC.clear();
    }
    return new ResponseEntity<Investment>(investment, HttpStatus.OK);
}
 
Example #2
Source File: RunningQuery.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void addNDC() {
    String user = this.settings.getUserDN();
    UUID uuid = this.settings.getId();
    if (user != null && uuid != null) {
        NDC.push("[" + user + "] [" + uuid + "]");
    }
}
 
Example #3
Source File: RunningQuery.java    From datawave with Apache License 2.0 4 votes vote down vote up
private void removeNDC() {
    NDC.pop();
}
 
Example #4
Source File: LoggingServiceActivator.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("Convert2Lambda")
@Override
protected HttpHandler getHttpHandler() {
    return new HttpHandler() {
        @Override
        public void handleRequest(final HttpServerExchange exchange) {
            final Map<String, Deque<String>> params = new TreeMap<>(exchange.getQueryParameters());
            final String msg = getValue(params, MSG_KEY, DEFAULT_MESSAGE);
            final boolean includeLevel = getValue(params, INCLUDE_LEVEL_KEY, false);
            final int logCount = getValue(params, LOG_COUNT_KEY, 1);
            final boolean logInfoOnly = getValue(params, LOG_INFO_ONLY_KEY, false);
            final boolean logException = getValue(params, LOG_EXCEPTION_KEY, false);
            final String ndcValue = getValue(params, NDC_KEY, null);
            final Set<Logger.Level> logLevels = getLevels(params);
            final String loggerName = getValue(params, LOG_NAME_KEY, null);
            if (ndcValue != null) {
                NDC.push(ndcValue);
            }
            // Assume other parameters are MDC key/value pairs
            for (String key : params.keySet()) {
                MDC.put(key, params.get(key).getFirst());
            }
            final Logger logger = (loggerName == null ? LOGGER : Logger.getLogger(loggerName));
            for (int i = 0; i < logCount; i++) {
                if (logInfoOnly) {
                    logger.info(getMessage(msg, Logger.Level.INFO, includeLevel));
                } else {
                    for (Logger.Level level : logLevels) {
                        if (logException) {
                            logger.log(level, getMessage(msg, level, includeLevel), createMultiNestedCause());
                        } else {
                            logger.log(level, getMessage(msg, level, includeLevel));
                        }
                    }
                }
            }
            // Clear NDC and MDC
            NDC.clear();
            MDC.clear();
            exchange.getResponseSender().send("Response sent");
        }
    };
}