LogRecord getMessage - 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 getMessage 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: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, 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:getMessage, setMessage
    } 
 
    @Override 
    public void log(LogRecord logRecord)
    { 
        logRecord.setMessage( pluginName + logRecord.getMessage() );
        ProxyServer.getInstance().getLogger().log( logRecord );
    } 
} 
7
CodeRank
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
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();

7
CodeRank
This code example shows how to use the following methods:getLevel, getMessage, getMillis, getSequenceNumber, getSourceClassName
	 * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) 
	 */ 
	@Override 
	public void publish(LogRecord record) {
		TestLogs testLogs = new TestLogs();		
		testLogs.setLogLevel(record.getLevel().getName());
		testLogs.setLogTime(new Date(record.getMillis()));
		testLogs.setMessage(record.getMessage());
		testLogs.setSequenceNumber(record.getSequenceNumber());
		testLogs.setClassName(record.getSourceClassName());
		testLogs.setMethodName(record.getSourceMethodName());
		testLogs.setThrowable(ClientCommon.toString(record.getThrown()));
		try { 
			remoteApi.insertLogMessage(testLogs);
		} catch (Exception ex) {
			LogHandler.teardown(); 
			System.out.println("error writing log to report engine; removing appender;");
			ex.printStackTrace();
		} 
	} 
6
CodeRank
getMessage Method Overview
Get the "raw" log message, before localization or formatting.
See Code Examples for other Java 8 LogRecord Methods: