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.

时间: 2025-01-17 15:47:10

Logging configuration的相关文章

Java Logging: Configuration

Table of Contents Configuration Class Configuration File The Java Logging API can be configured in two ways: Via a configuration class. Via a configuration file. The initialization of the configuration is taken care of by the java.util.logging.LogMan

Python(2.7.6) 标准日志模块 - Logging Configuration

除了使用 logging 模块中的 basicConfig 方法配置日志, Python 的 logging.config 模块中, dictConfig 和 fileConfig 方法分别支持通过字典和文件的方式配置 Logger.Handler 和 Formatter.下面用一个例子来简单地说明如何使用文件配置日志,更多详细的用法参考:https://docs.python.org/2/library/logging.config.html logging.conf ############

Enterprise Library 6.0 Semantic Logging Application Block Configuration

使用Enterprise Library 6.0的Logging application 模块,配置步骤如下: 1.Nuget 安装 Enterprise Library Logging模块 命令行:Install-package EnterpriseLibrary.Logging. 2.配置文件: 当前基本都是通过Enterprise Library 配置的,但是很不幸,我的总是安装失败,于是自己baidu了一把,然后进行配置,配置如下: <configSections> <secti

Java Logging: Overview

Table of Contents Log Level Logger Hierarchy LogManager In this text I will try to give you an overview of the java.util.logging API. Hopefully it will be easier to understand the individual components once you understand the big picture. Many of the

【java】java自带的java.util.logging.Logger日志功能

偶然翻阅到一篇文章,注意到Java自带的Logger日志功能,特地来细细的看一看,记录一下. 1.Java自带的日志功能,默认的配置 ①Logger的默认配置,位置在JRE安装目录下lib中的logging.properties中 ②logging.properties日志文件内容如下: ############################################################ # Default Logging Configuration File # # You

Python自动化运维之常用模块—logging

在现实生活中,记录日志非常重要.银行转账时会有转账记录:如果有出现什么问题,人们可以通过日志数据来搞清楚到底发生了什么.    对于系统开发.调试以及运行,记录日志都是同样的重要.如果没有日志记录,程序崩溃时你几乎就没办法弄明白到底发生了什么事情.1.简单使用 import logging logging.debug('debug message') logging.info('info message') logging.warn('warn message') logging.error('

Logging日志信息(转)

Mybatis内置的日志工厂提供日志功能,具体的日志实现有以下几种方式: SLF4J Apache Commons Logging Log4j 2 Log4j JDK logging 具体选择哪个日志实现由MyBatis的内置日志工厂确定.它会使用最先找到的(按上文列举的顺序查找). 如果一个都未找到,日志功能就会被禁用. 不少应用服务器的classpath中已经包含Commons Logging,如Tomcat和WebShpere, 所以MyBatis会把它作为具体的日志实现.记住这点非常重要

Java Se: Logging 框架说明

Java Logging 用惯了log4j等日志工具,竟然不知Java还自带了个log工具.今天有空了就来了解一下. 先来看一个简单的例子: public class SystemTest { private final Logger logger = Logger.getLogger("alias"); @Test public void showSystemProperty() { Properties props = System.getProperties(); Enumera

java.util.logging.Logger基础教程

从JDK1.4开始即引入与日志相关的类java.util.logging.Logger,但由于Log4J的存在,一直未能广泛使用.综合网上各类说法,大致认为: (1)Logger:适用于小型系统,当日志量过大时性能有待提升.好处在于JDK集成了此类,无需引入新包.且性能也在逐步改善当中,我认为一般而言,使用Logger即可. (2)Log4J:并发性较好,性能较强,适用于大型系统. 本文介绍java.util.logging.Logger的详细用法.    1.基本概念 Logger中有2个比较