How to make log4j not to prints stdout, thread name - java

Why does log4j print:
17:58:30,623 INFO [stdout] (http--127.0.0.1-8080-5)
The complete message is:
17:58:30,623 INFO [stdout] (http--127.0.0.1-8080-5) 2012-12-09 17:58:30.623 [INFO] com.edfx.adb.web.controller.AuthController#login - A message
I am using JBoss AS7 and I have exclude log4j like:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
And my log4j.properties is:
log4j.rootLogger=INFO, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c#%M - %m%n
I want to print the message as:
2012-12-09 17:58:30.623 [INFO] com.edfx.adb.web.controller.AuthController#login - A message
How can I do it?

It's because JBoss STDIO wraps stdout and stderr and the log4j ConsoleAppender outputs to stdout.
You can accomplish the same thing your trying to do by configuring the logging subsystem instead of using a log4j.properties file. Using the logging subsystem there is also no reason to exclude the dependency in the jboss-deployment-structure.xml.
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c#%M - %m%n"/>
</formatter>
</console-handler>
<!-- other handlers and loggers -->
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
</handlers>
</root-logger>
</subsystem>

Related

Log4j2.xml configuration doesn't work but log4j2.properties does

Hello I have this problem were if i use a log4j2.xml file as a configuration file the logger won't log to console, whereas if i am using a .properties file instead i will have the logs in file.
This is the .xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- Extra logging related to initialization of Log4j.
Set to debug or trace if log4j initialization is failing. -->
<Configuration status="warn">
<Appenders>
<!-- Console appender configuration -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</Console>
</Appenders>
<Loggers>
<!-- Root logger referring to console appender -->
<Root level="info" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
.properties file:
# Set to debug or trace if log4j initialization is failing
status = warn
# Name of the configuration
name = ConsoleLogConfigDemo
# Console appender configuration
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Root logger level
rootLogger.level = debug
# Root logger referring to console appender
rootLogger.appenderRef.stdout.ref = consoleLogger
(I am trying to do this for a migration from log4j to log4j2 and if i am using the .properties file everything seems to work)
I had the properties file and xml file both in resources folder.

Apache Flink - Can not create Hourly/Daily Log File with Log4j

I can not create daily and also hourly log file (especially for taskexecutor log) with log4j
Here is the my log4j.properties
# This affects logging for both user code and Flink
log4j.rootLogger=INFO, file
# Uncomment this if you want to _only_ change Flink's logging
#log4j.logger.org.apache.flink=INFO
# The following lines keep the log level of common libraries/connectors on
# log level INFO. The root logger does not override this. You have to manually
# change the log levels here.
log4j.logger.akka=INFO
log4j.logger.org.apache.kafka=INFO
log4j.logger.org.apache.hadoop=INFO
log4j.logger.org.apache.zookeeper=INFO
# Log all infos in the given file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${log.file}
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.file.append=false
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
${log.file} points to :
2020-02-13 17:40:51,105 INFO org.apache.flink.runtime.taskexecutor.TaskManagerRunner - -Dlog.file=/.../flink-1.9.1/log/flink-tarantula-taskexecutor-0-...log
In the meantime there is a logback.xml configuration also(which one flink uses ? )
logback.xml file :
<configuration>
<appender name="file" class="ch.qos.logback.core.FileAppender">
<file>${log.file}</file>
<append>false</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<!-- This affects logging for both user code and Flink -->
<root level="INFO">
<appender-ref ref="file"/>
</root>
<!-- Uncomment this if you want to only change Flink's logging -->
<!--<logger name="org.apache.flink" level="INFO">-->
<!--<appender-ref ref="file"/>-->
<!--</logger>-->
<!-- The following lines keep the log level of common libraries/connectors on
log level INFO. The root logger does not override this. You have to manually
change the log levels here. -->
<logger name="akka" level="INFO">
<appender-ref ref="file"/>
</logger>
<logger name="org.apache.kafka" level="INFO">
<appender-ref ref="file"/>
</logger>
<logger name="org.apache.hadoop" level="INFO">
<appender-ref ref="file"/>
</logger>
<logger name="org.apache.zookeeper" level="INFO">
<appender-ref ref="file"/>
</logger>
<!-- Suppress the irrelevant (wrong) warnings from the Netty channel handler -->
<logger name="org.apache.flink.shaded.akka.org.jboss.netty.channel.DefaultChannelPipeline" level="ERROR">
<appender-ref ref="file"/>
</logger>
</configuration>
here is the flink/lib folder
apache-log4j-extras-1.2.17.jar flink-dist_2.11-1.9.1.jar flink-table_2.11-1.9.1.jar flink-table-blink_2.11-1.9.1.jar log4j-1.2.17.jar slf4j-log4j12-1.7.15.jar
Solution Finally
After all tried, I found the solution, I could not create daily log file because of this statement was blocking creating daily file(s).
log4j.logger.org.apache.flink.shaded.akka.org.jboss.netty.channel.DefaultChannelPipeline=ERROR, filelog4j.rootLogger=INFO, file
Example of creating logs at midday and midnight of each day.
log4j.category.org.apache.flink.shaded.akka.org.jboss.netty.channel.DefaultChannelPipeline=ERROR, nettyFileAppender
log4j.rootLogger=INFO, file
# Uncomment this if you want to _only_ change Flink's logging
#log4j.logger.org.apache.flink=INFO
# The following lines keep the log level of common libraries/connectors on
# log level INFO. The root logger does not override this. You have to manually
# change the log levels here.
log4j.logger.akka=INFO
log4j.logger.org.apache.kafka=INFO
log4j.logger.org.apache.hadoop=INFO
log4j.logger.org.apache.zookeeper=INFO
# Log all infos in the given file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.file=${log.file}
log4j.appender.file.append=false
log4j.appender.file.DatePattern='.'yyyy-MM-dd-a
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
# Suppress the irrelevant (wrong) warnings from the Netty channel handler
log4j.appender.nettyFileAppender=org.apache.log4j.FileAppender
log4j.appender.nettyFileAppender.file=/path/to/nettyLog/nettyChannelIrrelevant.log
log4j.appender.nettyFileAppender.append=false
log4j.appender.nettyFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.nettyFileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
You don't specify how you provide your log4j.properties file. But a common issue is that someone has this file in their jar, and it gets ignored, because Flink will use the conf/log4j.properties file located on the cluster.
And assuming your jar doesn't include anything other than classes from the slf4j-api jar, then Flink will pick up the slf4j-log4j12.jar in flink/lib (since that's on the classpath), and thus use log4j (not logback), so the logback.xml configuration file is ignored.

Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: WFLYCTL0085: Failed to parse configuration

I added this config to my subsystem im JBoss and i got an error by build.
The config part:
<subsystem xmlns="urn:jboss:domain:logging:3.0">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<!-- MY CONFIGURATION PART -->
<file-handler name="ABC-FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%-5p %d %C (%F:%M:%L) - %m%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="ABC-Activity.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</file-handler>
<logger category="com.my.project.ActivityLogger">
<level name="INFO"/>
<handlers>
<handler name="ABC-FILE"/>
</handlers>
</logger>
here the error by build the web-app:
ERROR [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0055: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: WFLYCTL0085: Failed to parse configuration
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:131)
at org.jboss.as.server.ServerService.boot(ServerService.java:357)
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[113,17]
Message: WFLYCTL0198: Unexpected element '{urn:jboss:domain:logging:3.0}suffix' encountered
at org.jboss.as.controller.parsing.ParseUtils.unexpectedElement(ParseUtils.java:89)
at org.jboss.as.logging.LoggingSubsystemParser_3_0.parseFileHandlerElement(LoggingSubsystemParser_3_0.java:521)
at org.jboss.as.logging.LoggingSubsystemParser_3_0.readElement(LoggingSubsystemParser_3_0.java:152)
at org.jboss.as.logging.LoggingSubsystemParser_3_0.readElement(LoggingSubsystemParser_3_0.java:97)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69)
at org.jboss.as.server.parsing.StandaloneXml_4.parseServerProfile(StandaloneXml_4.java:546)
at org.jboss.as.server.parsing.StandaloneXml_4.readServerElement(StandaloneXml_4.java:242)
at org.jboss.as.server.parsing.StandaloneXml_4.readElement(StandaloneXml_4.java:141)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:103)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:49)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:123)
... 3 more
11:52:57,717 FATAL [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0056: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.
i used this docu https://docs.jboss.org/author/display/AS71/Logging+Configuration#LoggingConfiguration-rootlogger
what i wrong???
In our experience, this was caused due to a wrong standalone.xml configuration.
Jboss is very complicated. They keep specific history files for standalone.xml configurations. I don't know the reasons, thats a question for their developers.
For some reason sometimes standalone.xml has 0 bytes.
Look for the file in
JBOSS_AS_HOME/standalone/configuration/
In our case it was like this
drwxr-xr-x. 11 user user 4096 Mar 14 12:44 standalone_xml_history
-rw-rw-r--. 1 user user 0 Mar 14 12:44 standalone.xml
We replaced with latest "automatic backup/history" from standalone_xml_history directory; and everything went back to normal.

WildFly 9.0.1 WFLYCTL0158 Handler "CONSOLE" is not found

Suddenly (after working fine for some time), WildFly 9.0.1 (and also 9.0.2) seem to have somehow lost the CONSOLE handler for logging.
When trying to debug an application from NetBeans 8.0.2, the Console window shows:
ERROR [stderr] (default task-14) Handler java.util.logging.ConsoleHandler is not defined
as last entry, and the web application seems to be stuck (before actually starting).
In WildFly's management console, there seems to be a root logger using 2 handlers: CONSOLE and FILE.
Both Handlers seem to be existing in standalone-full.xml:
...
<subsystem xmlns="urn:jboss:domain:logging:3.0">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
...
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
...
</subsystem>
...
When changing config in the management console, I can delete the handlers out of the root logger. Then I can save, but taking them in again seems impossible, since I get the WFLYCTL0158, telling that the handler would not be defined.
JBoss Knowledge base says you should ensure right jars (logback-classic-1.1.9.jar and logback-core-1.1.9.jar in that case) are in WEB-INF/lib directory if you are using an application framework.
UPDATE
For those who do not have access to link above, and wonder what the next steps are, you can add following to pom.xml to make it work with your application framework, which will then add it to WEB-INF/lib during the build.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>

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. 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;
<?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.
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.
I had a log4j.properties file at the root level of the .war (WEB-INF/classes) from years ago that caused the same issue - deletion fixed it
Since you are using a logging framework, there are 2 ways to fix it:
Remove the logging framework and all the configuration files (why would I do that)
Move your log4j.properties file from src/main/resources to WEB-INF folder.
Quoting: JBoss Docs, Section 'Per Deployment Logging'
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. In a WAR or JAR deployment the configuration file can be in either the META-INF or WEB-INF/classes directories.
The following configuration files are allowed:
logging.properties
jboss-logging.properties
log4j.properties
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:
<root-logger>
<level name="TRACE"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>

Categories

Resources