Ideally, I would like to log everything during development on a localhost and to log only errors on the live server. I am having trouble logging to files on my development platform (Windows 10, Java with Wicket).
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://logging.apache.org/log4j/2.x/articles.html
http://mycuteblog.com/log4j2-xml-configuration-example/ -->
<Configuration status="DEBUG">
<Properties>
<Property name="log-path">${sys:catalina.home}/logs</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/>
</Console>
<RollingFile name="trace-log" fileName="${log-path}/luminous-trace.log"
filePattern="${log-path}/luminous-trace-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="error-log" fileName="${log-path}/luminous-error.log"
filePattern="${log-path}/luminous-error-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.linguaclassica" level="debug" additivity="false">
<appender-ref ref="trace-log" level="debug"/>
<appender-ref ref="error-log" level="error"/>
<appender-ref ref="console-log" level="debug"/>
</Logger>
<Root level="info" additivity="false">
<AppenderRef ref="console-log"/>
</Root>
</Loggers>
</Configuration>
I have managed to get some logs written to my tomcat's logs
folder.
Only some of my messages are appearing. I do not know what symbols are significant and what are not.
The base page for publicly accessable pages logs the subclass.
public class PublicBasePage extends WebPage
{
protected static final Logger logger = LogManager.getLogger(PublicBasePage.class);
public PublicBasePage()
{
super();
logger.info(this.getClass().getName());
}
}
[INFO ] 2017-10-19 17:07:13.208 [http-nio-8080-exec-57] PublicBasePage - com.linguaclassica.access.HomePage The base page for the private web pages logs a message.
public class PrivateBasePage extends WebPage
{
private static final Logger logger = LogManager.getLogger(PrivateBasePage.class);
public PrivateBasePage()
{
super();
logger.debug("()");
}
}
[DEBUG] 2017-10-19 17:12:05.662 [http-nio-8080-exec-62] PrivateBasePage - ()
However, messages for the private page do not get logged to a file or to the console.
public class ClientLandingPage extends PrivateBasePage
{
private static final Logger logger = LogManager.getLogger(ClientLandingPage.class);
public ClientLandingPage()
{
super();
logger.info("(info)");
logger.debug("(debug)");
logger.warn("(warn)");
}
}
I do not understand what is failing.
OK, this was careless. ClientLandingPage is obsolete and was never called, being replaced by shared/CommonOverviewPage. I changed the declarations to
private Logger logger = LogManager.getLogger(SomethingPage.class);
and the logs seem to come out as I want them.
Yesterday's logs have the date appended to the file name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.