Java Code Examples for org.apache.rocketmq.logging.InternalLogger#info()

The following examples show how to use org.apache.rocketmq.logging.InternalLogger#info() . 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: LoggerTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerConsoleLogger() throws IOException {
    PrintStream out = System.out;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(byteArrayOutputStream));

    Appender consoleAppender = LoggingBuilder.newAppenderBuilder()
        .withConsoleAppender(LoggingBuilder.SYSTEM_OUT)
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    Logger.getLogger("ConsoleLogger").addAppender(consoleAppender);
    Logger.getLogger("ConsoleLogger").setLevel(Level.INFO);

    InternalLogger consoleLogger1 = InternalLoggerFactory.getLogger("ConsoleLogger");
    consoleLogger1.info("console info Message");
    consoleLogger1.error("console error Message", new RuntimeException());
    consoleLogger1.debug("console debug message");

    consoleLogger1.info("console {} test", "simple");
    consoleLogger1.info("[WATERMARK] Send Queue Size: {} SlowTimeMills: {}", 1, 300);
    consoleLogger1.info("new consumer connected, group: {} {} {} channel: {}", "mygroup", "orderly",
        "broudcast", new RuntimeException("simple object"));

    System.setOut(out);
    consoleAppender.close();

    String result = new String(byteArrayOutputStream.toByteArray());

    System.out.println(result);

    Assert.assertTrue(result.contains("info"));
    Assert.assertTrue(result.contains("RuntimeException"));
    Assert.assertTrue(result.contains("WATERMARK"));
    Assert.assertTrue(result.contains("consumer"));
    Assert.assertTrue(result.contains("broudcast"));
    Assert.assertTrue(result.contains("simple test"));
    Assert.assertTrue(!result.contains("debug"));
}
 
Example 2
Source File: LoggerTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerFileLogger() throws IOException {
    String file = loggingDir + "/inner.log";

    Logger fileLogger = Logger.getLogger("innerLogger");

    Appender myappender = LoggingBuilder.newAppenderBuilder()
        .withDailyFileRollingAppender(file, "'.'yyyy-MM-dd")
        .withName("innerAppender")
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    fileLogger.addAppender(myappender);
    fileLogger.setLevel(Level.INFO);

    InternalLogger innerLogger = InternalLoggerFactory.getLogger("innerLogger");

    innerLogger.info("fileLogger info Message");
    innerLogger.error("fileLogger error Message", new RuntimeException());
    innerLogger.debug("fileLogger debug message");

    myappender.close();

    String content = readFile(file);

    System.out.println(content);

    Assert.assertTrue(content.contains("info"));
    Assert.assertTrue(content.contains("RuntimeException"));
    Assert.assertTrue(!content.contains("debug"));
}
 
Example 3
Source File: MQHelper.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
/**
 * Reset consumer topic offset according to time 根据时间重置消费者主题偏移量
 *
 * @param messageModel which model
 * @param instanceName which instance
 * @param consumerGroup consumer group
 * @param topic topic
 * @param timestamp time
 */
public static void resetOffsetByTimestamp(
    final MessageModel messageModel,
    final String instanceName,
    final String consumerGroup,
    final String topic,
    final long timestamp) throws Exception {
    final InternalLogger log = ClientLogger.getLog();

    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
    consumer.setInstanceName(instanceName);
    consumer.setMessageModel(messageModel);
    consumer.start();

    Set<MessageQueue> mqs = null;
    try {
        mqs = consumer.fetchSubscribeMessageQueues(topic);
        if (mqs != null && !mqs.isEmpty()) {
            TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
            for (MessageQueue mq : mqsNew) {
                long offset = consumer.searchOffset(mq, timestamp);
                if (offset >= 0) {
                    consumer.updateConsumeOffset(mq, offset);
                    log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
                        consumerGroup, offset, mq);
                }
            }
        }
    } catch (Exception e) {
        log.warn("resetOffsetByTimestamp Exception", e);
        throw e;
    } finally {
        if (mqs != null) {
            consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
        }
        consumer.shutdown();
    }
}
 
Example 4
Source File: FilterServerUtil.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static void callShell(final String shellString, final InternalLogger log) {
    Process process = null;
    try {
        String[] cmdArray = splitShellString(shellString);
        process = Runtime.getRuntime().exec(cmdArray);
        process.waitFor();
        log.info("CallShell: <{}> OK", shellString);
    } catch (Throwable e) {
        log.error("CallShell: readLine IOException, {}", shellString, e);
    } finally {
        if (null != process)
            process.destroy();
    }
}
 
Example 5
Source File: MixAll.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static void printObjectProperties(final InternalLogger logger, final Object object,
    final boolean onlyImportantField) {
    Field[] fields = object.getClass().getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            String name = field.getName();
            if (!name.startsWith("this")) {
                Object value = null;
                try {
                    field.setAccessible(true);
                    value = field.get(object);
                    if (null == value) {
                        value = "";
                    }
                } catch (IllegalAccessException e) {
                    log.error("Failed to obtain object properties", e);
                }

                if (onlyImportantField) {
                    Annotation annotation = field.getAnnotation(ImportantField.class);
                    if (null == annotation) {
                        continue;
                    }
                }

                if (logger != null) {
                    logger.info(name + "=" + value);
                } else {
                }
            }
        }
    }
}
 
Example 6
Source File: LoggerTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerConsoleLogger() throws IOException {
    PrintStream out = System.out;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(byteArrayOutputStream));

    Appender consoleAppender = LoggingBuilder.newAppenderBuilder()
        .withConsoleAppender(LoggingBuilder.SYSTEM_OUT)
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    Logger.getLogger("ConsoleLogger").addAppender(consoleAppender);
    Logger.getLogger("ConsoleLogger").setLevel(Level.INFO);

    InternalLogger consoleLogger1 = InternalLoggerFactory.getLogger("ConsoleLogger");
    consoleLogger1.info("console info Message");
    consoleLogger1.error("console error Message", new RuntimeException());
    consoleLogger1.debug("console debug message");

    consoleLogger1.info("console {} test", "simple");
    consoleLogger1.info("[WATERMARK] Send Queue Size: {} SlowTimeMills: {}", 1, 300);
    consoleLogger1.info("new consumer connected, group: {} {} {} channel: {}", "mygroup", "orderly",
        "broudcast", new RuntimeException("simple object"));

    System.setOut(out);
    consoleAppender.close();

    String result = new String(byteArrayOutputStream.toByteArray());

    System.out.println(result);

    Assert.assertTrue(result.contains("info"));
    Assert.assertTrue(result.contains("RuntimeException"));
    Assert.assertTrue(result.contains("WATERMARK"));
    Assert.assertTrue(result.contains("consumer"));
    Assert.assertTrue(result.contains("broudcast"));
    Assert.assertTrue(result.contains("simple test"));
    Assert.assertTrue(!result.contains("debug"));
}
 
Example 7
Source File: LoggerTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerFileLogger() throws IOException {
    String file = loggingDir + "/inner.log";

    Logger fileLogger = Logger.getLogger("innerLogger");

    Appender myappender = LoggingBuilder.newAppenderBuilder()
        .withDailyFileRollingAppender(file, "'.'yyyy-MM-dd")
        .withName("innerAppender")
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    fileLogger.addAppender(myappender);
    fileLogger.setLevel(Level.INFO);

    InternalLogger innerLogger = InternalLoggerFactory.getLogger("innerLogger");

    innerLogger.info("fileLogger info Message");
    innerLogger.error("fileLogger error Message", new RuntimeException());
    innerLogger.debug("fileLogger debug message");

    myappender.close();

    String content = readFile(file);

    System.out.println(content);

    Assert.assertTrue(content.contains("info"));
    Assert.assertTrue(content.contains("RuntimeException"));
    Assert.assertTrue(!content.contains("debug"));
}
 
Example 8
Source File: FilterServerUtil.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void callShell(final String shellString, final InternalLogger log) {
    Process process = null;
    try {
        String[] cmdArray = splitShellString(shellString);
        process = Runtime.getRuntime().exec(cmdArray);
        process.waitFor();
        log.info("CallShell: <{}> OK", shellString);
    } catch (Throwable e) {
        log.error("CallShell: readLine IOException, {}", shellString, e);
    } finally {
        if (null != process) {
            process.destroy();
        }
    }
}
 
Example 9
Source File: MixAll.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 打印对象的属性
 * @param logger logger
 * @param object object
 * @param onlyImportantField 是否只打印onlyImportantField的文件
 */
public static void printObjectProperties(final InternalLogger logger, final Object object,
    final boolean onlyImportantField) {

    Field[] fields = object.getClass().getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            String name = field.getName();
            if (!name.startsWith("this")) {
                Object value = null;
                try {
                    field.setAccessible(true);
                    value = field.get(object);
                    if (null == value) {
                        value = "";
                    }
                } catch (IllegalAccessException e) {
                    log.error("Failed to obtain object properties", e);
                }

                if (onlyImportantField) {
                    Annotation annotation = field.getAnnotation(ImportantField.class);
                    if (null == annotation) {
                        continue;
                    }
                }

                if (logger != null) {
                    logger.info(name + "=" + value);
                }
            }
        }
    }
}
 
Example 10
Source File: LoggerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerConsoleLogger() throws IOException {
    PrintStream out = System.out;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(byteArrayOutputStream));

    Appender consoleAppender = LoggingBuilder.newAppenderBuilder()
        .withConsoleAppender(LoggingBuilder.SYSTEM_OUT)
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    Logger.getLogger("ConsoleLogger").addAppender(consoleAppender);
    Logger.getLogger("ConsoleLogger").setLevel(Level.INFO);

    InternalLogger consoleLogger1 = InternalLoggerFactory.getLogger("ConsoleLogger");
    consoleLogger1.info("console info Message");
    consoleLogger1.error("console error Message", new RuntimeException());
    consoleLogger1.debug("console debug message");

    consoleLogger1.info("console {} test", "simple");
    consoleLogger1.info("[WATERMARK] Send Queue Size: {} SlowTimeMills: {}", 1, 300);
    consoleLogger1.info("new consumer connected, group: {} {} {} channel: {}", "mygroup", "orderly",
        "broudcast", new RuntimeException("simple object"));

    System.setOut(out);
    consoleAppender.close();

    String result = new String(byteArrayOutputStream.toByteArray());

    System.out.println(result);

    Assert.assertTrue(result.contains("info"));
    Assert.assertTrue(result.contains("RuntimeException"));
    Assert.assertTrue(result.contains("WATERMARK"));
    Assert.assertTrue(result.contains("consumer"));
    Assert.assertTrue(result.contains("broudcast"));
    Assert.assertTrue(result.contains("simple test"));
    Assert.assertTrue(!result.contains("debug"));
}
 
Example 11
Source File: LoggerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testInnerFileLogger() throws IOException {
    String file = loggingDir + "/inner.log";

    Logger fileLogger = Logger.getLogger("innerLogger");

    Appender myappender = LoggingBuilder.newAppenderBuilder()
        .withDailyFileRollingAppender(file, "'.'yyyy-MM-dd")
        .withName("innerAppender")
        .withLayout(LoggingBuilder.newLayoutBuilder().withDefaultLayout().build()).build();

    fileLogger.addAppender(myappender);
    fileLogger.setLevel(Level.INFO);

    InternalLogger innerLogger = InternalLoggerFactory.getLogger("innerLogger");

    innerLogger.info("fileLogger info Message");
    innerLogger.error("fileLogger error Message", new RuntimeException());
    innerLogger.debug("fileLogger debug message");

    myappender.close();

    String content = readFile(file);

    System.out.println(content);

    Assert.assertTrue(content.contains("info"));
    Assert.assertTrue(content.contains("RuntimeException"));
    Assert.assertTrue(!content.contains("debug"));
}
 
Example 12
Source File: MQHelper.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * Reset consumer topic offset according to time
 *
 * @param messageModel which model
 * @param instanceName which instance
 * @param consumerGroup consumer group
 * @param topic topic
 * @param timestamp time
 */
public static void resetOffsetByTimestamp(
    final MessageModel messageModel,
    final String instanceName,
    final String consumerGroup,
    final String topic,
    final long timestamp) throws Exception {
    final InternalLogger log = ClientLogger.getLog();

    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
    consumer.setInstanceName(instanceName);
    consumer.setMessageModel(messageModel);
    consumer.start();

    Set<MessageQueue> mqs = null;
    try {
        mqs = consumer.fetchSubscribeMessageQueues(topic);
        if (mqs != null && !mqs.isEmpty()) {
            TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
            for (MessageQueue mq : mqsNew) {
                long offset = consumer.searchOffset(mq, timestamp);
                if (offset >= 0) {
                    consumer.updateConsumeOffset(mq, offset);
                    log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
                        consumerGroup, offset, mq);
                }
            }
        }
    } catch (Exception e) {
        log.warn("resetOffsetByTimestamp Exception", e);
        throw e;
    } finally {
        if (mqs != null) {
            consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
        }
        consumer.shutdown();
    }
}
 
Example 13
Source File: FilterServerUtil.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void callShell(final String shellString, final InternalLogger log) {
    Process process = null;
    try {
        String[] cmdArray = splitShellString(shellString);
        process = Runtime.getRuntime().exec(cmdArray);
        process.waitFor();
        log.info("CallShell: <{}> OK", shellString);
    } catch (Throwable e) {
        log.error("CallShell: readLine IOException, {}", shellString, e);
    } finally {
        if (null != process)
            process.destroy();
    }
}
 
Example 14
Source File: MixAll.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void printObjectProperties(final InternalLogger logger, final Object object,
    final boolean onlyImportantField) {
    Field[] fields = object.getClass().getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            String name = field.getName();
            if (!name.startsWith("this")) {
                Object value = null;
                try {
                    field.setAccessible(true);
                    value = field.get(object);
                    if (null == value) {
                        value = "";
                    }
                } catch (IllegalAccessException e) {
                    log.error("Failed to obtain object properties", e);
                }

                if (onlyImportantField) {
                    Annotation annotation = field.getAnnotation(ImportantField.class);
                    if (null == annotation) {
                        continue;
                    }
                }

                if (logger != null) {
                    logger.info(name + "=" + value);
                } else {
                }
            }
        }
    }
}