Keycloak/Wildfly 如何将所有控制台日志配置为 JSON 格式

Keycloak/Wildfly How to configure all console logs to JSON format

我正在使用官方 Keycloak 图像并尝试为这样的控制台日志设置 JSON 格式

startup.cli

embed-server --server-config=standalone-ha.xml --std-out=echo

/subsystem=logging/json-formatter=JSON:add(exception-output-type=formatted)
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter,value=JSON)

stop-embedded-server

码头文件

FROM jboss/keycloak:12.0.1
COPY $GIT_KEYCLOAK_HOME/CI/startup.cli /opt/jboss/startup-scripts/startup.cli

有点效果。但是,并非所有日志都采用 JSON 格式。一开始有一大块(我相信这些是一些父 JBoss bootstrap 日志)仍然是常规格式。而且好像standalone.xml里面没有handler(至少我没找到)

我的问题是如何更改或禁用那些非 JSON 格式的日志。

日志输出:

-b 0.0.0.0

=========================================================================

Using Embedded H2 database

=========================================================================

Executing cli script: /opt/jboss/startup-scripts/startup.cli

11:12:05,763 INFO [org.jboss.modules] (CLI command executor) JBoss Modules version 1.10.2.Final

11:12:05,903 INFO [org.jboss.msc] (CLI command executor) JBoss MSC version 1.4.12.Final

11:12:05,914 INFO [org.jboss.threads] (CLI command executor) JBoss Threads version 2.4.0.Final

11:12:06,096 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Keycloak 12.0.1 (WildFly Core 13.0.3.Final) starting

11:12:06,243 INFO [org.jboss.vfs] (MSC service thread 1-3) VFS000002: Failed to clean existing content for temp file provider of type temp. Enable DEBUG level log to find what caused this

11:12:07,154 INFO [org.wildfly.security] (ServerService Thread Pool -- 20) ELY00001: WildFly Elytron version 1.13.1.Final

11:12:08,345 INFO [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

11:12:08,464 INFO [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

11:12:08,675 INFO [org.jboss.as.patching] (MSC service thread 1-5) WFLYPAT0050: Keycloak cumulative patch ID is: base, one-off patches include: none

11:12:08,692 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-2) WFLYDM0111: Keystore /opt/jboss/keycloak/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost

11:12:08,836 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server

11:12:08,840 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 12.0.1 (WildFly Core 13.0.3.Final) started in 3063ms - Started 56 of 86 services (39 services are lazy, passive or on-demand)

{"outcome" => "success"}

{"outcome" => "success"}

11:12:09,126 INFO [org.jboss.as] (MSC service thread 1-4) WFLYSRV0050: Keycloak 12.0.1 (WildFly Core 13.0.3.Final) stopped in 25ms

=========================================================================

JBoss Bootstrap Environment

JBOSS_HOME: /opt/jboss/keycloak

JAVA: java

JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED

=========================================================================

11:12:09,983 INFO [org.jboss.modules] (main) JBoss Modules version 1.10.2.Final

11:12:10,610 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.12.Final

11:12:10,624 INFO [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final

11:12:10,773 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Keycloak 12.0.1 (WildFly Core 13.0.3.Final) starting

11:12:10,920 INFO [org.jboss.vfs] (MSC service thread 1-6) VFS000002: Failed to clean existing content for temp file provider of type temp. Enable DEBUG level log to find what caused this

11:12:11,679 INFO [org.wildfly.security] (ServerService Thread Pool -- 20) ELY00001: WildFly Elytron version 1.13.1.Final

11:12:12,729 INFO [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

11:12:12,773 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 10) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

11:12:13,039 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)

11:12:13,073 INFO [org.xnio] (MSC service thread 1-5) XNIO version 3.8.2.Final

11:12:13,083 INFO [org.xnio.nio] (MSC service thread 1-5) XNIO NIO Implementation Version 3.8.2.Final

11:12:13,156 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 39) WFLYCLINF0001: Activating Infinispan subsystem.

11:12:13,170 INFO [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 5.0.19.Final

11:12:13,203 INFO [org.wildfly.extension.microprofile.config.smallrye._private] (ServerService Thread Pool -- 48) WFLYCONF0001: Activating WildFly MicroProfile Config Subsystem

11:12:13,234 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 52) WFLYNAM0001: Activating Naming Subsystem

11:12:13,238 INFO [org.jboss.as.clustering.jgroups] (ServerService Thread Pool -- 43) WFLYCLJG0001: Activating JGroups subsystem. JGroups version 4.2.5

11:12:13,193 INFO [org.jboss.as.connector] (MSC service thread 1-6) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.23.Final)

11:12:13,210 INFO [org.jboss.as.jaxrs] (ServerService Thread Pool -- 41) WFLYRS0016: RESTEasy version 3.13.2.Final

11:12:13,257 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 34) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)

11:12:13,251 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 40) WFLYIO001: Worker 'default' has auto-configured to 16 IO threads with 128 max task threads based on your 8 available processors

11:12:13,263 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = h2

11:12:13,286 INFO [org.jboss.as.security] (ServerService Thread Pool -- 55) WFLYSEC0002: Activating Security Subsystem

11:12:13,287 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 57) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.

11:12:13,316 INFO [org.wildfly.extension.microprofile.metrics.smallrye] (ServerService Thread Pool -- 50) WFLYMETRICS0001: Activating Eclipse MicroProfile Metrics Subsystem

11:12:13,340 INFO [org.jboss.as.security] (MSC service thread 1-8) WFLYSEC0001: Current PicketBox version=5.0.3.Final-redhat-00006

11:12:13,345 INFO [org.wildfly.extension.microprofile.health.smallrye] (ServerService Thread Pool -- 49) WFLYHEALTH0001: Activating Eclipse MicroProfile Health Subsystem

11:12:13,390 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]

11:12:13,396 INFO [org.jboss.as.naming] (MSC service thread 1-4) WFLYNAM0003: Starting Naming Service

11:12:13,427 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0003: Undertow 2.2.2.Final starting

11:12:13,469 WARN [org.wildfly.clustering.web.undertow] (ServerService Thread Pool -- 58) WFLYCLWEBUT0007: No routing provider found for default-server; using legacy provider based on static configuration

11:12:13,541 INFO [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 32 (per class), which is derived from the number of CPUs on this host.

11:12:13,541 INFO [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 128 (per class), which is derived from thread worker pool sizing.

11:12:13,596 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0014: Creating file handler for path '/opt/jboss/keycloak/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']

11:12:13,611 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0012: Started server default-server.

11:12:13,627 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0018: Host default-host starting

11:12:13,740 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTP listener default listening on 0.0.0.0:8080

11:12:13,752 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow AJP listener ajp listening on 0.0.0.0:8009

11:12:13,772 INFO [org.jboss.modcluster] (ServerService Thread Pool -- 60) MODCLUSTER000001: Initializing mod_cluster version 1.4.1.Final

11:12:13,834 INFO [org.jboss.modcluster] (ServerService Thread Pool -- 60) MODCLUSTER000032: Listening to proxy advertisements on /224.0.1.105:23364

11:12:14,075 INFO [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0493: EJB subsystem suspension complete

11:12:14,096 INFO [org.jboss.as.patching] (MSC service thread 1-2) WFLYPAT0050: Keycloak cumulative patch ID is: base, one-off patches include: none

11:12:14,131 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-4) WFLYDM0111: Keystore /opt/jboss/keycloak/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost

{"timestamp":"2021-05-28T11:12:14.141Z","sequence":45,"loggerClassName":"org.jboss.as.server.deployment.scanner.logging.DeploymentScannerLogger_$logger","loggerName":"org.jboss.as.server.deployment.scanner","level":"INFO","message":"WFLYDS0013: Started FileSystemDeploymentService for directory /opt/jboss/keycloak/standalone/deployments","threadName":"MSC service thread 1-5","threadId":20,"mdc":{},"ndc":"","hostName":"4fda77e3f17e","processName":"jboss-modules.jar","processId":265}

{"timestamp":"2021-05-28T11:12:14.154Z","sequence":46,"loggerClassName":"org.jboss.as.server.logging.ServerLogger_$logger","loggerName":"org.jboss.as.server.deployment","level":"INFO","message":"WFLYSRV0027: Starting deployment of \"keycloak-server.war\" (runtime-name: \"keycloak-server.war\")","threadName":"MSC service thread 1-6","threadId":21,"mdc":{},"ndc":"","hostName":"4fda77e3f17e","processName":"jboss-modules.jar","processId":265}

{"timestamp":"2021-05-28T11:12:14.234Z","sequence":47,"loggerClassName":"org.jboss.as.connector.logging.ConnectorLogger_$logger","loggerName":"org.jboss.as.connector.subsystems.datasources","level":"INFO","message":"WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]","threadName":"MSC service thread 1-6","threadId":21,"mdc":{},"ndc":"","hostName":"4fda77e3f17e","processName":"jboss-modules.jar","processId":265}

{"timestamp":"2021-05-28T11:12:14.246Z","sequence":48,"loggerClassName":"org.jboss.as.connector.logging.ConnectorLogger_$logger","loggerName":"org.jboss.as.connector.subsystems.datasources","level":"INFO","message":"WFLYJCA0001: Bound data source [java:jboss/datasources/KeycloakDS]","threadName":"MSC service thread 1-2","threadId":17,"mdc":{},"ndc":"","hostName":"4fda77e3f17e","processName":"jboss-modules.jar","processId":265}

这是因为在初始引导期间,一个 logging.properties 文件用于配置日志管理器,直到日志子系统被激活。有两种选择。

  1. 您将已配置的 logging.propertiesstandalone-ha.xml 复制到您的映像中。
  2. 在您 DockerfileRUN 命令中,通过启动服务器配置日志记录,然后执行 CLI 脚本。