LogRecord getLoggerName - 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 getLoggerName 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: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, 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, 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, getLoggerName, getThrown
    } 
 
    @Override 
    public String format(LogRecord record) {
        StringBuilder sb = new StringBuilder();
        sb.append(LEVEL_PREFIX.get(record.getLevel()));
        sb.append(' ');
 
        String[] classNameParts = record.getLoggerName().split("\\.");
 
        // add class name for non-info records 
        if (record.getLevel() != Level.INFO && classNameParts.length != 0) {
            sb.append(classNameParts[classNameParts.length - 1]);
            sb.append(": ");
        } 
 
        sb.append(formatMessage(record));
 
        // print stack trace if given 
        Throwable thrown = record.getThrown();

7
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMillis, getThrown
    } 
 
    private static String getHeader(LogRecord record) {
        StringBuilder sb = new StringBuilder();
 
        sb.append(FORMAT.format(new Date(record.getMillis()))).append(":");
        sb.append(levelToString(record.getLevel())).append(" ");
 
        sb.append("[").append(Thread.currentThread().getName()).append("] ");
 
        String loggerName = record.getLoggerName();
        if (loggerName != null) {
            sb.append("[").append(loggerName).append("]");
        } 
        return sb.toString();
    } 
 
    private class PrintWriterWithHeader extends PrintWriter {
        private final ByteArrayOutputStream out;
        private final String header;

6
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getMillis, getThreadID
	private SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss,SSS");
	 
	@Override 
	public String format(LogRecord record)
	{ 
		return StringUtil.concat(dateFmt.format(new Date(record.getMillis())), _,
				record.getLevel().getName(), _, String.valueOf(record.getThreadID()), _,
				record.getLoggerName(), _, record.getMessage(), CRLF);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getParameters, getResourceBundle
    public boolean isLoggable(final LogRecord record) {
        return true; 
    } 
 
    public void publish(final LogRecord record) {
        final String name = record.getLoggerName();
        Logger targetLogger = Logger.getLogger(name == null ? "anonymous" : name);
        final Priority targetLevel = levelMapper.getTargetLevelForSourceLevel(record.getLevel());
        final String text = formatRecord(record);
        targetLogger.log(LOGGER_CLASS_NAME, targetLevel, text, record.getThrown());
    } 
 
    private String formatRecord(final LogRecord record) {
        final ResourceBundle bundle = record.getResourceBundle();
        String msg = record.getMessage();
        if (bundle != null) {
            try { 
                msg = bundle.getString(msg);
            } catch (MissingResourceException ex) {
                // ignore 

6
CodeRank
getLoggerName Method Overview
Get the source Logger's name.
See Code Examples for other Java 8 LogRecord Methods: