Package org.apache.log4j.spi

Examples of org.apache.log4j.spi.LocationInfo


        assertThat(events.size(), equalTo(5));
        LoggingEvent event = events.get(0);
        assertThat(event, notNullValue());
        assertThat(event.getLevel(), equalTo(Level.ERROR));
        assertThat(event.getRenderedMessage(), equalTo("This is an error"));
        LocationInfo locationInfo = event.getLocationInformation();
        assertThat(locationInfo, notNullValue());
        assertThat(locationInfo.getClassName(), equalTo(Log4jESLoggerTests.class.getCanonicalName()));
        assertThat(locationInfo.getMethodName(), equalTo("locationInfoTest"));
        event = events.get(1);
        assertThat(event, notNullValue());
        assertThat(event.getLevel(), equalTo(Level.WARN));
        assertThat(event.getRenderedMessage(), equalTo("This is a warning"));
        locationInfo = event.getLocationInformation();
        assertThat(locationInfo, notNullValue());
        assertThat(locationInfo.getClassName(), equalTo(Log4jESLoggerTests.class.getCanonicalName()));
        assertThat(locationInfo.getMethodName(), equalTo("locationInfoTest"));
        event = events.get(2);
        assertThat(event, notNullValue());
        assertThat(event.getLevel(), equalTo(Level.INFO));
        assertThat(event.getRenderedMessage(), equalTo("This is an info"));
        locationInfo = event.getLocationInformation();
        assertThat(locationInfo, notNullValue());
        assertThat(locationInfo.getClassName(), equalTo(Log4jESLoggerTests.class.getCanonicalName()));
        assertThat(locationInfo.getMethodName(), equalTo("locationInfoTest"));
        event = events.get(3);
        assertThat(event, notNullValue());
        assertThat(event.getLevel(), equalTo(Level.DEBUG));
        assertThat(event.getRenderedMessage(), equalTo("This is a debug"));
        locationInfo = event.getLocationInformation();
        assertThat(locationInfo, notNullValue());
        assertThat(locationInfo.getClassName(), equalTo(Log4jESLoggerTests.class.getCanonicalName()));
        assertThat(locationInfo.getMethodName(), equalTo("locationInfoTest"));
        event = events.get(4);
        assertThat(event, notNullValue());
        assertThat(event.getLevel(), equalTo(Level.TRACE));
        assertThat(event.getRenderedMessage(), equalTo("This is a trace"));
        locationInfo = event.getLocationInformation();
        assertThat(locationInfo, notNullValue());
        assertThat(locationInfo.getClassName(), equalTo(Log4jESLoggerTests.class.getCanonicalName()));
        assertThat(locationInfo.getMethodName(), equalTo("locationInfoTest"));
       
    }
View Full Code Here


      jsonGen.writeStringField(fieldMessage, event.getMessage()
          .toString());
    }

    if (shouldInclude(fieldFile)) {
      final LocationInfo location = event.getLocationInformation();
      jsonGen.writeStringField(fieldFile, location.getFileName());
    }

    if (shouldInclude(fieldClass)) {
      final LocationInfo location = event.getLocationInformation();
      jsonGen.writeStringField(fieldClass, location.getClassName());
    }

    if (shouldInclude(fieldMethod)) {
      final LocationInfo location = event.getLocationInformation();
      jsonGen.writeStringField(fieldMethod, location.getMethodName());
    }

    if (shouldInclude(fieldLine)) {
      final LocationInfo location = event.getLocationInformation();
      jsonGen.writeStringField(fieldLine, location.getLineNumber());
    }

  }
View Full Code Here

      text.append("/");
      text.append(event.getThreadName());
    }

    if (mask.contains(FILE_NAME)) {
      final LocationInfo location = event.getLocationInformation();
      text.append("/");
      text.append(location.getFileName());
    }

    if (mask.contains(CLASS_NAME)) {
      final LocationInfo location = event.getLocationInformation();
      text.append("/");
      text.append(location.getClassName());
    }

    if (mask.contains(METHOD_NAME)) {
      final LocationInfo location = event.getLocationInformation();
      text.append("/");
      text.append(location.getMethodName());
    }

    if (mask.contains(LINE_NUMBER)) {
      final LocationInfo location = event.getLocationInformation();
      text.append("/");
      text.append(location.getLineNumber());
    }

    if (mask.contains(STACK_TRACE)) {
      final String[] stackArray = event.getThrowableStrRep();
      if (stackArray != null) {
View Full Code Here

    buffer.append("<td title=\"" + escapedLogger + " category\">");
    buffer.append(escapedLogger);
    buffer.append("</td>" + Layout.LINE_SEP);

    if (this.locationInfo) {
      LocationInfo locInfo = event.getLocationInformation();
      buffer.append("<td>");
      buffer.append(Transform.escapeTags(locInfo.getFileName()));
      buffer.append(':');
      buffer.append(locInfo.getLineNumber());
      buffer.append("</td>" + Layout.LINE_SEP);
    }
    buffer.append("<td title=\"Message\">");
    buffer.append(Transform.escapeTags(event.getRenderedMessage()));
    buffer.append("</td>" + Layout.LINE_SEP);
View Full Code Here

     * @param wrapperClassName
     *            - The wrapper that indicates the caller
     * @return the location information
     */
    public LocationInfo getLocationInfo(Class wrapperClassName) {
        LocationInfo locationInfo = null;

        try {
            if (stackLocal.get() == null) {
                stackLocal.set(this.getStackTraceElement(wrapperClassName));
            }

            locationInfo = new LocationInfo(stackLocal.get().getFileName(),
                    stackLocal.get().getClassName(), stackLocal.get()
                            .getMethodName(), stackLocal.get().getLineNumber()
                            + "");
        } catch (Throwable e) {
            if (CONFIGURATION
View Full Code Here

        // If the event is not the same, clear the cache
        if (event != loggingEvent.get()) {
            loggingEvent.set(event);
            clearLocationInfo();
        }
        LocationInfo locationInfo = null;
        try {
            locationInfo = (LocationInfo) LoggingContext
                    .getInstance()
                    .getLocationInfo(Class.forName(event.getFQNOfLoggerClass()));
            if (locationInfo != null) {
View Full Code Here

        }
        // For async appenders, the locationInfo is set in the MDC and not with
        // the thread since the thread that processes the logging is different
        // from the one that
        // generates location information.
        LocationInfo locationInfo = (LocationInfo) event.getMDC(LOCATION_INFO);
        if (locationInfo == null) {
            locationInfo = this.generateLocationInfo(event);
        }

        return locationInfo;
View Full Code Here

      this.type = type;
    }

    @Override
    public String convert(LoggingEvent event) {
        LocationInfo locationInfo = LoggingContext.getInstance().getLocationInfo(event);
        if (locationInfo == null) {
            return "";
        }
        switch (type) {
        case 'M':
            return locationInfo.getMethodName();
        case 'c':
            return event.getLoggerName();
        case 'C':
            return locationInfo.getClassName();
        case 'L':
            return locationInfo.getLineNumber();
        case 'l':
            return (locationInfo.getFileName() + ":"
                    + locationInfo.getClassName() + " "
                    + locationInfo.getLineNumber() + " " + locationInfo
                    .getMethodName());
        case 'F':
            return locationInfo.getFileName();
        }
        return "";
       
    }
View Full Code Here

     */
    public void append(final LoggingEvent event) {
        boolean isBufferSpaceAvailable = (batcher.isSpaceAvailable() && (logSummaryMap
                .size() == 0));
        boolean isBufferPutSuccessful = false;
        LocationInfo locationInfo = null;
        // Reject it when we have a fast property as these can be expensive
        Stopwatch s = locationInfoTimer.start();
        if (CONFIGURATION.shouldSummarizeOverflow(this.originalAppenderName)) {
            if (CONFIGURATION.shouldGenerateBlitz4jLocationInfo()) {
                locationInfo = LoggingContext.getInstance()
                        .generateLocationInfo(event);
            } else if (CONFIGURATION.shouldGenerateLog4jLocationInfo()) {
                locationInfo = event.getLocationInformation();
            }
        }
        s.stop();

        if (isBufferSpaceAvailable) {
            // Save the thread local info in the event so that the
            // processing threads can have access to the thread local of the arriving event
            Stopwatch sThreadLocal = saveThreadLocalTimer.start();
            saveThreadLocalInfo(event);
            sThreadLocal.stop();
            isBufferPutSuccessful = putInBuffer(event);
        }
        // If the buffer is full, then summarize the information
        if (CONFIGURATION.shouldSummarizeOverflow(this.originalAppenderName) && (!isBufferPutSuccessful)) {
           DynamicCounter.increment(this.originalAppenderName
                    + "_summarizeEvent");
            Stopwatch t = putDiscardMapTimeTracer.start();
            String loggerKey = event.getLoggerName();
            if (locationInfo != null) {
                loggerKey = locationInfo.getClassName() + "_"
                        + locationInfo.getLineNumber();
            }

            LogSummary summary = (LogSummary) logSummaryMap.get(loggerKey);
            if (summary == null) {
                // Saving the thread local info is needed only for the first
View Full Code Here

          @SuppressWarnings("unchecked")
          Set<Entry<?,?>> entrySet = props.entrySet();
          for (Entry<?, ?> entry : entrySet) {
            amqpProps.setHeader(entry.getKey().toString(), entry.getValue());
          }
          LocationInfo locInfo = logEvent.getLocationInformation();
          if (!"?".equals(locInfo.getClassName())) {
            amqpProps.setHeader(
                "location",
                String.format("%s.%s()[%s]", locInfo.getClassName(), locInfo.getMethodName(),
                    locInfo.getLineNumber()));
          }

          StringBuilder msgBody;
          String routingKey;
          synchronized (layoutMutex) {
View Full Code Here

TOP

Related Classes of org.apache.log4j.spi.LocationInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.