Reputation: 58774
I'm using Eclipse to run applications using maven tomcat plugin in local environment.
Each class uses org.apache.log4j.Logger
to log, as:
private static final Logger logger = LogManager.getLogger(MyClass.class);
Can I redirect all log output to Eclipse's Console log?
Upvotes: 1
Views: 1917
Reputation: 68942
Just add a console appender to your log4j.xml like:
<log4j:configuration>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
</root>
...
</log4j:configuration>
See also: https://www.mkyong.com/logging/log4j-xml-example/
A vaild logger looks like:
<logger name="com.package.Class">
<level value="info" />
</logger>
Upvotes: 1
Reputation: 63
You can configure log4j to print to console/file through the link provided by @stacker
https://www.mkyong.com/logging/log4j-xml-example/
but to add it in pom.xml add the file path inside <systemProperties>
tag
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
<systemProperties>
<log4j.configuration>file:src/main/resources/log4j.properties</log4j.configuration>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
Upvotes: 1