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


Java LocationInfo类代码示例

本文整理汇总了Java中org.apache.log4j.spi.LocationInfo的典型用法代码示例。如果您正苦于以下问题:Java LocationInfo类的具体用法?Java LocationInfo怎么用?Java LocationInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testLocationInfoNoFQCN

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
   * Tests LoggingEvent.getLocationInfo() when no FQCN is specified.
   * See bug 41186.
   */
public void testLocationInfoNoFQCN() {
    Category root = Logger.getRootLogger();
 Priority level = Level.INFO;
    LoggingEvent event =
      new LoggingEvent(
        null, root, 0L,  level, "Hello, world.", null);
    LocationInfo info = event.getLocationInformation();
 //
 //  log4j 1.2 returns an object, its layout doesn't check for nulls.
 //  log4j 1.3 returns a null.
 //
 assertNotNull(info);
 if (info != null) {
    assertEquals("?", info.getLineNumber());
 assertEquals("?", info.getClassName());
 assertEquals("?", info.getFileName());
 assertEquals("?", info.getMethodName());
 }
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:LoggingEventTest.java

示例2: testEventLogger

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
public void testEventLogger() {
    EventData data[] = new EventData[2];
    data[0] = new EventData();
    data[0].setEventType("Login");
    data[0].setEventId("1");
    data[0].setEventDateTime(new Date());
    data[0].put("Userid", "TestUser");
    EventLogger.logEvent(data[0]);

    data[1] = new EventData();
    data[1].setEventType("Update");
    data[1].setEventId("2");
    data[1].setEventDateTime(new Date());
    data[1].put("FileName", "/etc/hosts");
    EventLogger.logEvent(data[1]);

    assertEquals(2, listAppender.list.size());
    for (int i = 0; i < 2; ++i) {
        LoggingEvent event = listAppender.list.get(i);
        verify(event, data[i].toXML());
        LocationInfo li = event.getLocationInformation();
        assertEquals(this.getClass().getName(), li.getClassName());
        assertEquals(event.getMDC("hostname"), "localhost");
    }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:26,代码来源:EventLoggerTest.java

示例3: testSmoke

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
public void testSmoke() {
    SLF4JBridgeHandler.install();
    String msg = "msg";
    julLogger.info(msg);
    assertEquals(1, listAppender.list.size());
    LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
    assertEquals(LOGGER_NAME, le.getLoggerName());
    assertEquals(msg, le.getMessage());

    // get the location info in the event.
    // Note that this must have been computed previously
    // within an appender for the following assertion to
    // work properly
    LocationInfo li = le.getLocationInformation();
    System.out.println(li.fullInfo);
    assertEquals("SLF4JBridgeHandlerTest.java", li.getFileName());
    assertEquals("testSmoke", li.getMethodName());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:19,代码来源:SLF4JBridgeHandlerTest.java

示例4: createLogSourceEvent

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
private JSONObject createLogSourceEvent(LoggingEvent loggingEvent, HostData host) {
    JSONObject logSourceEvent = new JSONObject();
    if (locationInfo) {
        LocationInfo info = loggingEvent.getLocationInformation();
        logSourceEvent.put(LayoutFields.FILE_NAME, info.getFileName());
        logSourceEvent.put(LayoutFields.LINE_NUMBER, info.getLineNumber());
        logSourceEvent.put(LayoutFields.CLASS_NAME, info.getClassName());
        logSourceEvent.put(LayoutFields.METHOD_NAME, info.getMethodName());
        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        String jvmName = runtimeBean.getName();
        logSourceEvent.put(LayoutFields.PROCESS_ID, Long.valueOf(jvmName.split("@")[0]));
    }
    logSourceEvent.put(LayoutFields.LOGGER_NAME, loggingEvent.getLoggerName());
    logSourceEvent.put(LayoutFields.HOST_NAME, host.getHostName());
    logSourceEvent.put(LayoutFields.HOST_IP, host.getHostAddress());
    return logSourceEvent;
}
 
开发者ID:Talend,项目名称:daikon,代码行数:18,代码来源:Log4jJSONLayout.java

示例5: testGetStackifyErrorWithoutException

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
 * testGetStackifyErrorWithoutException
 */
@Test
public void testGetStackifyErrorWithoutException() {
	LocationInfo locInfo = Mockito.mock(LocationInfo.class);
	Mockito.when(locInfo.getClassName()).thenReturn("class");
	Mockito.when(locInfo.getMethodName()).thenReturn("method");
	Mockito.when(locInfo.getLineNumber()).thenReturn("123");
	
	LoggingEvent event = Mockito.mock(LoggingEvent.class);
	Mockito.when(event.getMessage()).thenReturn("Exception message");
	Mockito.when(event.getLocationInformation()).thenReturn(locInfo);
	
	LoggingEventAdapter adapter = new LoggingEventAdapter(Mockito.mock(EnvironmentDetail.class));
	StackifyError error = adapter.getStackifyError(event, null);
	
	Assert.assertNotNull(error);
	Assert.assertEquals("StringException", error.getError().getErrorType());
}
 
开发者ID:stackify,项目名称:stackify-log-log4j12,代码行数:21,代码来源:LoggingEventAdapterTest.java

示例6: testGetClassName

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
 * testGetClassName
 */
@Test
public void testGetClassName() {
	LocationInfo locInfo = Mockito.mock(LocationInfo.class);
	Mockito.when(locInfo.getClassName()).thenReturn("class");
	
	LoggingEvent event = Mockito.mock(LoggingEvent.class);
	Mockito.when(event.getLocationInformation()).thenReturn(locInfo);
	
	LoggingEventAdapter adapter = new LoggingEventAdapter(Mockito.mock(EnvironmentDetail.class));

	String className = adapter.getClassName(event);
	
	Assert.assertNotNull(className);
	Assert.assertEquals("class", className);
}
 
开发者ID:stackify,项目名称:stackify-log-log4j12,代码行数:19,代码来源:LoggingEventAdapterTest.java

示例7: getLocationInformation

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
@Override
public LocationInfo getLocationInformation() {
    if (this.locationInfo == null) {
        // HACK: Use preprocessor information
        String msg = this.event.getMessage().toString();
        Matcher m = PREPROCESSOR_PATTERN.matcher(msg);
        if (LOG.isDebugEnabled()) LOG.debug("Checking whether we can use PREPROCESSOR info for location: " + msg);
        
        if (m.find()) {
            if (LOG.isDebugEnabled()) LOG.debug("Using preprocessor information get source location [" + m + "]");
            
            String fileName = m.group(1);
            int lineNumber = Integer.parseInt(m.group(2));
            this.locationInfo = new FastLocationInfo(lineNumber, fileName, "", "");
            this.cleanMessage = m.replaceFirst("");
        } else {
            if (LOG.isDebugEnabled()) LOG.debug("Using stack offset lookup to get source location");
            StackTraceElement stack[] = Thread.currentThread().getStackTrace();
//            System.err.println(String.format("Stack=%d / Offset=%d", stack.length, this.stackOffset));
            if (this.stackOffset < stack.length) {
//                for (int i = 0; i < stack.length; i++) {
//                    System.err.printf("[%02d] %s\n", i, stack[i]);
//                }
                this.locationInfo = new FastLocationInfo(stack[this.stackOffset].getLineNumber(),
                                                         stack[this.stackOffset].getFileName(),
                                                         stack[this.stackOffset].getClassName(),
                                                         stack[this.stackOffset].getMethodName());
            }
        }
    }
    return (this.locationInfo);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:33,代码来源:FastLoggingEvent.java

示例8: testLocationInfo

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
 * testLocationInfo
 */
public void testLocationInfo() throws Exception {
    LocationInfo expected = this.origEvent.getLocationInformation();
    assertNotNull(expected);
    
    LocationInfo actual = this.fastEvent.getLocationInformation();
    assertNotNull(actual);
    System.err.println(this.fastEvent.getLocationInformation());
    
    assertEquals(expected.getLineNumber(), actual.getLineNumber());
    assertEquals(expected.getFileName(), actual.getFileName());
    assertEquals(expected.getClassName(), actual.getClassName());
    assertEquals(expected.getMethodName(), actual.getMethodName());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:17,代码来源:TestFastLoggingEvent.java

示例9: testPreProcessorLocationInfo

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
 * testPreProcessorLocationInfo
 */
public void testPreProcessorLocationInfo() {
    String fileName = "ExecutionSite.java";
    String lineNum = "1958";
    String msg = "Dispatching 1 messages and waiting for the results for InsertCallForwarding #1024611756678316032/0";
    logger.info(String.format("%s:%s %s", fileName, lineNum, msg));
    assertNotNull(fastEvent);
    
    LocationInfo actual = this.fastEvent.getLocationInformation();
    assertNotNull(actual);
    assertEquals(fileName, actual.getFileName());
    assertEquals(lineNum, actual.getLineNumber());
    assertEquals(msg, fastEvent.getMessage());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:17,代码来源:TestFastLoggingEvent.java

示例10: format

import org.apache.log4j.spi.LocationInfo; //导入依赖的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

示例11: getLocationInformation

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
public LocationInfo getLocationInformation() {
            if (location == null) {
                Throwable t = new Throwable();
//                t.printStackTrace();
                location = new LambdaLocation(t);
            }
            return location;
        }
 
开发者ID:blazegraph,项目名称:tinkerpop3,代码行数:9,代码来源:LambdaLogger.java

示例12: format

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
@Override
public String format(LoggingEvent event) {
  BenderLogEntry entry = new BenderLogEntry();
  entry.threadName = event.getThreadName();
  entry.posixTimestamp = event.getTimeStamp();
  entry.timestamp = FORMATTER.print(entry.posixTimestamp);
  entry.message = event.getRenderedMessage();
  entry.level = event.getLevel().toString();
  entry.logger = event.getLogger().getName();
  entry.alias = ALIAS;
  entry.version = VERSION;

  if (event.getThrowableInformation() != null) {
    final ThrowableInformation throwableInfo = event.getThrowableInformation();
    ExceptionLog ex = new ExceptionLog();

    if (throwableInfo.getThrowable().getClass().getCanonicalName() != null) {
      ex.clazz = throwableInfo.getThrowable().getClass().getCanonicalName();
    }
    if (throwableInfo.getThrowable().getMessage() != null) {
      ex.message = throwableInfo.getThrowable().getMessage();
    }
    if (throwableInfo.getThrowableStrRep() != null) {
      Arrays.asList(throwableInfo.getThrowableStrRep()).forEach(m -> {
        ex.stacktrace.add(m.replaceAll("\\t", "   "));
      });
    }
    entry.exception = ex;
  }

  LocationInfo locinfo = event.getLocationInformation();
  entry.file = locinfo.getFileName();
  entry.lineNumber = Integer.parseInt(locinfo.getLineNumber());
  entry.method = locinfo.getMethodName();
  entry.clazz = locinfo.getClassName();

  return GSON.toJson(entry) + "\n";
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:39,代码来源:BenderLayout.java

示例13: convert

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
public
   String convert(LoggingEvent event) {
     LocationInfo locationInfo = event.getLocationInformation();
     switch(type) {
     case FULL_LOCATION_CONVERTER:
return locationInfo.fullInfo;
     case METHOD_LOCATION_CONVERTER:
return locationInfo.getMethodName();
     case LINE_LOCATION_CONVERTER:
return locationInfo.getLineNumber();
     case FILE_LOCATION_CONVERTER:
return locationInfo.getFileName();
     default: return null;
     }
   }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:16,代码来源:PatternParser.java

示例14: testSerializationWithLocation

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
   * Serialize a logging event with an exception and check it against
   * a witness.
   * @throws Exception if exception during test.
   *
   */
  public void testSerializationWithLocation() throws Exception {
    Logger root = Logger.getRootLogger();
    LoggingEvent event =
      new LoggingEvent(
        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
    LocationInfo info = event.getLocationInformation();
//    event.prepareForDeferredProcessing();

    int[] skip = new int[] { 352, 353, 354, 355, 356 };
    SerializationTestHelper.assertSerializationEquals(
      "witness/serialization/location.bin", event, skip, 237);
  }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:LoggingEventTest.java

示例15: format

import org.apache.log4j.spi.LocationInfo; //导入依赖的package包/类
/**
 * Format a logging event.
  * @param event event to format.
 * @param toAppendTo string buffer to which class name will be appended.
 */
public void format(final LoggingEvent event, final StringBuffer toAppendTo) {
  final int initialLength = toAppendTo.length();
  LocationInfo li = event.getLocationInformation();

  if (li == null) {
    toAppendTo.append(LocationInfo.NA);
  } else {
    toAppendTo.append(li.getClassName());
  }

  abbreviate(initialLength, toAppendTo);
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:18,代码来源:ClassNamePatternConverter.java


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