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


Java ThrowableInformation.getThrowableStrRep方法代碼示例

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


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

示例1: getThrowableRepresentationFromLoggingEvent

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Extracts Stack trace of Throwable contained in LogginEvent, if there is
 * any
 * 
 * @param aLoggingEvent
 *            logging event
 * @return stack trace of throwable
 */
public String getThrowableRepresentationFromLoggingEvent(LoggingEvent aLoggingEvent) {
	// extract throwable information from loggingEvent if available
	ThrowableInformation throwableinfo = aLoggingEvent.getThrowableInformation();
	StringBuffer throwableStringBuffer = new StringBuffer();

	if (throwableinfo != null) {
		String[] lines = throwableinfo.getThrowableStrRep();
		for (int index = 0; index < lines.length; index++) {
			throwableStringBuffer = (StringBuffer) throwableStringBuffer.append(lines[index]
					+ "\r\n");
		}
	}
	String result = quotedString(throwableStringBuffer.toString());
	if (this.getThrowableMaxChars() != -1 && result.length() > this.getThrowableMaxChars()) {
		result = result.substring(0, this.getThrowableMaxChars() - 1);
	}

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

示例2: append

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
@Override
protected void append(final LoggingEvent loggingEvent) {
	final StringBuilder buf = new StringBuilder();
	buf.append(getLayout().format(loggingEvent));
	final ThrowableInformation ti = loggingEvent.getThrowableInformation();

	if (ti != null) {
		final String[] cause = ti.getThrowableStrRep();

		for (final String line : cause) {
			buf.append(line).append('\n');
		}
	}

	j2DClient.get().addEventLine(new HeaderLessEventLine(buf.toString(), NotificationType.CLIENT));
}
 
開發者ID:arianne,項目名稱:stendhal,代碼行數:17,代碼來源:GameConsoleAppender.java

示例3: format

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void format(final LoggingEvent event, final StringBuffer toAppendTo) {
  if (maxLines != 0) {
    ThrowableInformation information = event.getThrowableInformation();

    if (information != null) {
      String[] stringRep = information.getThrowableStrRep();

      int length = stringRep.length;
      if (maxLines < 0) {
          length += maxLines;
      } else if (length > maxLines) {
          length = maxLines;
      }

      for (int i = 0; i < length; i++) {
          String string = stringRep[i];
          toAppendTo.append(string).append("\n");
      }
    }
  }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:25,代碼來源:ThrowableInformationPatternConverter.java

示例4: prepareLoggingEvent

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Prepares the LoggingEvent for beeing processes in another thread, by saving away the NDC, MDC, thread name,  
 * throwable information and location information (if parameter getLocationInformation is true).   
 * 
 * @param loggingEvent the logging event to prepare.
 * @param getLocationInformation flag indicating if location information should be fetched for the logging event.
 * 
 * @since 2.0
 */
public static void prepareLoggingEvent(final LoggingEvent loggingEvent, final boolean getLocationInformation)
{
   // Set the NDC and thread name for the calling thread as these LoggingEvent fields were not set at event creation time.
   loggingEvent.getNDC();
   loggingEvent.getThreadName();
   // Get a copy of this thread's MDC.
   loggingEvent.getMDCCopy();
   ThrowableInformation throwableInformation =  loggingEvent.getThrowableInformation();
   if( throwableInformation != null )
   {
      // Make the ThrowableInformation of the LoggingEvent store away the representation of the stack trace.
      throwableInformation.getThrowableStrRep();
   }
   if( getLocationInformation ) 
   {
      loggingEvent.getLocationInformation();
   }
}
 
開發者ID:tolo,項目名稱:JServer,代碼行數:28,代碼來源:LogManager.java

示例5: exceptionInformation

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Pull out details of exception in a Hashmap (if they exist)
 * 
 * @param loggingEvent
 * @return
 */
protected void exceptionInformation(
        final LoggingEvent loggingEvent) {
    if (loggingEvent.getThrowableInformation() != null) {
        final ThrowableInformation throwableInformation = loggingEvent
                .getThrowableInformation();
        if (throwableInformation.getThrowable().getClass()
                .getCanonicalName() != null) {
            ExceptionField.put(EXCEPTION.CLASS, throwableInformation.getThrowable().getClass()
                    .getCanonicalName());
        }
        if (throwableInformation.getThrowable().getMessage() != null) {
            ExceptionField.put(EXCEPTION.MESSAGE, throwableInformation.getThrowable().getMessage());
        }
        if (throwableInformation.getThrowableStrRep() != null) {
            final String stackTrace = StringUtils.join(
                    throwableInformation.getThrowableStrRep(), "\n");
            ExceptionField.put(EXCEPTION.STACKTRACE, stackTrace);
        }
    }
}
 
開發者ID:stuart-warren,項目名稱:logit,代碼行數:27,代碼來源:Layout.java

示例6: toJson

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    Throwable thrown = ti.getThrowable();
    String eclass = (thrown != null) ?
        thrown.getClass().getName()
        : "";
    json.writeStringField(EXCEPTION_CLASS, eclass);
    String[] stackTrace = ti.getThrowableStrRep();
    json.writeArrayFieldStart(STACK);
    for (String row : stackTrace) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:50,代碼來源:Log4Json.java

示例7: format

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的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

示例8: setThrownStackTrace

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Set stack trace information associated with this Log4JLogRecord.
 * When this method is called, the stack trace in a
 * String-based format is made
 * available via the getThrownStackTrace() method.
 *
 * @param throwableInfo An org.apache.log4j.spi.ThrowableInformation to
 * associate with this Log4JLogRecord.
 * @see #getThrownStackTrace()
 */
public void setThrownStackTrace(ThrowableInformation throwableInfo) {
  String[] stackTraceArray = throwableInfo.getThrowableStrRep();

  StringBuffer stackTrace = new StringBuffer();
  String nextLine;

  for (int i = 0; i < stackTraceArray.length; i++) {
    nextLine = stackTraceArray[i] + "\n";
    stackTrace.append(nextLine);
  }

  _thrownStackTrace = stackTrace.toString();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:Log4JLogRecord.java

示例9: addThrowableInformation

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
  * Adds the ThrowableInformation object to an existing BSON object.
  * 
  * @param bson
  *            The BSON object to add the throwable info to <i>(must not be null)</i>.
  * @param throwableInfo
  *            The ThrowableInformation object to add to the BSON object <i>(may be null)</i>.
  */
 @SuppressWarnings(value = "unchecked")
 protected void addThrowableInformation(Document bson, final ThrowableInformation throwableInfo) {
     if (throwableInfo != null) {
         Throwable currentThrowable = throwableInfo.getThrowable();
         @SuppressWarnings("rawtypes")
         StringBuilder simpleThrowables = new StringBuilder();
List throwables = new BasicDBList();

         while (currentThrowable != null) {
         	Document throwableBson = bsonifyThrowable(currentThrowable, simpleThrowables);

             if (throwableBson != null) {
                 throwables.add(throwableBson);
             }

             currentThrowable = currentThrowable.getCause();
         }

         if (throwables.size() > 0) {
             bson.put(KEY_THROWABLES, throwables);
             bson.put(KEY_STACKTRACES, simpleThrowables.toString());
         } else {
         	simpleThrowables.setLength(0);
         	for(String item : throwableInfo.getThrowableStrRep()){
         		simpleThrowables.append(item).append('\n');
         	}
         	bson.put(KEY_STACKTRACES, simpleThrowables.toString());
         }
     }
 }
 
開發者ID:d0k1,項目名稱:log4jmongo,代碼行數:39,代碼來源:AbstractBsonAppender.java

示例10: createStackTraceEvent

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
private void createStackTraceEvent(JSONObject logstashEvent, LoggingEvent loggingEvent,
        final ThrowableInformation throwableInformation) {
    if (throwableInformation.getThrowableStrRep() != null) {
        final String[] options = { "full" };
        final ThrowableInformationPatternConverter converter = ThrowableInformationPatternConverter.newInstance(options);
        final StringBuffer sb = new StringBuffer();
        converter.format(loggingEvent, sb);
        final String stackTrace = sb.toString();
        logstashEvent.put(LayoutFields.STACK_TRACE, stackTrace);
    }
}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:12,代碼來源:Log4jJSONLayout.java

示例11: addErrorAppender

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Add a usage appender for the root logger. This appender will write ERROR and FATAL log messages 
 * to the usage database.
 */
public static void addErrorAppender() {
	usageAppender = new AppenderSkeleton() {
		boolean logAll = Boolean.getBoolean("logAll");
		PatternLayout patternLayout = new PatternLayout("[%t] %c - %m");
		
		@Override
		protected void append(LoggingEvent event) {
			
			if (logAll || event.getLevel().equals(Level.ERROR) ||
				event.getLevel().equals(Level.FATAL)) {
				ThrowableInformation info = event.getThrowableInformation();
				StringBuffer buf = new StringBuffer();
				if (info == null) buf.append("No stack trace");
				else {
					for (String line : info.getThrowableStrRep())
						buf.append(line).append('\n');
				}

				EnsembleUsageLogger.logUsage(
						event.getLevel().toString(),
						patternLayout.format(event) +" -- "+ buf.toString());
			}
		}
		@Override
		public void close() { /* do nothing */ }
		@Override
		public boolean requiresLayout() { return false;	}
		
	};
	
	Logger.getRootLogger().addAppender(usageAppender);
}
 
開發者ID:nasa,項目名稱:OpenSPIFe,代碼行數:37,代碼來源:EnsembleUsageLogger.java

示例12: format

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void format(final LoggingEvent event, final StringBuffer toAppendTo) {
	final ThrowableInformation information = event.getThrowableInformation();

	if (information != null) {
		final String[] stringRep = information.getThrowableStrRep();

		int length = 0;

		if (option == null) {
			length = stringRep.length;
		} else if ("full".equals(option)) {
			length = stringRep.length;
		} else if ("short".equals(option)) {
			length = -1;
		} else if ("none".equals(option)) {
			return;
		} else {
			length = stringRep.length;
		}

		toAppendTo.append("\n[Exception: ");

		if (length == -1) {
			toAppendTo.append(generateAbbreviatedExceptionMessage(information.getThrowable()));
		} else {
			for (int i = 0; i < length; i++) {
				final String string = stringRep[i];
				toAppendTo.append(string).append('\n');
			}
		}

		toAppendTo.append("]");
	}
}
 
開發者ID:foundation-runtime,項目名稱:logging,代碼行數:39,代碼來源:FoundationLoggingThrowableInformationPatternConverter.java

示例13: encodeToMap

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
/**
 * Encodes a LoggingEvent into a HashMap using the logstash JSON format.
 * 
 * @param loggingEvent
 *          The LoggingEvent to encode.
 * @param includeLocationInfo
 *          Whether to include LocationInfo in the map, or not.
 * @return A Map representing the LoggingEvent, which is suitable to be
 *         serialized by a JSON encoder such as Jackson.
 */
@SuppressWarnings("rawtypes")
public static Map<String, Object> encodeToMap(LoggingEvent loggingEvent, boolean includeLocationInfo) {
  Map<String, Object> logstashEvent = new LoggingEventMap();
  String threadName = loggingEvent.getThreadName();
  long timestamp = loggingEvent.getTimeStamp();
  HashMap<String, Object> exceptionInformation = new HashMap<String, Object>();
  Map mdc = loggingEvent.getProperties();
  String ndc = loggingEvent.getNDC();

  logstashEvent.put("@version", VERSION);
  logstashEvent.put("@timestamp", dateFormat(timestamp));
  logstashEvent.put("source_host", getHostname());
  logstashEvent.put("message", loggingEvent.getRenderedMessage());

  if (loggingEvent.getThrowableInformation() != null) {
    final ThrowableInformation throwableInformation = loggingEvent.getThrowableInformation();
    if (throwableInformation.getThrowable().getClass().getCanonicalName() != null) {
      exceptionInformation.put("exception_class", throwableInformation.getThrowable().getClass().getCanonicalName());
    }
    if (throwableInformation.getThrowable().getMessage() != null) {
      exceptionInformation.put("exception_message", throwableInformation.getThrowable().getMessage());
    }
    if (throwableInformation.getThrowableStrRep() != null) {
      StringBuilder stackTrace = new StringBuilder();
      for (String line : throwableInformation.getThrowableStrRep()) {
        stackTrace.append(line);
        stackTrace.append("\n");
      }
      exceptionInformation.put("stacktrace", stackTrace);
    }
    logstashEvent.put("exception", exceptionInformation);
  }

  if (includeLocationInfo) {
    LocationInfo info = loggingEvent.getLocationInformation();
    logstashEvent.put("file", info.getFileName());
    logstashEvent.put("line_number", info.getLineNumber());
    logstashEvent.put("class", info.getClassName());
    logstashEvent.put("method", info.getMethodName());
  }

  logstashEvent.put("logger_name", loggingEvent.getLoggerName());
  logstashEvent.put("mdc", mdc);
  logstashEvent.put("ndc", ndc);
  logstashEvent.put("level", loggingEvent.getLevel().toString());
  logstashEvent.put("thread_name", threadName);

  return logstashEvent;
}
 
開發者ID:apache,項目名稱:samza,代碼行數:60,代碼來源:LoggingEventJsonSerde.java

示例14: append

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
@Override
protected void append(LoggingEvent event) {
	String modifiedMessage = event.getMessage().toString();
	if (maxMessageLength >= 0
			&& modifiedMessage.length() > maxMessageLength) {
		modifiedMessage = modifiedMessage.substring(0, maxMessageLength) + "...(" + (modifiedMessage.length() - maxMessageLength) + " characters more)";
	}

	String throwableStrReps[] = null;
	ThrowableInformation throwableInfo = event.getThrowableInformation();
	if (throwableInfo!=null) {
		throwableStrReps = throwableInfo.getThrowableStrRep();
	}

	if (StringUtils.isNotEmpty(hideRegex)) {
		modifiedMessage = Misc.hideAll(modifiedMessage, hideRegex);

		if (throwableStrReps!=null) {
			for (int i=0; i<throwableStrReps.length; i++) {
				throwableStrReps[i] = Misc.hideAll(throwableStrReps[i], hideRegex);
			}
		}
	}

	String threadHideRegex = LogUtil.getThreadHideRegex();
	if (StringUtils.isNotEmpty(threadHideRegex)) {
		modifiedMessage = Misc.hideAll(modifiedMessage, threadHideRegex);

		if (throwableStrReps!=null) {
			for (int i=0; i<throwableStrReps.length; i++) {
				throwableStrReps[i] = Misc.hideAll(throwableStrReps[i], threadHideRegex);
			}
		}
	}
	
	LoggingEvent modifiedEvent = new LoggingEvent(
			event.getFQNOfLoggerClass(), event.getLogger(),
			event.getTimeStamp(), event.getLevel(), modifiedMessage,
			event.getThreadName(), new ThrowableInformation(throwableStrReps),
			event.getNDC(), event.getLocationInformation(),
			event.getProperties());

	synchronized (appenders) {
		for (Appender appender : appenders) {
			appender.doAppend(modifiedEvent);
		}
	}
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:49,代碼來源:IbisAppenderWrapper.java

示例15: appendException

import org.apache.log4j.spi.ThrowableInformation; //導入方法依賴的package包/類
private boolean appendException(StringBuilder buf, LoggingEvent event) {
    ThrowableInformation throwableInfo = event.getThrowableInformation();
    if (throwableInfo == null) {
        return false;
    }

    appendQuotedName(buf, Field.EXCEPTION.val);
    buf.append(":{");

    boolean hasPrevField = false;

    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
    Throwable throwable = throwableInfo.getThrowable();
    if (throwable != null) {
        String message = throwable.getMessage();
        if (message != null) {
            appendField(buf, ExceptionField.MESSAGE.val, message);
            hasPrevField = true;
        }

        String className = throwable.getClass().getCanonicalName();
        if (className != null) {
            if (hasPrevField) {
                buf.append(',');
            }
            appendField(buf, ExceptionField.CLASS.val, className);
            hasPrevField = true;
        }
    }

    String[] stackTrace = throwableInfo.getThrowableStrRep();
    if (stackTrace != null && stackTrace.length != 0) {
        if (hasPrevField) {
            buf.append(',');
        }
        appendQuotedName(buf, ExceptionField.STACKTRACE.val);
        buf.append(":\"");
        for (int i = 0, len = stackTrace.length; i < len; i++) {
            appendValue(buf, stackTrace[i]);
            if (i != len - 1) {
                appendChar(buf, '\n');
            }
        }
        buf.append('\"');
    }

    buf.append('}');

    return true;
}
 
開發者ID:szhem,項目名稱:log4j-json-layout,代碼行數:51,代碼來源:LogStashJsonLayout.java


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