Wildlfy CLI 调试嵌入式模式

huangapple go评论52阅读模式
英文:

Wildlfy CLI debugging in embedded mode

问题

在创建嵌入式服务器时通过 EmbeddedProcessFactory.createStandaloneServer,没有可能启用标准输出回显——不允许使用 --std-out=echo 参数。现在在此服务器上调用 CLI 命令会丢弃所有输出,如果有任何错误消息不具有意义,如何调试这个问题?

英文:

When creating an embedded server via

EmbeddedProcessFactory.createStandaloneServer

there is no possibility to enable stdout echoing - the command --std-out=echo arg is not allowed here.

Now calling CLI commands on this server discards all the output and if any error message is not meaningful, how to debug this?

答案1

得分: 2

如果您直接使用WildFly嵌入式服务器,可以通过任何日志管理器来控制日志记录。默认情况下,这将使用JBoss日志管理器。您只需确保logging.properties文件在类路径上。以下是JBoss日志管理器的示例配置:

# 要配置的其他日志记录器名称(根记录器始终已配置)
loggers=

# 根记录器级别
logger.level=INFO

# 根记录器处理程序
logger.handlers=CONSOLE

# 控制台处理程序配置
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN

# 格式化程序模式配置
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n

您也可以使用其他日志管理器,例如logback或log4j2。使用Configuration.Builder,您可以设置日志提示。以下是使用log4j2的示例:

final StandaloneServer server = EmbeddedProcessFactory.createStandaloneServer(
        Configuration.Builder.of(Path.of("/opt/wildfly-27.0.1.Final"))
                .setLoggerHint(Configuration.LoggerHint.LOG4J2)
                .build());
try {
    server.start();
    try (ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990)) {
        final ModelNode op = Operations.createOperation("read-resource");
        op.get("attributes-only").set(true);
        System.out.println(client.execute(op));
    }
} finally {
    server.stop();
}

不要翻译代码部分。

英文:

If you're using the WildFly embedded server directly, you can control logging via any log manager. By default this will use the JBoss Log Manager. You'd just need to make sure a logging.properties file is on your class path. Here is an example configuration for the JBoss Log Manager.

# Additional logger names to configure (root logger is always configured)
loggers=

# Root logger level
logger.level=INFO

# Root logger handlers
logger.handlers=CONSOLE

# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN

# Formatter pattern configuration
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n

You could use a different log manager as well like logback or log4j2. With the Configuration.Builder you'd set the logging hint. Here is an example using log4j2.

<!-- language: lang-java -->

final StandaloneServer server = EmbeddedProcessFactory.createStandaloneServer(
        Configuration.Builder.of(Path.of(&quot;/opt/wildfly-27.0.1.Final&quot;))
                .setLoggerHint(Configuration.LoggerHint.LOG4J2)
                .build());
try {
    server.start();
    try (ModelControllerClient client = ModelControllerClient.Factory.create(&quot;localhost&quot;, 9990)) {
        final ModelNode op = Operations.createOperation(&quot;read-resource&quot;);
        op.get(&quot;attributes-only&quot;).set(true);
        System.out.println(client.execute(op));
    }
} finally {
    server.stop();
}

huangapple
  • 本文由 发表于 2023年4月17日 14:55:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032408.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定