LogRecord getThrown - 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 getThrown method.

This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getParameters, getThrown
     * juli handler that Redirect to log4j 
     */ 
    public static class JuliToLog4jHandler extends Handler {
 
        public void publish(LogRecord record) {
            org.apache.log4j.Logger log4j = getTargetLogger(record.getLoggerName());
            Priority priority = toLog4j(record.getLevel());
            log4j.log(priority, toLog4jMessage(record), record.getThrown());
        } 
 
        static org.apache.log4j.Logger getTargetLogger(String loggerName) {
            return org.apache.log4j.Logger.getLogger(loggerName);
        } 
 
        public static org.apache.log4j.Logger getTargetLogger(Class<?> clazz) {
            return getTargetLogger(clazz.getName());
        } 
 
        private String toLog4jMessage(LogRecord record) {
            String message = record.getMessage();

8
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMillis, getThreadID, getThrown
   * @return a formatted log record 
   */ 
  @Override 
  public synchronized String format(final LogRecord record) {
    buffer.setLength(PREFIX.length());
    buffer.append(timestampFormatter.format(new Date(record.getMillis())));
    buffer.append(' ');
    buffer.append(levelNumberToCommonsLevelName(record.getLevel()));
    if (longForm) {
      buffer.append(" [");
      buffer.append(record.getThreadID());
      buffer.append("] ");
      buffer.append(record.getLoggerName());
    } 
    buffer.append(SUFFIX);
    buffer.append(formatMessage(record)).append('\n');
    if (record.getThrown() != null) {
      final StringWriter trace = new StringWriter();
      record.getThrown().printStackTrace(new PrintWriter(trace));
      buffer.append(trace);

8
CodeRank
This code example shows how to use the following methods:getMessage, getThrown
  @Override 
  public void publish(LogRecord record) {
    Formatter formatter = getFormatter();
    String message;
    if (formatter == null) {
      message = record.getMessage();
    } else { 
      message = formatter.format(record);
    } 
    Throwable throwable = record.getThrown();
    if (throwable == null) {
      context.log(message);
    } else { 
      context.log(message, throwable);
    } 
  } 
 
  @Override 
  public void flush() { 
    // do nothing 
8
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMillis, getThrown
    // MCPC+ end 
 
    public String format(LogRecord record)
    { 
        StringBuilder msg = new StringBuilder();
        msg.append(this.dateFormat.format(Long.valueOf(record.getMillis())));
        Level lvl = record.getLevel();
 
        String name = lvl.getLocalizedName();
        if ( name == null )
        { 
            name = lvl.getName();        	
        } 
 
        if ( ( name != null ) && ( name.length() > 0 ) )
        { 
            msg.append(" [" + name + "] ");
        } 
        else 
        { 

8
CodeRank
This code example shows how to use the following methods:getLevel, getMessage, getMillis, getSourceClassName, getThrown
 
public class LoggerShortFormat extends java.util.logging.Formatter {
  @Override 
  @Nonnull 
  public String format(@Nonnull final LogRecord record) {
    return record.getMillis() + " " +
        record.getLevel() + " [" +
        record.getSourceClassName() + "] " +
        record.getMessage() +
        (record.getThrown() != null ? " Stack trace:\n" + getStackTrace(record.getThrown()) : "") + "\n";
  } 
 
  public static void intialize() throws Exception { 
    InputStream input = null;
    try { 
      input = LoggerShortFormat.class.getClassLoader().getResourceAsStream("logging.properties");
      LogManager.getLogManager().readConfiguration(input);
    } finally { 
      if (input != null) {
        input.close();
8
CodeRank
This code example shows how to use the following methods:getMessage, getThrown
     * Holds the formatter for all Android log handlers. 
     */ 
    private static final Formatter THE_FORMATTER = new Formatter() {
        @Override 
        public String format(LogRecord r) { 
            Throwable thrown = r.getThrown(); 
            if (thrown != null) { 
                StringWriter sw = new StringWriter(); 
                PrintWriter pw = new PrintWriter(sw); 
                sw.write(r.getMessage()); 
                sw.write("\n"); 
                thrown.printStackTrace(pw); 
                pw.flush(); 
                return sw.toString(); 
            } else { 
                return r.getMessage(); 
            } 
        } 
    }; 
 
    /** 
7
CodeRank
This code example shows how to use the following methods:getLevel, getMillis, getThrown
This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getThrown
	private static final int LOGGER_WIDTH = 30;
 
	@Override 
	public String format(LogRecord record) {
		StringBuilder sb = new StringBuilder();
		sb.append(Str.fillUpRight(Str.cutRight(record.getLevel().getName(), 4), " ", 5));
		sb.append(Str.fillUpRight(Str.cutLeft(record.getLoggerName(), LOGGER_WIDTH - 1, ".."), " ", LOGGER_WIDTH));
		sb.append("-> ");
		sb.append(record.getMessage());
		sb.append("\n");
		if (record.getThrown() != null) {
			StringWriter sw = new StringWriter();
			PrintWriter out = new PrintWriter(sw);
			record.getThrown().printStackTrace(out);
			out.flush();
			sb.append(sw.toString());
		} 
		return sb.toString();
	} 
 
7
CodeRank
This code example shows how to use the following methods:getLevel, getMessage, getThrown
  } 
 
  @Override 
  public String format(LogRecord logRecord) {
    StringBuilder builder = new StringBuilder(128);
    Throwable thrown = logRecord.getThrown();
 
    if (atLeastWarningLevel(logRecord)) {
      builder.append(logRecord.getLevel().getName())
              .append(": ");
    } 
    builder.append(logRecord.getMessage());
    if (thrown != null) {
      builder.append(" [")
              .append(thrown.getMessage())
              .append("]");
    } 
    builder.append(ENDL);
 
    if (thrown != null && atLeastWarningLevel(logRecord)) {

7
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getResourceBundle, getSequenceNumber
        check(logger.isLoggable(Level.WARNING));
        logger.addHandler(new Handler() {
            public void close() {} 
            public void flush() {} 
            public void publish(LogRecord l) {
                equal(l.getLoggerName(), name);
                equal(l.getMessage(), message);
                equal(l.getResourceBundle(), null);
                equal(l.getSourceClassName(), "LoggerSubclass");
                equal(l.getSourceMethodName(), "test");
                equal(l.getThrown(), null);
                equal(l.getLevel(), Level.WARNING);
 
                if (lastSequenceNumber.get() != -1) {
                    equal(lastSequenceNumber.get() + 1,
                          l.getSequenceNumber());
                    equal(lastThreadID.get(),
                          l.getThreadID());
                    equal((int) Thread.currentThread().getId(),
                          l.getThreadID());

7
CodeRank
getThrown Method Overview
Get any throwable associated with the log record.
See Code Examples for other Java 8 LogRecord Methods: