Java Code Examples for org.apache.log4j.spi.LocationInfo#getMethodName()

The following examples show how to use org.apache.log4j.spi.LocationInfo#getMethodName() . 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: Console.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
protected void append(LoggingEvent evt) {
	if (stream.isClosed())
		return;
	String message;
	if (evt.getLevel().toInt() <= Level.DEBUG_INT) {
		LocationInfo info = evt.getLocationInformation();
		message = "" + evt.getLevel().toString()
				+ " [" + DateFormatUtils.format(evt.timeStamp, "HH:mm:ss.SS") + "]"
				+ " @" + info.getClassName()
				+ ">" + info.getMethodName()
				+ ">" + info.getLineNumber()
				+ " - " + evt.getMessage();
	} else {
		message = "" + evt.getLevel().toString()
				+ " - " + evt.getMessage();
	}
	tryPrintMessage(message, evt.getThrowableInformation());
}
 
Example 2
Source File: BenderLayout.java    From bender with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example 3
Source File: PatternParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
     }
   }
 
Example 4
Source File: PropertyRewritePolicy.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public LoggingEvent rewrite(final LoggingEvent source) {
    if (!properties.isEmpty()) {
        Map<String, String> rewriteProps = source.getProperties() != null ? new HashMap<>(source.getProperties())
                : new HashMap<>();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            if (!rewriteProps.containsKey(entry.getKey())) {
                rewriteProps.put(entry.getKey(), entry.getValue());
            }
        }
        LogEvent event;
        if (source instanceof LogEventAdapter) {
            event = new Log4jLogEvent.Builder(((LogEventAdapter) source).getEvent())
                    .setContextData(new SortedArrayStringMap(rewriteProps))
                    .build();
        } else {
            LocationInfo info = source.getLocationInformation();
            StackTraceElement element = new StackTraceElement(info.getClassName(), info.getMethodName(),
                    info.getFileName(), Integer.parseInt(info.getLineNumber()));
            Thread thread = getThread(source.getThreadName());
            long threadId = thread != null ? thread.getId() : 0;
            int threadPriority = thread != null ? thread.getPriority() : 0;
            event = Log4jLogEvent.newBuilder()
                    .setContextData(new SortedArrayStringMap(rewriteProps))
                    .setLevel(OptionConverter.convertLevel(source.getLevel()))
                    .setLoggerFqcn(source.getFQNOfLoggerClass())
                    .setMarker(null)
                    .setMessage(new SimpleMessage(source.getRenderedMessage()))
                    .setSource(element)
                    .setLoggerName(source.getLoggerName())
                    .setThreadName(source.getThreadName())
                    .setThreadId(threadId)
                    .setThreadPriority(threadPriority)
                    .setThrown(source.getThrowableInformation().getThrowable())
                    .setTimeMillis(source.getTimeStamp())
                    .setNanoTime(0)
                    .setThrownProxy(null)
                    .build();
        }
        return new LogEventAdapter(event);
    }
    return source;
}
 
Example 5
Source File: LogEventWrapper.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public StackTraceElement getSource() {
    LocationInfo info = event.getLocationInformation();
    return new StackTraceElement(info.getClassName(), info.getMethodName(), info.getFileName(),
            Integer.parseInt(info.getLineNumber()));
}