当前位置: 首页>>代码示例>>Java>>正文


Java LoggingEvent.getNDC方法代码示例

本文整理汇总了Java中org.apache.log4j.spi.LoggingEvent.getNDC方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.getNDC方法的具体用法?Java LoggingEvent.getNDC怎么用?Java LoggingEvent.getNDC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.spi.LoggingEvent的用法示例。


在下文中一共展示了LoggingEvent.getNDC方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: format

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public String format(LoggingEvent event)
{
    Map<String,Object> map = new TreeMap<String,Object>();
    map.put("timestamp",    new Date(event.getTimeStamp()));
    map.put("thread",       event.getThreadName());
    map.put("logger",       event.getLogger().getName());
    map.put("level",        event.getLevel().toString());
    map.put("message",      event.getRenderedMessage());

    if (event.getThrowableStrRep() != null) map.put("exception",    event.getThrowableStrRep());
    if (event.getNDC() != null)             map.put("ndc",          event.getNDC());
    if (tags != null)                       map.put("tags",         tags);

    if ((event.getProperties() != null) && ! event.getProperties().isEmpty())
    {
        map.put("mdc", event.getProperties());
    }


    if (processId != null)  map.put("processId", processId);
    if (hostname != null)   map.put("hostname", hostname);
    if (instanceId != null) map.put("instanceId", instanceId);

    if (enableLocation)
    {
        LocationInfo info = event.getLocationInformation();
        Map<String,Object> location = new TreeMap<String,Object>();
        location.put("className",  info.getClassName());
        location.put("methodName", info.getMethodName());
        location.put("fileName",   info.getFileName());
        location.put("lineNumber", info.getLineNumber());
        map.put("locationInfo", location);
    }

    return converterTL.get().convert(map);
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:38,代码来源:JsonLayout.java

示例2: defaultLogFormat

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
static private Object defaultLogFormat(LoggingEvent loggingEvent) {

        LoggingEventX eventX = new LoggingEventX(loggingEvent.getFQNOfLoggerClass(), loggingEvent.getLogger()
                , loggingEvent.getTimeStamp(), loggingEvent.getLevel(), loggingEvent.getMessage(),
                loggingEvent.getThreadName(), loggingEvent.getThrowableInformation(), loggingEvent.getNDC(),
                loggingEvent.getLocationInformation(), loggingEvent.getProperties());

        eventX.setLogTime(new Date(loggingEvent.getTimeStamp()));
        eventX.setLogLevel(eventX.getLevel().toString());
        return eventX;
    }
 
开发者ID:Crab2died,项目名称:log4j-redis-appender,代码行数:12,代码来源:RedisAppender.java

示例3: format

import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public String format(LoggingEvent event)
{
	if( sbuf.capacity() > 1024 )
	{
		sbuf = new StringBuilder(256);
	}
	else
	{
		sbuf.setLength(0);
	}
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<tr>");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<td>");
	sbuf.append(dateFormat.format(new Date(event.timeStamp)));
	sbuf.append("</td>");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<td>");
	if( event.getLevel().equals(Level.DEBUG) )
	{
		sbuf.append("<font color=\"#339933\">");
		sbuf.append(event.getLevel());
		sbuf.append("</font>");
	}
	else if( event.getLevel().isGreaterOrEqual(Level.WARN) )
	{
		sbuf.append("<font color=\"#993300\"><strong>");
		sbuf.append(event.getLevel());
		sbuf.append("</strong></font>");
	}
	else
	{
		sbuf.append(event.getLevel());
	}
	sbuf.append("</td>");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<td>");
	sbuf.append(Transform.escapeTags(event.getLoggerName()));
	sbuf.append("</td>");
	sbuf.append(Layout.LINE_SEP);
	if( locationInfo )
	{
		LocationInfo locInfo = event.getLocationInformation();
		sbuf.append("<td>");
		sbuf.append(Transform.escapeTags(locInfo.getFileName()));
		sbuf.append(':');
		sbuf.append(locInfo.getLineNumber());
		sbuf.append("</td>");
		sbuf.append(Layout.LINE_SEP);
	}
	sbuf.append("<td>");
	sbuf.append(Transform.escapeTags(event.getRenderedMessage()));
	sbuf.append("</td>");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("</tr>");
	sbuf.append(Layout.LINE_SEP);
	if( event.getNDC() != null )
	{
		sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">");
		sbuf.append("NDC: ");
		sbuf.append(Transform.escapeTags(event.getNDC()));
		sbuf.append("</td></tr>");
		sbuf.append(Layout.LINE_SEP);
	}
	String s[] = event.getThrowableStrRep();
	if( s != null )
	{
		sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : xx-small;\" colspan=\"6\">");
		appendThrowableAsHTML(s, sbuf);
		sbuf.append("</td></tr>");
		sbuf.append(Layout.LINE_SEP);
	}
	return sbuf.toString();
}
 
开发者ID:equella,项目名称:Equella,代码行数:76,代码来源:HTMLLayout2.java


注:本文中的org.apache.log4j.spi.LoggingEvent.getNDC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。