當前位置: 首頁>>代碼示例>>Java>>正文


Java MDC.get方法代碼示例

本文整理匯總了Java中org.apache.log4j.MDC.get方法的典型用法代碼示例。如果您正苦於以下問題:Java MDC.get方法的具體用法?Java MDC.get怎麽用?Java MDC.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.MDC的用法示例。


在下文中一共展示了MDC.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decide

import org.apache.log4j.MDC; //導入方法依賴的package包/類
/**
 * Returns Filter#DENY if Expression returns false based on the values
 * returned from the MDC Context.
 * 
 * @param event
 *          <code>LoggingEvent</code>
 */
public int decide(final LoggingEvent event) {

	int ret = DENY;

	if (keys != null && expression != null) {
		final List<Object> mdcValues = new ArrayList<Object>();
		final List<Class<String>> keyTypes = new ArrayList<Class<String>>();
		final String[] keyValues = keys.split(SPLIT_EXPRESSION);
		if (keyValues != null) {
			for (final String keyValue : keyValues) {
				final Object mdcValue = MDC.get(keyValue);
				keyTypes.add((Class<String>) keyValue.getClass());
				mdcValues.add(mdcValue);
			}
		}
		ret = evaluate(getExpressionEvaluator(keyTypes, keyValues), mdcValues);
	}

	return ret;
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:28,代碼來源:MDCFilter.java

示例2: getMdcLong

import org.apache.log4j.MDC; //導入方法依賴的package包/類
long getMdcLong ( String key, long defval )
{
	final Object o = MDC.get ( key );
	if ( o == null ) return defval;
	if ( o instanceof String )
	{
		try
		{
			return new Long ( o.toString () );
		}
		catch ( NumberFormatException x )
		{
			return defval;
		}
	}
	if ( o instanceof Long )
	{
		return (Long)o;
	}
	return defval;
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:22,代碼來源:EcompLayout.java

示例3: onAction

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Override
public void onAction(final Player player, final RPAction action) {
	if (!action.has(TEXT)) {
		return;
	}

	String username = PlayerEntryContainer.getContainer().get(player).username;

	// remove "context" because it contains a copy of the action with the error object.
	// Thus resulting a message with duplicated information that is hard to read
	Object context = MDC.get("context");
	MDC.remove("context");

	logger.error(player.getName() + " (" + username + "):"
	  + System.getProperty("line.separator")
	  + action.get(TEXT).replaceAll("\r\n", System.getProperty("line.separator")));

	MDC.put("context", context);
}
 
開發者ID:arianne,項目名稱:stendhal,代碼行數:20,代碼來源:ReportErrorAction.java

示例4: mdcPut

import org.apache.log4j.MDC; //導入方法依賴的package包/類
static public void mdcPut(mdcKeys key, Object value) {
	LogParameters logParameters = (LogParameters) MDC.get("ContextualParameters");
	
	if (logParameters == null) {
		throw new IllegalStateException("ContextualParameters is null: call mdcInit() before!");
	}

	logParameters.put(key.toString().toLowerCase(), value);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:10,代碼來源:Log4jHelper.java

示例5: addContext

import org.apache.log4j.MDC; //導入方法依賴的package包/類
/**
 * Adds context information to Log4J's MDC object.
 * The simple classname of the current object is added as the ProcessName.
 * However, if a ProcessName already exists, then the simply classname is added as the SubProcessName.
 */
protected void addContext() {
    String name = this.getClass().getSimpleName();
    String existingName = (String) MDC.get(BusinessEventLogMeta.PROCESS_NAME);
    if (existingName == null)
        MDC.put(BusinessEventLogMeta.PROCESS_NAME, name);
    else if (!existingName.equals(name))
        MDC.put(BusinessEventLogMeta.SUB_PROCESS_NAME, name);
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:14,代碼來源:GraphService.java

示例6: unsetContext

import org.apache.log4j.MDC; //導入方法依賴的package包/類
/**
 * Unsets context information from Log4J's MDC object.
 * if a SubProcessName exists, them simply remove SubProcessName from MDC
 * However, if the SubProcessName doesn't exists, then remove ProcessName from MDC
 */
protected void unsetContext() {
    if(MDC.get(BusinessEventLogMeta.SUB_PROCESS_NAME)!=null)
        MDC.remove(BusinessEventLogMeta.SUB_PROCESS_NAME);
    else
        MDC.remove(BusinessEventLogMeta.PROCESS_NAME);
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:12,代碼來源:GraphService.java

示例7: testDecide

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Test
public void testDecide() {

  final String keys = "LoggedBy,MessageId";
  final String expression = "LoggedBy != null || MessageId != null";

  final List<Object> mdcValues = new ArrayList<Object>();
  final List<Class<String>> keyTypes = new ArrayList<Class<String>>();
  final String[] keyValues = keys.split(",");
  if (keyValues != null) {
    for (final String keyValue : keyValues) {
      final Object mdcValue = MDC.get(keyValue);
      keyTypes.add((Class<String>) keyValue.getClass());
      mdcValues.add(mdcValue);
    }
  }

  final ExpressionEvaluator evaluator = new ExpressionEvaluator();
  evaluator.setParameters(keyValues, keyTypes.toArray(new Class[0]));

  try {
    evaluator.cook(expression);
  } catch (Exception e) {
    LOG.error(e);
    fail(e.getMessage());
  }

  assertNotNull(evaluator);

  ExpressionCache.getInstance().put(expression, evaluator);

  ExpressionEvaluator testEvaluator = ExpressionCache.getInstance().get(
      expression);

  assertNotNull(testEvaluator);

  assertTrue(testEvaluator.equals(evaluator));

  ExpressionCache.getInstance().put(expression, evaluator);
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:41,代碼來源:ExpressionCacheTest.java

示例8: setLoggerLevel

import org.apache.log4j.MDC; //導入方法依賴的package包/類
public static void setLoggerLevel(String loggerName, String level) {
    Object o = MDC.get(Log.MDC_KEY_LOGGER_LEVELS);
    Map map = new HashMap();
    if (o != null && o instanceof Map) {
        map.putAll((Map)o);
    }
    map.put(loggerName, level);
    MDC.put(Log.MDC_KEY_LOGGER_LEVELS, map);
}
 
開發者ID:andyphillips404,項目名稱:awplab-core,代碼行數:10,代碼來源:MDCLoggerLevelsAutoClosable.java

示例9: beforeExecute

import org.apache.log4j.MDC; //導入方法依賴的package包/類
protected void beforeExecute(Thread t, Runnable r) {
	String GROUP_KEY = "GROUP_KEY";
	Object group = MDC.get(GROUP_KEY);
	// 將group名稱綁定到當前log4j的線程上下文中
	Hashtable<?, ?> ht = MDC.getContext();
	if (ht != null)
		ht.clear();
	if (group != null)
		MDC.put(GROUP_KEY, group);
}
 
開發者ID:dreajay,項目名稱:jcode,代碼行數:11,代碼來源:TcpConnector.java

示例10: log

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Override
public void log(String op_cate, JSONObject jo, SecuritySession session) throws BusinessError {
	try {
		JSONObject t = (JSONObject)jo.clone();
		t.put("op_cate", op_cate);//FIXME 變量命名,先後順序不太好弄啊規則都是反著的
		//
		Object remote_addr = MDC.get(LogConst.REMOTE_ADDR);
		if(remote_addr != null){
			t.put("remote_addr",remote_addr);
		}
		Object x_req = MDC.get(LogConst.X_REQ_ID);
		if(x_req != null){
			t.put(LogConst.X_REQ_ID,x_req);
		}
		if(session!=null){//並入登陸信息
			if(session.company != null){
				t.put("pk_company", session.company.company_id);//有可能會出錯
				t.put("code_company", session.company.company_code);
				t.put("name_company", session.company.company_name);
			}
			t.put("code_account", session.account_code);
			t.put("name_account", session.account_name);
			t.put("pk_account", session.account_id);
			if(StringUtils.isBlank(session.ip)){//如果為空就去取來自攔截器的
				t.put("ip",MDC.get(LogConst.REMOTE_ADDR));
			}else{
				t.put("ip", session.ip);
			}
			t.put("ts_crt", new Timestamp(System.currentTimeMillis()));
		}
		operations.save(t,getCollCode());//查詢的時候,你就費點勁
	} catch (Exception e) {
		ErrorBuilder.process(e);
	}
}
 
開發者ID:noc0der,項目名稱:uranus,代碼行數:36,代碼來源:OpLogServiceMongoImpl.java

示例11: tryIdentifyUser

import org.apache.log4j.MDC; //導入方法依賴的package包/類
private String tryIdentifyUser() {
	String userName = tryGetUserName();
	if (userName != null) {
		return userName;
	}

	// NOTE: That is actually very questionable part. We're assuming ip might be in
	// MDC under some hardcoded key... 
	Object ip = MDC.get("x_ip");
	if (ip != null) {
		return String.valueOf(ip);
	}

	return null;
}
 
開發者ID:skarpushin,項目名稱:summerb,代碼行數:16,代碼來源:RollingFileAppenderRecurringExcSkip.java

示例12: append

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Override
public void append(LoggingEvent event) {
    Object value = MDC.get(FILE_NAMES);
    if (value != null) {
        Collection<String> names = (Collection<String>) value;
        for (String fileName : names) {
            append(fileName, event);
        }
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:11,代碼來源:MultipleFileAppender.java

示例13: append

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Override
public void append(LoggingEvent event) {
    Object value = MDC.get(FILE_NAME);
    if (value != null) {
        append(value.toString(), event);
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:8,代碼來源:FileAppender.java

示例14: getMDC

import org.apache.log4j.MDC; //導入方法依賴的package包/類
/**
    Returns the the context corresponding to the <code>key</code>
    parameter. If there is a local MDC copy, possibly because we are
    in a logging server or running inside AsyncAppender, then we
    search for the key in MDC copy, if a value is found it is
    returned. Otherwise, if the search in MDC copy returns a null
    result, then the current thread's <code>MDC</code> is used.
    
    <p>Note that <em>both</em> the local MDC copy and the current
    thread's MDC are searched.

*/
public
Object getMDC(String key) {
  Object r;
  // Note the mdcCopy is used if it exists. Otherwise we use the MDC
  // that is associated with the thread.
  if(mdcCopy != null) {
    r = mdcCopy.get(key);
    if(r != null) {
      return r;
    }
  }
  return MDC.get(key);
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:26,代碼來源:LogEvent.java

示例15: newScope

import org.apache.log4j.MDC; //導入方法依賴的package包/類
@Override
public Scope newScope(TraceContext currentSpan) {
  final Object previousTraceId = MDC.get("traceId");
  final Object previousSpanId = MDC.get("spanId");
  final Object previousParentId = MDC.get("parentId");

  if (currentSpan != null) {
    MDC.put("traceId", currentSpan.traceIdString());
    MDC.put("spanId", HexCodec.toLowerHex(currentSpan.spanId()));
    if (currentSpan.parentId() != null) {
      MDC.put("parentId", HexCodec.toLowerHex(currentSpan.parentId()));
    }
  } else {
    MDC.remove("traceId");
    MDC.remove("spanId");
    MDC.remove("parentId");
  }

  Scope scope = delegate.newScope(currentSpan);
  class MDCCurrentTraceContextScope implements Scope {
    @Override
    public void close() {
      scope.close();
      if (previousTraceId != null) {
        MDC.put("traceId", previousTraceId);
      } else {
        MDC.remove("traceId");
      }

      if (previousSpanId != null) {
        MDC.put("spanId", previousSpanId);
      } else {
        MDC.remove("spanId");
      }

      if (previousParentId != null) {
        MDC.put("parentId", previousParentId);
      } else {
        MDC.remove("parentId");
      }
    }
  }
  return new MDCCurrentTraceContextScope();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:45,代碼來源:TraceContextConfig.java


注:本文中的org.apache.log4j.MDC.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。