Java Code Examples for org.apache.log4j.MDC#remove()

The following examples show how to use org.apache.log4j.MDC#remove() . 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: CloverJMX.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void releaseJob(long runId) {
	Object oldRunId = MDC.get(LogUtils.MDC_RUNID_KEY);
	MDC.put(LogUtils.MDC_RUNID_KEY, runId);
	try {
		WatchDog watchDog = watchDogCache.remove(runId);
		if (watchDog == null) {
			log.warn("Released WatchDog not found for runId #" + runId);
		} else {
			sendReleaseWatchdogNotification(watchDog);
			log.debug("WatchDog unregistered from CloverJMX #" + runId);
		}
	} finally {
		if (oldRunId == null) {
			MDC.remove(LogUtils.MDC_RUNID_KEY);
		} else {
			MDC.put(LogUtils.MDC_RUNID_KEY, oldRunId);
		}
	}
}
 
Example 2
Source File: Log4jAuditor.java    From knox with Apache License 2.0 6 votes vote down vote up
private void auditLog( String action, String resourceName, String resourceType, String outcome, String message ) {
  if ( logger.isInfoEnabled() ) {
    MDC.put( AuditConstants.MDC_ACTION_KEY, action );
    MDC.put( AuditConstants.MDC_RESOURCE_NAME_KEY, maskTokenFromURL(resourceName) );
    MDC.put( AuditConstants.MDC_RESOURCE_TYPE_KEY, resourceType );
    MDC.put( AuditConstants.MDC_OUTCOME_KEY, outcome );
    MDC.put( AuditConstants.MDC_SERVICE_KEY, serviceName );
    MDC.put( AuditConstants.MDC_COMPONENT_KEY, componentName );

    logger.info( message );

    MDC.remove( AuditConstants.MDC_ACTION_KEY );
    MDC.remove( AuditConstants.MDC_RESOURCE_NAME_KEY );
    MDC.remove( AuditConstants.MDC_RESOURCE_TYPE_KEY );
    MDC.remove( AuditConstants.MDC_OUTCOME_KEY );
    MDC.remove( AuditConstants.MDC_SERVICE_KEY );
    MDC.remove( AuditConstants.MDC_COMPONENT_KEY );
  }
}
 
Example 3
Source File: RPScheduler.java    From marauroa with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For each action in the actual turn, make it to be run in the
 * ruleProcessor.
 *
 * @param ruleProcessor
 *            the class that really run the action.
 */
public synchronized void visit(IRPRuleProcessor ruleProcessor) {
	for (Map.Entry<RPObject, List<RPAction>> entry : actualTurn.entrySet()) {
		RPObject object = entry.getKey();
		List<RPAction> list = entry.getValue();

		for (RPAction action : list) {
			MDC.put("context", object + " " + action);
			try {
				if ((DebugInterface.get()).executeAction(object, action)) {
					ruleProcessor.execute(object, action);						
				}
			} catch (Exception e) {
				logger.error("error in visit()", e);
			}
			MDC.remove("context");
		}
	}
}
 
Example 4
Source File: DocumentAttributeIndexingQueueImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Override
public void indexDocument(String documentId) {
    if (StringUtils.isBlank(documentId)) {
        throw new RiceIllegalArgumentException("documentId was null or blank");
    }
    MDC.put("docId", documentId);
    try {
        long t1 = System.currentTimeMillis();
        LOG.info("Indexing document attributes for document " + documentId);
        Document document = getWorkflowDocumentService().getDocument(documentId);
        if (document == null) {
            throw new RiceIllegalArgumentException("Failed to locate document with the given id: " + documentId);
        }
        DocumentContent documentContent =
                KewApiServiceLocator.getWorkflowDocumentService().getDocumentContent(documentId);
        List<SearchableAttributeValue> attributes = buildSearchableAttributeValues(document, documentContent);
        KEWServiceLocator.getRouteHeaderService().updateRouteHeaderSearchValues(documentId, attributes);
        long t2 = System.currentTimeMillis();
        LOG.info("...finished indexing document " + documentId + " for document search, total time = " + (t2 - t1) +
                " ms.");
    } finally {
        MDC.remove("docId");
    }
}
 
Example 5
Source File: CloverJMX.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean abortGraphExecution(long runId, boolean waitForAbort) {
	Object oldRunId = MDC.get(LogUtils.MDC_RUNID_KEY);
	MDC.put(LogUtils.MDC_RUNID_KEY, runId);
	try {
		WatchDog watchDog = watchDogCache.get(runId);
		if (watchDog != null) {
			watchDog.abort(waitForAbort);
			return true;
		}
		return false;
	} finally {
		if (oldRunId == null) {
			MDC.remove(LogUtils.MDC_RUNID_KEY);
		} else {
			MDC.put(LogUtils.MDC_RUNID_KEY, oldRunId);
		}
	}
}
 
Example 6
Source File: OLATSessionTrackingFilter.java    From olat with Apache License 2.0 6 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    MDC.put(LOGGING_KEY_SESSIONID, httpRequest.getSession().getId());

    if (log.isDebugEnabled()) {
        final StringBuilder requestedUrl = new StringBuilder();
        requestedUrl.append(httpRequest.getRequestURL());
        if (httpRequest.getQueryString() != null) {
            requestedUrl.append(httpRequest.getQueryString());
        }
        log.debug("request: " + requestedUrl + " for session: " + httpRequest.getRequestedSessionId());
    }

    chain.doFilter(request, response);

    MDC.remove(LOGGING_KEY_SESSIONID);
}
 
Example 7
Source File: TaskLogger.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void debug(TaskId id, String message) {
    if (logger.isDebugEnabled()) {
        updateMdcWithTaskLogFilename(id);
        logger.debug(format(id, message));
        MDC.remove(FileAppender.FILE_NAME);
    }
}
 
Example 8
Source File: TaskLogger.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void trace(TaskId id, String message, Throwable th) {
    if (logger.isTraceEnabled()) {
        updateMdcWithTaskLogFilename(id);
        logger.trace(format(id, message), th);
        MDC.remove(FileAppender.FILE_NAME);
    }
}
 
Example 9
Source File: JobLogger.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void flush(JobId id) {
    updateMdcWithTaskLogFilename(id);
    logger.debug(PREFIX + id + " closing logger");
    for (Appender appender : (List<Appender>) Collections.list(logger.getAllAppenders())) {
        if (appender instanceof AsynchFileAppender) {
            ((AsynchFileAppender) appender).flush();
        }
    }
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 10
Source File: JobLogger.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void close(JobId id) {
    updateMdcWithTaskLogFilename(id);
    logger.debug(PREFIX + id + " closing logger");
    for (Appender appender : (List<Appender>) Collections.list(logger.getAllAppenders())) {
        if (appender != null && appender instanceof FileAppender) {
            appender.close();
        }
    }
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 11
Source File: CloverJMX.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public GraphTracking getGraphTracking(long runId) {
	Object oldRunId = MDC.get(LogUtils.MDC_RUNID_KEY);
	MDC.put(LogUtils.MDC_RUNID_KEY, runId);
	try {
		return getWatchDog(runId).getGraphTracking();
	} finally {
		if (oldRunId == null) {
			MDC.remove(LogUtils.MDC_RUNID_KEY);
		} else {
			MDC.put(LogUtils.MDC_RUNID_KEY, oldRunId);
		}
	}
}
 
Example 12
Source File: MDCUserServletFilter.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpSession session = httpRequest.getSession();
	boolean setUserId = false;
	if ( session != null && session.getAttribute(Constants.SESS_ACCOUNT) != null ) {
		String accountId = ((AccountObj)session.getAttribute(Constants.SESS_ACCOUNT)).getAccount();
		MDC.put(_USERID_KEY_NAME, accountId);
		setUserId = true;
	}
	if (!setUserId) {
		String url = httpRequest.getRequestURL().toString();
		if (url.indexOf("/services/") > -1) {
			MDC.put(_USERID_KEY_NAME, "CXF-WEBSERVICE");
			setUserId = true;
		}
		if (url.indexOf("/camel/") > -1) {
			MDC.put(_USERID_KEY_NAME, "CAMEL-ESB");
			setUserId = true;
		}
	}
	try {
		chain.doFilter(request, response);
	} catch (ServletException | IOException e) {
		e.printStackTrace();
	} finally {
		if (setUserId) {
			MDC.remove(_USERID_KEY_NAME);
		}
	}
}
 
Example 13
Source File: JobLogger.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public void trace(JobId id, String message) {
    updateMdcWithTaskLogFilename(id);
    logger.trace(PREFIX + id + " " + message);
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 14
Source File: JobLogger.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public void error(JobId id, String message) {
    updateMdcWithTaskLogFilename(id);
    logger.error(PREFIX + id + " " + message);
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 15
Source File: ExceptionRoutingServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
protected DocumentRouteHeaderValue placeInExceptionRouting(String errorMessage, RouteNodeInstance nodeInstance, PersistedMessageBO persistedMessage, RouteContext routeContext, DocumentRouteHeaderValue document, boolean invokePostProcessor) throws Exception {
	String documentId = document.getDocumentId();
    MDC.put("docId", documentId);
    PerformanceLogger performanceLogger = new PerformanceLogger(documentId);
    try {

        // mark all active requests to initialized and delete the action items
        List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(documentId);
        for (ActionRequestValue actionRequest : actionRequests) {
            if (actionRequest.isActive()) {
                actionRequest.setStatus(ActionRequestStatus.INITIALIZED.getCode());
                for (ActionItem actionItem : actionRequest.getActionItems()) {
                    KEWServiceLocator.getActionListService().deleteActionItem(actionItem);
                }
                KEWServiceLocator.getActionRequestService().saveActionRequest(actionRequest);
            }
        }

        LOG.debug("Generating exception request for doc : " + documentId);
        if (errorMessage == null) {
        	errorMessage = "";
        }
        if (errorMessage.length() > KewApiConstants.MAX_ANNOTATION_LENGTH) {
            errorMessage = errorMessage.substring(0, KewApiConstants.MAX_ANNOTATION_LENGTH);
        }
        List<ActionRequestValue> exceptionRequests = new ArrayList<ActionRequestValue>();
        if (nodeInstance.getRouteNode().isExceptionGroupDefined()) {
        	exceptionRequests = generateExceptionGroupRequests(routeContext);
        } else {
        	exceptionRequests = generateKimExceptionRequests(routeContext);
        }
        if (exceptionRequests.isEmpty()) {
            LOG.warn("Failed to generate exception requests for exception routing!");
        }
        document = activateExceptionRequests(routeContext, exceptionRequests, errorMessage, invokePostProcessor);

        if (persistedMessage == null) {
            LOG.warn("Attempting to delete null persisted message.");
        } else {
            KSBServiceLocator.getMessageQueueService().delete(persistedMessage);
        }
    } finally {
        performanceLogger.log("Time to generate exception request.");
        MDC.remove("docId");
    }

    return document;
}
 
Example 16
Source File: JobLogger.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public void info(JobId id, String message) {
    updateMdcWithTaskLogFilename(id);
    logger.info(PREFIX + id + " " + message);
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 17
Source File: TaskLogger.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public void warn(TaskId id, String message) {
    updateMdcWithTaskLogFilename(id);
    logger.warn(format(id, message));
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 18
Source File: TaskLogger.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
public void error(TaskId id, String message) {
    updateMdcWithTaskLogFilename(id);
    logger.error(format(id, message));
    MDC.remove(FileAppender.FILE_NAME);
}
 
Example 19
Source File: AbstractService.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Clear the logging context.
 */
protected void clearLoggingContext() {
    
    MDC.remove("serviceName");

    MDC.remove("serviceUUID");

    MDC.remove("hostname");
    
}
 
Example 20
Source File: ASTEvalHelper.java    From database with GNU General Public License v2.0 2 votes vote down vote up
private static void clearLoggingContext() {
    
    MDC.remove("tx");
}