0

我以前有问题,而应用程序在控制台中打印所有日志。然后在关注一些帖子之后,我能够将日志打印到单独的应用程序日志中。

现在,在重新启动应用程序服务器(IBM WAS 8.5)时,它会将一些 SystemOut 日志打印到新创建的应用程序日志中。

Gradle build,排除了一些来自其他依赖项的 jars

            exclude(group: 'org.slf4j', module:'slf4j-nop')
            all*.exclude group: "javax.servlet", module: "servlet-api"
            all*.exclude group: "org.slf4j", module: "log4j-over-slf4j"
            all*.exclude group: "org.slf4j", module: "slf4j-log4j12"
            all*.exclude group: "log4j", module: "log4j"

application.properties :-

        logging.file=MySpringBoot-applicaiton.log

和 logback.xml:-

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <include resource="org/springframework/boot/logging/logback/defaults.xml" />
        <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
        <include resource="org/springframework/boot/logging/logback/file-appender.xml" />

        <root level="INFO">
            <appender-ref ref="FILE" />
        </root>
    </configuration>

MySpringBoot-applicaiton.log

>     [server.startup : 1] o.s.integration.channel.DirectChannel    : Channel 'application.sendXXXXXXXXRequestChannel' has 1 subscriber(s).
>     [server.startup : 1] o.s.i.endpoint.EventDrivenConsumer       : started sendXXXXXXXOutboundGateway
>     [server.startup : 1] o.s.i.endpoint.EventDrivenConsumer       : Adding {ws:outbound-gateway(marshaling):sendXXXXXXXXOutboundGateway}
> as a subscriber to the 'sendXXXXXXXXXRequestChannel' channel
>     [server.startup : 1] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
>     [server.startup : 1] com.XXX.XXX.api.rest.ServletInitializer  : Started ServletInitializer in 47.992 seconds (JVM running for 142.685)
>     [server.startup : 1] com.ibm.ws.webcontainer.webapp           : SRVE0292I: Servlet Message -
> [MySpringBootEar-FUT.SNAPSHOT-0#MySpringBootWeb.war]:.Initializing
> Spring FrameworkServlet 'dispatcherServlet'
>     [server.startup : 1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
>     [server.startup : 1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 47
> ms
>     [server.startup : 1] c.i.w.w.servlet.ServletWrapper           : SRVE0242I: [MySpringBootEar-FUT.SNAPSHOT-0] [/mycustomurl]
> [dispatcherServlet]: Initialization successful.
>     [server.startup : 1] com.ibm.ws.webcontainer.webapp           : SRVE0292I: Servlet Message -
> [MySpringBootEar-FUT.SNAPSHOT-0#MySpringBootWar.war]:.Initializing
> Spring FrameworkServlet 'messageDispatcherServlet'
>     [server.startup : 1] o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet 'messageDispatcherServlet': initialization started
>     [server.startup : 1] o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet 'messageDispatcherServlet': initialization completed
> in 31 ms
>     [server.startup : 1] c.i.w.w.servlet.ServletWrapper           : SRVE0242I: [MySpringBootEar-FUT.SNAPSHOT-0] [/mycustomurl]
> [messageDispatcherServlet]: Initialization successful.
>     [server.startup : 1] com.ibm.ws.webcontainer.webapp           : SRVE0278E: Error while adding servlet mapping --> /*.
>     [server.startup : 1] com.ibm.ws.webcontainer                  : SRVE0250I: Web Module null has been bound to
> default_host[*:9080,*:80,*:9443,*:5060,*:5061,*:443].

在最后两行日志中,它是来自服务器的消息,现在正在打印到应用程序日志中。

==================================================== ================= 更新:

2018-11-06 15:40:24.291  WARN 27132 --- [P=756984:O=0:CT] com.ibm.ws.runtime.WsServerImpl          : WSVR0001I: Server server1 open for e-business

在将 logback 与 springboot 一起使用时,上面的行现在正在打印到应用程序日志中。没有 logback xml 配置只是添加logging.file=applicaiton.properties文件中。

上面的日志是 IBM WebSphere 日志。这是如何进入我的应用程序日志的。

4

1 回答 1

0

我遇到了类似的问题。您可以通过在 logback.xml 中添加以下内容将服务器启动相关信息从应用程序日志重定向到 websphere stdout.log:-

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </layout>
</appender>

<logger name="com.ibm.ws.runtime" level="warn"
    additivity="false">
    <appender-ref ref="STDOUT" />
</logger>

<root level="WARN">
    <appender-ref ref="STDOUT" />
</root>
于 2019-01-30T07:45:27.957 回答