带有引导的Spring-boot将一些系统日志打印到应用程序日志中

时间:2018-10-30 19:28:25

标签: spring-boot websphere logback logback-classic spring-logback

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

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

Gradle build ,排除了一些jar,因为它们来自其他依赖项

            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日志。这如何进入我的申请日志。

1 个答案:

答案 0 :(得分: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>