LogRecord setThrown - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for LogRecord setThrown method.

This code example shows how to use the following methods:setLoggerName, setSourceClassName, setThrown
  private void log(Level level, Object message, Throwable t) {
    if (!logger.isLoggable(level)) {
      return; 
    } 
    String msg = (message == null) ? "NULL" : message.toString();
    LogRecord record = new LogRecord(level, msg);
    record.setLoggerName(logger.getName());
    record.setThrown(t);
    // This will disable stack trace lookup inside JUL. If someone wants location info, they can use their own formatter 
    // or use a different logging framework like sl4j, or log4j 
    record.setSourceClassName(null);
 
    logger.log(record);
  } 
} 
8
CodeRank
This code example shows how to use the following methods:setSourceClassName, setSourceMethodName, setThrown
	 * @see com.liferay.faces.util.logging.LogRecordFactory#getLogRecord(java.util.logging.Level, java.lang.String, java.lang.Throwable) 
	 */ 
	public LogRecord getLogRecord(java.util.logging.Level level, String message, Throwable thrown) {
 
		// Create a new LogRecord instance. 
		LogRecord logRecord = new LogRecord(level, message);
 
		// Determine the source class name and source method name. 
		Throwable source = new Throwable();
		StackTraceElement[] stackTraceElements = source.getStackTrace();
		StackTraceElement callerStackTraceElement = stackTraceElements[2];
 
		// Set the source class name and source method name. 
		logRecord.setSourceClassName(callerStackTraceElement.getClassName());
		logRecord.setSourceMethodName(callerStackTraceElement.getMethodName());
 
		// If specified, set the throwable associated with the log event. 
		if (thrown != null) {
			logRecord.setThrown(thrown);
		} 

7
CodeRank
This code example shows how to use the following methods:setLoggerName, setSourceClassName, setThrown
            log(level, message, null);
        } 
 
        @Override 
        public void log(Level level, String message, Throwable thrown) {
            LogRecord logRecord = new LogRecord(level, message);
            logRecord.setLoggerName(logger.getName());
            logRecord.setThrown(thrown);
            logRecord.setSourceClassName(logger.getName());
            logger.log(logRecord);
        } 
 
        @Override 
        public void log(LogEvent logEvent) {
            logger.log(logEvent.getLogRecord());
        } 
 
        @Override 
        public Level getLevel() {
            return logger.getLevel();
7
CodeRank
This code example shows how to use the following methods:setLoggerName, setMillis, setThrown
      String level = lro.getString("level");
      String loggerName = lro.getString("loggerName");
      String msg = lro.getString("msg");
      long timestamp = Long.parseLong(lro.getString("timestamp"));
      Throwable thrown = JsonLogRecordThrowable.fromJsonString(lro.getString("thrown"));
      LogRecord lr = new LogRecord(Level.parse(level), msg);
      lr.setLoggerName(loggerName);
      lr.setThrown(thrown);
      lr.setMillis(timestamp);
      return lr;
    } catch (JSONException e) {
      throw new InvalidJsonLogRecordFormatException(e);
    } 
  } 
 
  private static class JsonLogRecordThrowable extends Throwable {
 
    private static Throwable fromJsonString(String jsonString) throws JSONException {
      if (jsonString.equals("{}")) {
        return null; 
6
CodeRank
This code example shows how to use the following methods:setSourceClassName, setSourceMethodName, setThrown
	 * method may conservatively return <code>false</code>. We will just log 
	 * a warning message and continue. 
	 */ 
	private static void exceptionOccured( 
			final NoninvertibleTransformException exception, final String method) {
		final LogRecord record = new LogRecord(Level.WARNING, exception
				.getLocalizedMessage()); 
		record.setSourceClassName(TransformedShape.class.getName());
		record.setSourceMethodName(method);
		record.setThrown(exception);
		org.geotools.util.logging.Logging.getLogger("org.geotools.renderer.lite").log(record);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:setSourceClassName, setSourceMethodName, setThrown
	 * @see com.liferay.faces.util.logging.LogRecordFactory#getLogRecord(java.util.logging.Level, java.lang.String, java.lang.Throwable) 
	 */ 
	public LogRecord getLogRecord(java.util.logging.Level level, String message, Throwable thrown) {
 
		// Create a new LogRecord instance. 
		LogRecord logRecord = new LogRecord(level, message);
 
		// Determine the source class name and source method name. 
		Throwable source = new Throwable();
		StackTraceElement[] stackTraceElements = source.getStackTrace();
		StackTraceElement callerStackTraceElement = stackTraceElements[2];
 
		// Set the source class name and source method name. 
		logRecord.setSourceClassName(callerStackTraceElement.getClassName());
		logRecord.setSourceMethodName(callerStackTraceElement.getMethodName());
 
		// If specified, set the throwable associated with the log event. 
		if (thrown != null) {
			logRecord.setThrown(thrown);
		} 

6
CodeRank
This code example shows how to use the following methods:setLoggerName, setMillis, setThrown
This code example shows how to use the following methods:setLoggerName, setThrown
    assertEquals("SEVERE: message" + System.getProperty("line.separator"), new LogFormatter().format(logRecord));
  } 
 
  @Test
  public void logShouldLogExceptions() { 
    LogRecord logRecord = new LogRecord(Level.WARNING, "message");
    logRecord.setLoggerName("MyLogger");
    logRecord.setThrown(new RuntimeException(new IllegalArgumentException("Something went wrong here")));
 
    String logOutput = new LogFormatter().format(logRecord);
    assertTrue(logOutput, logOutput.contains("WARNING: message [java.lang.IllegalArgumentException: Something went wrong here]" + System.getProperty("line.separator")));
    assertTrue(logOutput, logOutput.contains("at fitnesse.logging.LogFormatterTest.logShouldLogExceptions"));
 
  } 
 
  @Test
  public void logShouldNotLogExceptionsAtInfoLevel() { 
    LogRecord logRecord = new LogRecord(Level.WARNING, "message");
    logRecord.setLoggerName("MyLogger");
    logRecord.setThrown(new RuntimeException(new IllegalArgumentException("Something went wrong here")));
7
CodeRank
This code example shows how to use the following methods:setLoggerName, setThrown
     * 
     * See bug report #13 for more details. 
     */ 
    private void log(String callerFQCN, Level level, String msg, Throwable t) {
        // millis and thread are filled by the constructor 
        LogRecord record = new LogRecord(level, msg);
        record.setLoggerName(name());
        record.setThrown(t);
        fillCallerData(callerFQCN, record);
        logger.log(record);
    } 
 
    static final String SELF = JdkLogger.class.getName();
    static final String SUPER = AbstractInternalLogger.class.getName();
 
    /** 
     * Fill in caller data if possible. 
     * 
     * @param record 
     *          The record to update 
7
CodeRank
This code example shows how to use the following methods:setSourceClassName, setSourceMethodName, setThrown
	 * method may conservatively return <code>false</code>. We will just log 
	 * a warning message and continue. 
	 */ 
	private static void exceptionOccured( 
			final NoninvertibleTransformException exception, final String method) {
		final LogRecord record = new LogRecord(Level.WARNING, exception
				.getLocalizedMessage());
		record.setSourceClassName(TransformedShape.class.getName());
		record.setSourceMethodName(method);
		record.setThrown(exception);
		org.geotools.util.logging.Logging.getLogger("org.geotools.renderer.lite").log(record);
	} 
} 
7
CodeRank
setThrown Method Overview
Set a throwable associated with the log event.
See Code Examples for other Java 8 LogRecord Methods: