I would like to control the logging by configuring log level in logger.xml.
I used play.Logger with level ERROR set in logger.xml but logger with level INFO, DEBGU are also getting logged.
I have used ALogger log = play.Logger.of(Application.class); with INFO level in logger.xml but only error logs are getting logged.
I tried creating the custom logger class also by having custom methods for info and debug but it didn't work out.
I have not found any solution in any of the forum/community pages. Please guide me how to proceed further.
Below is the code & also the logger.xml
package test
import play.mvc.Controller;
import play.mvc.Result;
import views.html.index;
public class Application extends Controller {
public static Result index() {
return ok(index.render("Rendering "));
}
public static Result ourApp() {
ALogger log = play.Logger.of(Application.class);
log.info("**** Info enabled *****");
log.debug("**** debug enabled *****");
log.error("**** error enabled *****");
if(log.isDebugEnabled())
{
log.debug("**** Debug enabled *****");
}
if(log.isInfoEnabled())
{
log.info("**** Info enabled *****");
}
if(log.isErrorEnabled())
{
log.error("**** Error enabled *****");
}
return ok();
}
public static Result getXPage(String patId) {
String xValue = TestDao.getXNotes(patId);
return ok(test.render(Value));
}
}
logger.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/app.log</file>
<encoder>
<pattern>%date - [%level] - from %logger %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date - [%level] - %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="INFO" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
Output:-
2012-11-22 19:05:43,920 - [INFO] - from play
Application started (Dev)
2012-11-22 19:05:44,127 - [ERROR] - from test.Application
**** error enabled *****
Try using the logger name instead of the Class name
ALogger log = play.Logger.of("application");
This wokrs fine. Also comment out the lines that mention the log level in the file application.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With