org.jboss.logmanager.Level Java Examples

The following examples show how to use org.jboss.logmanager.Level. 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: ExecutionBuilderTest.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
private static ExecutionBuilder getExecutionBuilderFromRMIRegistry()
{
    try
    {
        Registry registry = LocateRegistry.getRegistry(PORT);
        ExecutionBuilder executionBuilder = (ExecutionBuilder) registry.lookup(ExecutionBuilder.LOOKUP_NAME);
        executionBuilder.clear();
        return executionBuilder;
    }
    catch (RemoteException | NotBoundException e)
    {
        LOG.log(Level.SEVERE, e.getMessage(), e);
        e.printStackTrace();
    }
    return null;
}
 
Example #2
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void log(Level level, Object message, Throwable t, Object... params) {
    if (!logger.isLoggable(level)) {
        return;
    }
    String msg = (message == null) ? "NULL" : message.toString();
    LogRecord record = new LogRecord(level, msg);
    record.setLoggerName(logger.getName());
    if (t != null) {
        record.setThrown(t);
    } else if (params != null && params.length != 0 && params[params.length - 1] instanceof Throwable) {
        // The exception may be the last parameters (SLF4J uses this convention).
        // As the logger can be used in a SLF4J style, we need to check
        record.setThrown((Throwable) params[params.length - 1]);
    }
    record.setSourceClassName(null);
    record.setParameters(params);
    logger.log(record);
}
 
Example #3
Source File: JsonFormatterTest.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormat() throws Exception {
    final JsonFormatter formatter = new JsonFormatter();
    formatter.setPrintDetails(true);
    ExtLogRecord record = createLogRecord("Test formatted %s", "message");
    compare(record, formatter);

    record = createLogRecord("Test Message");
    compare(record, formatter);

    record = createLogRecord(Level.ERROR, "Test formatted %s", "message");
    record.setLoggerName("org.jboss.logmanager.ext.test");
    record.setMillis(System.currentTimeMillis());
    final Throwable t = new RuntimeException("Test cause exception");
    final Throwable dup = new IllegalStateException("Duplicate");
    t.addSuppressed(dup);
    final Throwable cause = new RuntimeException("Test Exception", t);
    dup.addSuppressed(cause);
    cause.addSuppressed(new IllegalArgumentException("Suppressed"));
    cause.addSuppressed(dup);
    record.setThrown(cause);
    record.putMdc("testMdcKey", "testMdcValue");
    record.setNdc("testNdc");
    formatter.setExceptionOutputType(JsonFormatter.ExceptionOutputType.DETAILED_AND_FORMATTED);
    compare(record, formatter);
}
 
Example #4
Source File: JsonFormatterTest.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogstashFormat() throws Exception {
    KEY_OVERRIDES.put(Key.TIMESTAMP, "@timestamp");
    final LogstashFormatter formatter = new LogstashFormatter();
    formatter.setPrintDetails(true);
    ExtLogRecord record = createLogRecord("Test formatted %s", "message");
    compareLogstash(record, formatter, 1);

    record = createLogRecord("Test Message");
    formatter.setVersion(2);
    compareLogstash(record, formatter, 2);

    record = createLogRecord(Level.ERROR, "Test formatted %s", "message");
    record.setLoggerName("org.jboss.logmanager.ext.test");
    record.setMillis(System.currentTimeMillis());
    record.setThrown(new RuntimeException("Test Exception"));
    record.putMdc("testMdcKey", "testMdcValue");
    record.setNdc("testNdc");
    compareLogstash(record, formatter, 2);
}
 
Example #5
Source File: XmlFormatterTest.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormat() throws Exception {
    final XmlFormatter formatter = new XmlFormatter();
    formatter.setPrintDetails(true);
    ExtLogRecord record = createLogRecord("Test formatted %s", "message");
    compare(record, formatter);

    record = createLogRecord("Test Message");
    compare(record, formatter);

    record = createLogRecord(Level.ERROR, "Test formatted %s", "message");
    record.setLoggerName("org.jboss.logmanager.ext.test");
    record.setMillis(System.currentTimeMillis());
    final Throwable t = new RuntimeException("Test cause exception");
    final Throwable dup = new IllegalStateException("Duplicate");
    t.addSuppressed(dup);
    final Throwable cause = new RuntimeException("Test Exception", t);
    dup.addSuppressed(cause);
    cause.addSuppressed(new IllegalArgumentException("Suppressed"));
    cause.addSuppressed(dup);
    record.setThrown(cause);
    record.putMdc("testMdcKey", "testMdcValue");
    record.setNdc("testNdc");
    formatter.setExceptionOutputType(JsonFormatter.ExceptionOutputType.DETAILED_AND_FORMATTED);
    compare(record, formatter);
}
 
Example #6
Source File: LogContextStdioContextSelector.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public StdioContext getStdioContext() {
    final LogContext logContext = LogContext.getLogContext();
    final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
    StdioContext stdioContext = root.getAttachment(STDIO_CONTEXT_ATTACHMENT_KEY);
    if (stdioContext == null) {
        stdioContext = StdioContext.create(
                new NullInputStream(),
                new LoggingOutputStream(logContext.getLogger("stdout"), Level.INFO),
                new LoggingOutputStream(logContext.getLogger("stderr"), Level.ERROR)
        );
        final StdioContext appearing = root.attachIfAbsent(STDIO_CONTEXT_ATTACHMENT_KEY, stdioContext);
        if (appearing != null) {
            stdioContext = appearing;
        }
    }
    return stdioContext;
}
 
Example #7
Source File: SyslogAuditLogHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
void writeLogItem(String formattedItem) throws IOException {
    boolean reconnect =  isReconnect();
    if (!reconnect) {
        handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName()));
        errorManager.getAndThrowError();
    } else {
        ControllerLogger.MGMT_OP_LOGGER.attemptingReconnectToSyslog(name, reconnectTimeout);
        try {
            // Reinitialise the delegating syslog handler if required, if we're already connected we don't need to
            // establish a new connection
            if (!connected) {
                stop();
                initialize();
            }
            handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName()));
            errorManager.getAndThrowError();
            lastErrorTime = -1;
        } catch (Exception e) {
            // A failure has occurred and initialization should be reattempted
            connected = false;
            lastErrorTime = System.currentTimeMillis();
            errorManager.throwAsIoOrRuntimeException(e);
        }
    }
}
 
Example #8
Source File: WildFlyLogContextSelector.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void clearLogContext() {
    // Remove the configurator and clear the log context
    final Configurator configurator = EMBEDDED_LOG_CONTEXT.getLogger("").detach(Configurator.ATTACHMENT_KEY);
    // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
    if (configurator instanceof PropertyConfigurator) {
        final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
        clearLogContext(logContextConfiguration);
    } else if (configurator instanceof LogContextConfiguration) {
        clearLogContext((LogContextConfiguration) configurator);
    } else {
        // Remove all the handlers and close them as well as reset the loggers
        final List<String> loggerNames = Collections.list(EMBEDDED_LOG_CONTEXT.getLoggerNames());
        for (String name : loggerNames) {
            final Logger logger = EMBEDDED_LOG_CONTEXT.getLoggerIfExists(name);
            if (logger != null) {
                final Handler[] handlers = logger.clearHandlers();
                if (handlers != null) {
                    for (Handler handler : handlers) {
                        handler.close();
                    }
                }
                logger.setFilter(null);
                logger.setUseParentFilters(false);
                logger.setUseParentHandlers(true);
                logger.setLevel(Level.INFO);
            }
        }
    }
}
 
Example #9
Source File: Main.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The main method.
 *
 * @param args the command-line arguments
 */
public static void main(String[] args) throws IOException {
    MDC.put("process", "host controller");


    // Grab copies of our streams.
    final InputStream in = System.in;
    //final PrintStream out = System.out;
    //final PrintStream err = System.err;

    byte[] authKey = new byte[ProcessController.AUTH_BYTES_ENCODED_LENGTH];
    try {
        StreamUtils.readFully(new Base64InputStream(System.in), authKey);
    } catch (IOException e) {
        STDERR.println(HostControllerLogger.ROOT_LOGGER.failedToReadAuthenticationKey(e));
        fail();
        return;
    }

    // Make sure our original stdio is properly captured.
    try {
        Class.forName(ConsoleHandler.class.getName(), true, ConsoleHandler.class.getClassLoader());
    } catch (Throwable ignored) {
    }

    // Install JBoss Stdio to avoid any nasty crosstalk.
    StdioContext.install();
    final StdioContext context = StdioContext.create(
        new NullInputStream(),
        new LoggingOutputStream(Logger.getLogger("stdout"), Level.INFO),
        new LoggingOutputStream(Logger.getLogger("stderr"), Level.ERROR)
    );
    StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));

    create(args, new String(authKey, Charset.forName("US-ASCII")));

    while (in.read() != -1) {}
    exit();
}
 
Example #10
Source File: JsonFormatterTest.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
private static void compare(final ExtLogRecord record, final JsonObject json, final Map<String, String> metaData) {
    Assert.assertEquals(record.getLevel(), Level.parse(getString(json, Key.LEVEL)));
    Assert.assertEquals(record.getLoggerClassName(), getString(json, Key.LOGGER_CLASS_NAME));
    Assert.assertEquals(record.getLoggerName(), getString(json, Key.LOGGER_NAME));
    compareMaps(record.getMdcCopy(), getMap(json, Key.MDC));
    Assert.assertEquals(record.getFormattedMessage(), getString(json, Key.MESSAGE));
    Assert.assertEquals(
            new SimpleDateFormat(StructuredFormatter.DEFAULT_DATE_FORMAT).format(new Date(record.getMillis())),
            getString(json, Key.TIMESTAMP));
    Assert.assertEquals(record.getNdc(), getString(json, Key.NDC));
    // Assert.assertEquals(record.getResourceBundle());
    // Assert.assertEquals(record.getResourceBundleName());
    // Assert.assertEquals(record.getResourceKey());
    Assert.assertEquals(record.getSequenceNumber(), getLong(json, Key.SEQUENCE));
    Assert.assertEquals(record.getSourceClassName(), getString(json, Key.SOURCE_CLASS_NAME));
    Assert.assertEquals(record.getSourceFileName(), getString(json, Key.SOURCE_FILE_NAME));
    Assert.assertEquals(record.getSourceLineNumber(), getInt(json, Key.SOURCE_LINE_NUMBER));
    Assert.assertEquals(record.getSourceMethodName(), getString(json, Key.SOURCE_METHOD_NAME));
    Assert.assertEquals(record.getThreadID(), getInt(json, Key.THREAD_ID));
    Assert.assertEquals(record.getThreadName(), getString(json, Key.THREAD_NAME));
    if (metaData != null) {
        for (String key : metaData.keySet()) {
            Assert.assertEquals(metaData.get(key), json.getString(key));
        }
    }
    // TODO (jrp) stack trace should be validated
}
 
Example #11
Source File: EmbeddedLogContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Attempts to clear the global log context used for embedded servers.
 */
static synchronized void clearLogContext() {
    final LogContext embeddedLogContext = Holder.LOG_CONTEXT;
    // Remove the configurator and clear the log context
    final Configurator configurator = embeddedLogContext.getLogger("").detach(Configurator.ATTACHMENT_KEY);
    // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
    if (configurator instanceof PropertyConfigurator) {
        final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
        clearLogContext(logContextConfiguration);
    } else if (configurator instanceof LogContextConfiguration) {
        clearLogContext((LogContextConfiguration) configurator);
    } else {
        // Remove all the handlers and close them as well as reset the loggers
        final List<String> loggerNames = Collections.list(embeddedLogContext.getLoggerNames());
        for (String name : loggerNames) {
            final Logger logger = embeddedLogContext.getLoggerIfExists(name);
            if (logger != null) {
                final Handler[] handlers = logger.clearHandlers();
                if (handlers != null) {
                    for (Handler handler : handlers) {
                        handler.close();
                    }
                }
                logger.setFilter(null);
                logger.setUseParentFilters(false);
                logger.setUseParentHandlers(true);
                logger.setLevel(Level.INFO);
            }
        }
    }
}
 
Example #12
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(Object message, Throwable t, Object... params) {
    log(Level.DEBUG, message, t, params);
}
 
Example #13
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void trace(final Object message) {
    log(Level.TRACE, message);
}
 
Example #14
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void trace(Object message, Object... params) {
    log(Level.TRACE, message, null, params);
}
 
Example #15
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void trace(final Object message, final Throwable t) {
    log(Level.TRACE, message, t);
}
 
Example #16
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void trace(Object message, Throwable t, Object... params) {
    log(Level.TRACE, message, t, params);
}
 
Example #17
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void log(Level level, Object message) {
    log(level, message, null);
}
 
Example #18
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void debug(final Object message, final Throwable t) {
    log(Level.DEBUG, message, t);
}
 
Example #19
Source File: HibernateOrmProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
public void produceLoggingCategories(BuildProducer<LogCategoryBuildItem> categories) {
    if (hibernateConfig.log.bindParam) {
        categories.produce(new LogCategoryBuildItem("org.hibernate.type.descriptor.sql.BasicBinder", Level.TRACE));
    }
}
 
Example #20
Source File: KubernetesConfigProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
public void produceLoggingCategories(BuildProducer<LogCategoryBuildItem> categories) {
    categories.produce(new LogCategoryBuildItem("okhttp3.OkHttpClient", Level.WARN));
}
 
Example #21
Source File: SimpleStartStopTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * Start / stopping the server shouldn't generate any errors.
 * Also it shouldn't bloat the journal with lots of IDs (it should do some cleanup when possible)
 * <br>
 * This is also validating that the same server could be restarted after stopped
 *
 * @throws Exception
 */
@Test
public void testStartStopAndCleanupIDs() throws Exception {
   AssertionLoggerHandler.clear();
   AssertionLoggerHandler.startCapture();
   try {
      ActiveMQServer server = null;

      for (int i = 0; i < 50; i++) {
         server = createServer(true, false);
         server.start();
         server.fail(false);
      }

      // There shouldn't be any error from starting / stopping the server
      assertFalse("There shouldn't be any error for just starting / stopping the server", AssertionLoggerHandler.hasLevel(Level.ERROR));
      assertFalse(AssertionLoggerHandler.findText("AMQ224008"));

      HashMap<Integer, AtomicInteger> records = this.internalCountJournalLivingRecords(server.getConfiguration(), false);

      AtomicInteger recordCount = records.get((int) JournalRecordIds.ID_COUNTER_RECORD);

      assertNotNull(recordCount);

      // The server should remove old IDs from the journal
      assertTrue("The server should cleanup after IDs on the bindings record. It left " + recordCount +
                    " ids on the journal", recordCount.intValue() < 5);

      server.start();

      records = this.internalCountJournalLivingRecords(server.getConfiguration(), false);

      recordCount = records.get((int) JournalRecordIds.ID_COUNTER_RECORD);

      assertNotNull(recordCount);

      assertTrue("If this is zero it means we are removing too many records", recordCount.intValue() != 0);

      server.stop();

   } finally {
      AssertionLoggerHandler.stopCapture();
   }
}
 
Example #22
Source File: XmlFormatterTest.java    From jboss-logmanager-ext with Apache License 2.0 4 votes vote down vote up
private static void compare(final ExtLogRecord record, final String xmlString) throws XMLStreamException {
    final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    final XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xmlString));

    boolean inException = false;
    while (reader.hasNext()) {
        final int state = reader.next();
        if (state == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals(Key.EXCEPTION.getKey())) {
            inException = false;
        }
        if (state == XMLStreamConstants.START_ELEMENT) {
            final String localName = reader.getLocalName();
            if (localName.equals(Key.EXCEPTION.getKey())) {
                inException = true;// TODO (jrp) stack trace may need to be validated
            } else if (localName.equals(Key.LEVEL.getKey())) {
                Assert.assertEquals(record.getLevel(), Level.parse(getString(reader)));
            } else if (localName.equals(Key.LOGGER_CLASS_NAME.getKey())) {
                Assert.assertEquals(record.getLoggerClassName(), getString(reader));
            } else if (localName.equals(Key.LOGGER_NAME.getKey())) {
                Assert.assertEquals(record.getLoggerName(), getString(reader));
            } else if (localName.equals(Key.MDC.getKey())) {
                compareMap(record.getMdcCopy(), getMap(reader));
            } else if (!inException && localName.equals(Key.MESSAGE.getKey())) {
                Assert.assertEquals(record.getFormattedMessage(), getString(reader));
            } else if (localName.equals(Key.NDC.getKey())) {
                final String value = getString(reader);
                Assert.assertEquals(record.getNdc(), (value == null ? "" : value));
            } else if (localName.equals(Key.SEQUENCE.getKey())) {
                Assert.assertEquals(record.getSequenceNumber(), getLong(reader));
            } else if (localName.equals(Key.SOURCE_CLASS_NAME.getKey())) {
                Assert.assertEquals(record.getSourceClassName(), getString(reader));
            } else if (localName.equals(Key.SOURCE_FILE_NAME.getKey())) {
                Assert.assertEquals(record.getSourceFileName(), getString(reader));
            } else if (localName.equals(Key.SOURCE_LINE_NUMBER.getKey())) {
                Assert.assertEquals(record.getSourceLineNumber(), getInt(reader));
            } else if (localName.equals(Key.SOURCE_METHOD_NAME.getKey())) {
                Assert.assertEquals(record.getSourceMethodName(), getString(reader));
            } else if (localName.equals(Key.THREAD_ID.getKey())) {
                Assert.assertEquals(record.getThreadID(), getInt(reader));
            } else if (localName.equals(Key.THREAD_NAME.getKey())) {
                Assert.assertEquals(record.getThreadName(), getString(reader));
            } else if (localName.equals(Key.TIMESTAMP.getKey())) {
                final SimpleDateFormat sdf = new SimpleDateFormat(StructuredFormatter.DEFAULT_DATE_FORMAT);
                Assert.assertEquals(sdf.format(new Date(record.getMillis())), getString(reader));
            }
        }
    }
}
 
Example #23
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void error(Object message, Throwable t, Object... params) {
    log(Level.ERROR, message, t, params);
}
 
Example #24
Source File: JBossLogManagerTest.java    From ecs-logging-java with Apache License 2.0 4 votes vote down vote up
@Override
public void error(String message, Throwable t) {
    logger.log(Level.ERROR, message, t);
}
 
Example #25
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isWarnEnabled() {
    return logger.isLoggable(Level.WARN);
}
 
Example #26
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public boolean isInfoEnabled() {
    return logger.isLoggable(Level.INFO);
}
 
Example #27
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public boolean isDebugEnabled() {
    return logger.isLoggable(Level.DEBUG);
}
 
Example #28
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public boolean isTraceEnabled() {
    return logger.isLoggable(Level.TRACE);
}
 
Example #29
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void fatal(final Object message) {
    log(Level.FATAL, message);
}
 
Example #30
Source File: VertxLogDelegate.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void fatal(final Object message, final Throwable t) {
    log(Level.FATAL, message, t);
}