List of usage examples for java.util.logging LogRecord getLevel
public Level getLevel()
From source file:nu.nethome.home.impl.HomeServer.java
private void newLogRecord(LogRecord record) { if (isLogRecordInBlacklist(record)) { return;/* w w w . j av a 2s . c o m*/ } totalLogRecordCount++; if (logRecords.remainingCapacity() == 0) { if (logRecords.getLast().getLevel().intValue() >= Level.WARNING.intValue()) { currentWarningCount--; } logRecords.removeLast(); } logRecords.offerFirst(record); if (record.getLevel().intValue() >= Level.WARNING.intValue()) { currentWarningCount++; if (record.getLevel().intValue() < Level.SEVERE.intValue()) { commandLineExecutor.executeCommandLine(warningAction); } else { commandLineExecutor.executeCommandLine(errorAction); } } }
From source file:org.apache.tomee.embedded.AppDataSourceTest.java
@Test public void run() throws OpenEJBException, NamingException, IOException { final File tempWar = new File("target/AppDataSourceTest"); tempWar.mkdirs();//w w w . j a v a 2s . c o m new File(tempWar, "WEB-INF").mkdirs(); IO.writeString(new File(tempWar, "WEB-INF/resources.xml"), "<resources>\n" + "<Resource id=\"java:app/gace/MyDS\" type=\"DataSource\">\n" + "DataSourceCreator=dbcp\n" + "</Resource>\n" + "</resources>\n"); final Collection<LogRecord> records = new ArrayList<>(); try (final Container c = new Container(new Configuration().randomHttpPort())) { Jdk14Logger.class.cast(LogFactory.getLog(BasicDataSource.class)).getLogger().addHandler(new Handler() { @Override public void publish(final LogRecord record) { if (record.getLevel() == Level.SEVERE || record.getLevel() == Level.WARNING) { records.add(record); } } @Override public void flush() { // no-op } @Override public void close() throws SecurityException { // no-op } }); c.deploy(null, tempWar); } // if we have the JMX bug of dbcp2 integration (in 7.0.0) then we have a WARNING record from BasicDataSource.close() // saying: // Failed to unregister the JMX name: // Tomcat:type=DataSource,host=localhost,context=/AppDataSourceTest,class=javax.sql.DataSource,name="openejb/Resource/AppDataSourceTest/app/gace/MyDS" assertTrue(records.isEmpty()); }
From source file:org.broadleafcommerce.common.logging.Log4JRemoteGwtLoggingService.java
@Override public String logOnServer(LogRecord record) { Level level = record.getLevel(); String message;//from ww w . j ava 2 s.c om message = record.getMessage(); if (Level.INFO.equals(level)) { LOG.info(message, record.getThrown()); } else if (Level.SEVERE.equals(level)) { LOG.error(message, record.getThrown()); } else if (Level.WARNING.equals(level)) { LOG.warn(message, record.getThrown()); } else if (Level.FINE.equals(level)) { LOG.debug(message, record.getThrown()); } else { LOG.error(message, record.getThrown()); } return null; }
From source file:org.broadleafcommerce.common.logging.Log4JRemoteGwtLoggingServlet.java
@Override public String logOnServer(LogRecord record) { Level level = record.getLevel(); String message;//from ww w . j a v a2 s. c o m message = getThreadLocalRequest().getRemoteAddr() + ":" + record.getMessage(); if (Level.INFO.equals(level)) { LOG.info(message, record.getThrown()); } else if (Level.SEVERE.equals(level)) { LOG.error(message, record.getThrown()); } else if (Level.WARNING.equals(level)) { LOG.warn(message, record.getThrown()); } else if (Level.FINE.equals(level)) { LOG.debug(message, record.getThrown()); } else { LOG.error(message, record.getThrown()); } return null; }
From source file:org.diorite.impl.log.ForwardLogHandler.java
@Override public void publish(final LogRecord record) { final Logger logger = this.getLogger(record.getLoggerName()); final Throwable exception = record.getThrown(); final Level level = record.getLevel(); final String message = this.getFormatter().formatMessage(record); if (Objects.equals(level, Level.SEVERE)) { logger.error(message, exception); } else if (Objects.equals(level, Level.WARNING)) { logger.warn(message, exception); } else if (Objects.equals(level, Level.INFO)) { logger.info(message, exception); } else if (Objects.equals(level, Level.CONFIG)) { logger.debug(message, exception); } else {//from w ww .j av a 2s . c o m logger.trace(message, exception); } }
From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java
@Override public String format(LogRecord record) { Date time = new Date(record.getMillis()); String formattedTime = dateFormat.format(time); final String logMessage; if (record.getThrown() == null) { Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName() }; logMessage = logMessageFormat.format(log); } else {/*from w w w . j a v a 2 s . com*/ String stack = getStackLayout(record.getThrown(), ""); Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName(), record.getThrown().getMessage(), stack }; logMessage = exceptionMessageFormat.format(log); } return logMessage; }
From source file:org.ebayopensource.turmeric.eclipse.core.logging.PluginLogDelegateHandler.java
@Override public void publish(final LogRecord record) { if (record == null || StringUtils.isBlank(record.getMessage())) return;/*from www . java 2 s .co m*/ final int level = level(record.getLevel()); if (shouldLogRawMessage(record)) { log(level, record.getLoggerName(), record.getMessage(), null); } else { log(level, record.getLoggerName(), StringUtils.replace(formatter.format(record), "\n", "\n "), record.getThrown()); } }
From source file:org.ebayopensource.turmeric.runtime.tests.common.jetty.SimpleConsoleHandler.java
@Override public void publish(LogRecord record) { StringBuilder buf = new StringBuilder(); buf.append("[").append(record.getLevel().getName()); buf.append("] ").append(record.getLoggerName()); buf.append(" (").append(record.getSourceMethodName()); buf.append("): ").append(record.getMessage()); System.out.println(buf.toString()); if (record.getThrown() != null) { record.getThrown().printStackTrace(System.out); }//w w w . j av a 2s . c om }
From source file:org.ensembl.healthcheck.StandaloneTestRunner.java
public Logger getLogger() { if (logger == null) { logger = Logger.getLogger(StandaloneTestRunner.class.getCanonicalName()); ConsoleHandler localConsoleHandler = new ConsoleHandler(); localConsoleHandler.setFormatter(new Formatter() { DateFormat format = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); @Override/* w w w. j a va2 s.co m*/ public String format(LogRecord record) { return String.format("%s %s %s : %s%n", format.format(new Date(record.getMillis())), record.getSourceClassName(), record.getLevel().toString(), record.getMessage()); } }); if (options.isVerbose()) { localConsoleHandler.setLevel(Level.ALL); logger.setLevel(Level.ALL); } else { localConsoleHandler.setLevel(Level.INFO); logger.setLevel(Level.INFO); } logger.setUseParentHandlers(false); logger.addHandler(localConsoleHandler); } return logger; }
From source file:org.geoserver.importer.rest.ImportJSONWriter.java
void messages(List<LogRecord> records) { if (!records.isEmpty()) { json.key("messages"); json.array();/*from ww w . j a v a2s .co m*/ for (int i = 0; i < records.size(); i++) { LogRecord record = records.get(i); json.object(); json.key("level").value(record.getLevel().toString()); json.key("message").value(record.getMessage()); json.endObject(); } json.endArray(); } }