Mr Special
Mr Special

Reputation: 1676

System.out.print() is not worked, log4j still works well

may anyone explain for my question as below.

  1. My java web application uses the org.apache.log4j.Logger library.
  2. I put a command like: log.info("this is log4j output")
  3. I put another command like System.out.println("This is system out put")
  4. Ok, I deploy the web application by tomcat server.

Now, Im tracing log in catalina.out. My question:

During running of the application "this is log4j output" is shown, but "This is system out put" is not shown.

This is log4j configuration:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "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 think that both of them will be shown (log4j output and system.out).

I dont know why. May anyone explain the question?

Thanks!

Upvotes: 0

Views: 545

Answers (1)

GhostCat
GhostCat

Reputation: 140467

System.out prints to the "standard out" console. That can be your text console, but it could be anything, as it can easily be configured to go elsewhere.

On the other hand, any logger library can be configured to log to any place you want to.

Long story short: most likely, this is due to some specific configuration setting in your environment. But we don't know your setup, so we can't give any more specific answer.

Upvotes: 3

Related Questions