Java Code Examples for java.util.logging.LogRecord#getLevel()

The following examples show how to use java.util.logging.LogRecord#getLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Slf4jLoggingHandler.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private MappedLevel convertLevel(LogRecord record)
{
    if (record.getLevel() == Level.SEVERE && isJECleaner(record)
        && record.getMessage().startsWith("Average cleaner backlog has grown from"))
    {
        // this is not a real ERROR condition; reducing level to INFO
        return INFO;
    }

    if (record.getLevel() == Level.WARNING && isJECleaner(record))
    {
        Matcher matcher = NOT_DELETED_DUE_TO_PROTECTION.matcher(record.getMessage());
        if (matcher.matches() && matcher.groupCount() > 0 && Integer.parseInt(matcher.group(1)) < _logHandlerCleanerProtectedFilesLimit)
        {
            return DEBUG;
        }
    }

    return convertLevel(record.getLevel());
}
 
Example 2
Source File: EnvironmentLogger.java    From baratine with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Logs the message.
 */
@Override
public void log(LogRecord record)
{
  if (record == null)
    return;
  
  Level recordLevel = record.getLevel();

  if (! isLoggable(recordLevel))
    return;
  
  for (Logger ptr = this; ptr != null; ptr = ptr.getParent()) {
    Handler handlers[] = ptr.getHandlers();

    if (handlers != null) {
      for (int i = 0; i < handlers.length; i++) {
        handlers[i].publish(record);
      }
    }

    if (! ptr.getUseParentHandlers())
      break;
  }
}
 
Example 3
Source File: LoggerRule.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
@Override
protected boolean matchesSafely(LoggerRule item) {
    synchronized (item) {
        for (LogRecord record : item.getRecords()) {
            if (level == null || record.getLevel() == level) {
                if (message.matches(record.getMessage())) {
                    if (thrown != null) {
                        if (thrown.matches(record.getThrown())) {
                            return true;
                        }
                    } else {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: EclipseLogHandler.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void publish(LogRecord record) {

  // translate log levels into severity
  int severity = 0;
  Level level = record.getLevel();
  if (Level.CONFIG.equals(level) || Level.INFO.equals(level) || Level.FINE.equals(level)
          || Level.FINER.equals(level) || Level.FINEST.equals(level)) {
    severity = IStatus.INFO;
  } else if (Level.WARNING.equals(level)) {
    severity = IStatus.WARNING;
  } else if (Level.SEVERE.equals(level)) {
    severity = IStatus.ERROR;
  }

  // get message
  String message = record.getMessage();

  // get throwable
  Throwable t = record.getThrown();

  Status status = new Status(severity, mPluginID, IStatus.OK,
          NLS.bind(Messages.CheckstyleLog_msgStatusPrefix, message), t);
  mPluginLog.log(status);
}
 
Example 5
Source File: MavenLogStreamFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalLogFormatted(final String msg, final LogRecord record) {
    final Level level = record.getLevel();
    final Throwable t = record.getThrown();
    if (Level.FINE.equals(level) || Level.FINER.equals(level) || Level.CONFIG.equals(level)) {
        if (t == null) {
            logger.debug(msg);
        } else {
            logger.debug(msg, t);
        }
    } else if (Level.INFO.equals(level)) {
        if (t == null) {
            logger.info(msg);
        } else {
            logger.info(msg, t);
        }
    } else if (Level.WARNING.equals(level)) {
        if (t == null) {
            logger.warn(msg);
        } else {
            logger.warn(msg, t);
        }
    } else if (Level.ALL.equals(level) || Level.SEVERE.equals(level)) {
        if (t == null) {
            logger.error(msg);
        } else {
            logger.error(msg, t);
        }
    }
}
 
Example 6
Source File: NbErrorManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void publish(LogRecord record) {
    if (record.getThrown() != null) {
        Level level = record.getLevel();
        if (level.intValue() == Level.WARNING.intValue() + 1) {
            // unknown level
            level = null;
        }
        if (level != null && level.intValue() == Level.SEVERE.intValue() + 1) {
            // unknown level
            level = null;
        }
        Exc ex = createExc(record.getThrown(), level, record.getLevel().intValue() == 1973 ? record : null);
        NotifyExcPanel.notify(ex);
    }
}
 
Example 7
Source File: SimpleConsoleLoggingFormatter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * Populates the string builder with logging information.
 * 
 * @param sb
 *            the string builder
 * @param record
 *            one log record to be used for population of the string builder
 */
protected void fillStringBuilderWithMessage(final StringBuilder sb, final LogRecord record) {
	if ((record.getLevel() == Level.WARNING) || (record.getLevel() == Level.SEVERE)) {
		sb.append(record.getLevel().getLocalizedName());
		sb.append(": ");
	}

	sb.append(record.getMessage());
	sb.append(LINE_SEPERATOR);
}
 
Example 8
Source File: JavaLoggingAspect.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@OnBefore
public static @Nullable LogAdviceTraveler onBefore(ThreadContext context,
        @BindParameter @Nullable LogRecord record, @BindReceiver Object logger) {
    if (record == null) {
        return null;
    }
    Level level = record.getLevel();
    if (!((Logger) logger).isLoggable(level)) {
        // Logger.log(LogRecord) was called directly
        return null;
    }
    return onBeforeCommon(context, record, level);
}
 
Example 9
Source File: JDK14LoggerIT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public void publish(LogRecord record)
{
  // Assign the log message and it's level to the outer class instance
  // variables so that it can see the messages logged
  lastLogMessage = getFormatter().formatMessage(record);
  lastLogMessageLevel = record.getLevel();
}
 
Example 10
Source File: LogFormat.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String format(LogRecord record) {
    String text = "[" + new SimpleDateFormat("HH:mm:ss").format(new Date(record.getMillis()));
    Level level = record.getLevel();

    if (level == Level.WARNING) {
        text += " WARNING]";
    } else if (level == Level.SEVERE) {
        text += " SEVERE]";
    } else {
        text += " INFO]";
    }

    text += " " + record.getMessage();
    text += "\r\n";

    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter stringWriter = new StringWriter();
        thrown.printStackTrace(new PrintWriter(stringWriter));
        text += stringWriter;
    }

    text = text.replaceAll("(\\u001b\\[\\d{1,3}(?:;\\d+)*m|(?:\\u001b\\[m)*)", "");
    // text = Colorizer.stripColors(text);

    return text;
}
 
Example 11
Source File: CPPCheckTest.java    From violations-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelfClosingErrorTagScoping() {

  List<LogRecord> severeLogEvents = new ArrayList<LogRecord>();
  Handler logHandler =
      new Handler() {
        @Override
        public void publish(final LogRecord record) {
          if (Level.SEVERE == record.getLevel()) {
            severeLogEvents.add(record);
          }
        }

        @Override
        public void flush() {}

        @Override
        public void close() throws SecurityException {}
      };
  Logger.getLogger("").setLevel(Level.SEVERE);
  Logger.getLogger("").addHandler(logHandler);
  final String rootFolder = getRootFolder();

  final List<Violation> actual =
      violationsApi() //
          .withPattern(".*/cppcheck/self_closing_scope_limited\\.xml$") //
          .inFolder(rootFolder) //
          .findAll(CPPCHECK) //
          .violations();

  assertThat(severeLogEvents) //
      .hasSize(0);
  assertThat(actual) //
      .hasSize(1);

  Logger.getLogger("").removeHandler(logHandler);
}
 
Example 12
Source File: LogFormatter.java    From darklaf with MIT License 5 votes vote down vote up
private String getMessageColor(final LogRecord record) {
    if (record.getLevel() == Level.SEVERE) {
        return ANSI_RED;
    } else if (record.getLevel() == Level.WARNING) {
        return ANSI_YELLOW;
    } else {
        return ANSI_BLACK;
    }
}
 
Example 13
Source File: VespaLogHandler.java    From vespa with Apache License 2.0 5 votes vote down vote up
/**
 * Publish a log record into the Vespa log target.
 */
public synchronized void publish(LogRecord record) {
    Level level = record.getLevel();
    String component = record.getLoggerName();

    LevelController ctrl = getLevelControl(component);
    if (!ctrl.shouldLog(level)) {
        return;
    }

    if (logRejectFilter.shouldReject(record.getMessage())) {
        return;
    }

    try {
        // provokes rotation of target
        setOutputStream(logTarget.open());
    } catch (RuntimeException e) {
        LogRecord r = new LogRecord(Level.SEVERE, "Unable to open file target");
        r.setThrown(e);
        emergencyLog(r);
        setOutputStream(System.err);
    }
    super.publish(record);
    flush();
    closeFileTarget();
}
 
Example 14
Source File: TesterLogValidationFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public boolean isLoggable(LogRecord record) {
    if (targetLevel != null) {
        Level level = record.getLevel();
        if (targetLevel != level) {
            return true;
        }
    }

    if (targetMessage != null) {
        String msg = record.getMessage();
        if (msg == null || !msg.contains(targetMessage)) {
            return true;
        }
    }

    if (targetThrowableString != null) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        record.getThrown().printStackTrace(pw);
        pw.close();
        String throwableString = sw.toString();
        if (!throwableString.contains(targetThrowableString)) {
            return true;
        }


    }

    messageCount.incrementAndGet();

    return true;
}
 
Example 15
Source File: VespaFormatter.java    From vespa with Apache License 2.0 4 votes vote down vote up
public String format(LogRecord r) {
    StringBuilder sbuf = new StringBuilder(300); // initial guess

    String levelName = LogLevel.getVespaLogLevel(r.getLevel()).toString().toLowerCase();

    String component = r.getLoggerName();

    // format the time
    sbuf.append(VespaFormat.formatTime(r.getInstant()));
    sbuf.append("\t");

    sbuf.append(hostname).append("\t")
        .append(processID).append("/")
        .append(r.getThreadID()).append("\t")
        .append(serviceName).append("\t");

    if (component == null && componentPrefix == null) {
        sbuf.append("-");
    } else if (component == null) {
        sbuf.append(componentPrefix);
    } else if (componentPrefix == null) {
        sbuf.append(".").append(component);
    } else {
        sbuf.append(componentPrefix).append(".").append(component);
    }

    sbuf.append("\t").append(levelName).append("\t");

    // for events, there is no ordinary message string;
    // instead we render a string represantion of the event object:
    if (r.getLevel() == LogLevel.EVENT) {
        Event event = (Event) r.getParameters()[0];
        sbuf.append(VespaFormat.escape(event.toString()));
    } else {
        // otherwise, run standard java text formatting on the message
        sbuf.append(VespaFormat.escape(formatMessage(r)));
    }
    appendException(r.getThrown(), sbuf);

    sbuf.append("\n");
    return sbuf.toString();
}
 
Example 16
Source File: LoggingMediaHttpUploaderProgressListenerTest.java    From hadoop-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public String format(LogRecord record) {
  return record.getLevel() + ": " + record.getMessage();
}
 
Example 17
Source File: ColoredConsoleLogger.java    From moleculer-java with MIT License 4 votes vote down vote up
@Override
public synchronized void log(LinkedList<LogRecord> records, StringBuilder lines) {
	Throwable cause;
	String msg;
	for (LogRecord record : records) {
		final Level l = record.getLevel();
		if (l == Level.SEVERE) {

			coloredPrinter.print(SEVERE, Attribute.LIGHT, FColor.RED, BColor.NONE);

		} else if (l == Level.WARNING) {

			coloredPrinter.print(WARNING, Attribute.LIGHT, FColor.YELLOW, BColor.NONE);

		} else if (l == Level.INFO) {

			coloredPrinter.print(INFO, Attribute.LIGHT, FColor.GREEN, BColor.NONE);

		} else if (l == Level.CONFIG) {

			coloredPrinter.print(CONFIG, Attribute.CLEAR, FColor.CYAN, BColor.NONE);

		} else if (l == Level.FINE) {

			coloredPrinter.print(FINE, Attribute.CLEAR, FColor.MAGENTA, BColor.NONE);

		} else if (l == Level.FINER) {

			coloredPrinter.print(FINER, Attribute.CLEAR, FColor.BLUE, BColor.NONE);

		} else {

			coloredPrinter.print(FINEST, Attribute.CLEAR, FColor.RED, BColor.NONE);

		}
		msg = record.getMessage();
		if (msg == null) {
			msg = "<null>";
		} else {
			msg = msg.trim();
		}
		coloredPrinter.println(msg, Attribute.LIGHT, FColor.WHITE, BColor.NONE);
		coloredPrinter.clear();
        
		cause = record.getThrown();
		if (cause != null) {
			cause.printStackTrace(errorWriter);
		}
	}

}
 
Example 18
Source File: LogFormatter.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public String format(LogRecord record) {
    return record.getMillis() + " " + record.getLevel() + " "
            + record.getLoggerName().substring(record.getLoggerName().lastIndexOf('.') + 1) + " " + record.getMessage() + "\n";
}
 
Example 19
Source File: JavaLoggingAdapter.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void publish(
                     LogRecord record ) {

    Level level = record.getLevel();
    String message = record.getMessage();
    if (level.intValue() == Level.ALL.intValue()) {
        throw new RuntimeException("ALL");
    }

    if (level.intValue() <= Level.FINEST.intValue()) {
        logger.debug(message);
        return;//300
    }

    if (level.intValue() <= Level.FINE.intValue()) {
        logger.debug(message);
        return;//500
    }

    if (level.intValue() <= Level.CONFIG.intValue()) {
        logger.debug(message);
        return;//700
    }

    if (level.intValue() <= Level.INFO.intValue()) {
        logger.info(message);
        return;//800
    }

    if (level.intValue() <= Level.WARNING.intValue()) {
        logger.warn(message);
        return;//900
    }

    if (level.intValue() <= Level.SEVERE.intValue()) {
        logger.error(message);
        return;//1000
    }

    if (level.intValue() <= Level.OFF.intValue()) {
        throw new RuntimeException("OFF");
    }

}
 
Example 20
Source File: Slf4jLogger.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected void internalLogFormatted(String msg, LogRecord record) {

    Level level = record.getLevel();
    Throwable t = record.getThrown();

    Handler[] targets = getHandlers();
    if (targets != null) {
        for (Handler h : targets) {
            h.publish(record);
        }
    }
    if (!getUseParentHandlers()) {
        return;
    }

    /*
     * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the
     * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
     */
    if (Level.FINE.equals(level)) {
        if (locationAwareLogger == null) {
            logger.debug(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    } else if (Level.INFO.equals(level)) {
        if (locationAwareLogger == null) {
            logger.info(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
        }
    } else if (Level.WARNING.equals(level)) {
        if (locationAwareLogger == null) {
            logger.warn(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
        }
    } else if (Level.FINER.equals(level)) {
        if (locationAwareLogger == null) {
            logger.trace(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    } else if (Level.FINEST.equals(level)) {
        if (locationAwareLogger == null) {
            logger.trace(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
        }
    } else if (Level.ALL.equals(level)) {
        // should never occur, all is used to configure java.util.logging
        // but not accessible by the API Logger.xxx() API
        if (locationAwareLogger == null) {
            logger.error(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
        }
    } else if (Level.SEVERE.equals(level)) {
        if (locationAwareLogger == null) {
            logger.error(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
        }
    } else if (Level.CONFIG.equals(level)) {
        if (locationAwareLogger == null) {
            logger.debug(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    } else if (Level.OFF.equals(level)) {
        // don't log
    }
}