Logging configuration

The Play logger is built on Log4j. Since most Java libraries use Log4j or a wrapper able to use Log4j as a backend, you can easily configure logging that is well-suited to your application.

Logging from your application

Play provides a default logger with the class play.Logger. This class uses Log4j to write messages and exceptions to a logger named “play”.

Logging from your application is easy:

Logger.info("A log message");
Logger.error(ex, "Oops");

The play.Logger class’ methods support easy formatting through the standard Java formatter syntax:

Logger.debug("The param was %s", param);
Logger.info("I want to log %s and %s and %s", a, b, c);

You can still use Log4j directly to create alternative loggers for specific needs:

org.apache.log4j.Logger.getLogger("another.logger");

Configure log levels

You can configure the play logger’s log level. Just define this key in the application.conf file:

application.log=INFO

You can change this value without restarting the server. Note that this level only applies to messages generated by the application.

If you need to fully configure Log4j, create a log4j.properties file in the conf/ directory. Since this directory is the first element of the classpath, this file will be the default used by all libraries.

The default Log4j configuration is the following:

log4j.rootLogger=ERROR, Console
 
log4j.logger.play=INFO
 
# Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n

Copy this file and update it for your specifics needs!

Continuing the discussion

Next, we continue configuration with Configuration in several environments.

转载于:https://www.cnblogs.com/zhiji6/p/4446856.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值