简体   繁体   English

System.out.println无法打印到控制台

[英]System.out.println not printing to console

I have a Spring web app running on Wildfly 8.* and for some reason it won't print to the console. 我有一个在Wildfly 8. *上运行的Spring Web应用程序,由于某种原因,它不会打印到控制台。 I see all the console logs and stack traces fine but the System messages just don't appear. 我看到所有控制台日志和堆栈跟踪都很好,但是系统消息却没有出现。

The problem might be with my log4j setup so I'll post that config; 问题可能出在我的log4j设置上,所以我将发布该配置。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration  PUBLIC
  "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="true"
    xmlns:log4j='http://jakarta.apache.org/log4j/'>

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" 
          value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <root>
        <level value="DEBUG" />
        <appender-ref ref="console" />
    </root>
</log4j:configuration>

I've ran apps on JBoss 7.1 before however without this problem so I'm really at a loss on what could be wrong. 我之前在JBoss 7.1上运行过应用程序,但是没有这个问题,所以我对可能出了什么问题真的很茫然。

Feel free to ask about any of my other config not sure what would be needed. 随意询问我的任何其他配置,不确定是否需要什么。

Edit: 编辑:

logger.org.jboss.as.config.level=DEBUG
logger.org.jboss.as.config.useParentHandlers=true

logger.jacorb.config.level=ERROR
logger.jacorb.config.useParentHandlers=true

logger.org.apache.tomcat.util.modeler.level=WARN
logger.org.apache.tomcat.util.modeler.useParentHandlers=true

logger.com.arjuna.level=WARN
logger.com.arjuna.useParentHandlers=true

handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.level=INFO
handler.CONSOLE.formatter=COLOR-PATTERN
handler.CONSOLE.properties=autoFlush,target,enabled
handler.CONSOLE.autoFlush=true
handler.CONSOLE.target=SYSTEM_OUT
handler.CONSOLE.enabled=true

handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=ALL
handler.FILE.formatter=PATTERN
handler.FILE.properties=append,autoFlush,enabled,suffix,fileName
handler.FILE.constructorProperties=fileName,append
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.enabled=true
handler.FILE.suffix=.yyyy-MM-dd
handler.FILE.fileName=C\:\\wildfly-8.2.0.Final\\standalone\\log\\server.log

formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n

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

Here is my logging config in my standalone deployments folder. 这是我的独立部署文件夹中的日志记录配置。

几年前,我在.war(WEB-INF / classes)的根目录下有一个log4j.properties文件,该文件引起了同样的问题-删除已将其修复

Since you are using a logging framework, there are 2 ways to fix it: 由于您使用的是日志记录框架,因此有两种方法可以修复它:

  1. Remove the logging framework and all the configuration files (why would I do that) 删除日志记录框架和所有配置文件(为什么要这样做)
  2. Move your log4j.properties file from src/main/resources to WEB-INF folder. 将您的log4j.properties文件从src/main/resources移至WEB-INF文件夹。

Quoting: JBoss Docs , Section 'Per Deployment Logging' 引用: JBoss Docs的 “每部署日志记录”部分

Per-deployment logging allows you to add a logging configuration file to your deployment and have the logging for that deployment configured according to the configuration file. 按部署日志记录允许您将日志记录配置文件添加到部署中,并根据配置文件为该部署配置日志记录。 In an EAR the configuration should be in the META-INF directory. 在EAR中,配置应位于META-INF目录中。 In a WAR or JAR deployment the configuration file can be in either the META-INF or WEB-INF/classes directories. 在WAR或JAR部署中,配置文件可以位于META-INF或WEB-INF / classes目录中。 The following configuration files are allowed: 允许使用以下配置文件:

  • logging.properties logging.properties
  • jboss-logging.properties jboss-logging.properties
  • log4j.properties log4j.properties
  • log4j.xml log4j.xml
  • jboss-log4j.xml jboss-log4j.xml

I usually have trouble configuring logs per deployment in wildfly, but you can use the logging system from wildfly, changing logging configuration of your standalone ou domain config files to this would do the trick: 我通常在wildfly中为每个部署配置日志时遇到麻烦,但是您可以使用wildfly中的日志记录系统,将独立的ou域配置文件的日志记录配置更改为此可以解决问题:

<root-logger>
    <level name="TRACE"/>
    <handlers>
        <handler name="CONSOLE"/>
        <handler name="FILE"/>
    </handlers>
</root-logger>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM