如何隐藏播放框架生成的日志
How to hide logs generated by play framework
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<!--Appenders-->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/home/sankalp/logs/application.log</file>
<append>true</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>false</immediateFlush>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>application1-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 5MB, keep 7 days worth of history, but at most 30MB -->
<maxFileSize>5MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>30MB</totalSizeCap>
</rollingPolicy>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<!--
The logger name is typically the Java/Scala package name.
This configures the log level to log at for a package and its children packages.
-->
<!--Loggers-->
<logger name="com.exampleenter code here" level="INFO" />
<!-- <logger name="application" level="DEBUG" />-->
<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<!--Root logger-->
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
application.log 文件
2020-07-09 12:47:59,353 - [INFO] - from play in play-internal-execution-context-1
datasource [jdbc:mysql://localhost:3307/ortholive_test_1may] bound to JNDI as DefaultDS
2020-07-09 12:47:59,361 - [WARN] - from com.jolbox.bonecp.BoneCPConfig in play-internal-execution-context-1
LogStatementsEnabled is set to true, but log4j level is not set at DEBUG. Disabling statement logging.
2020-07-09 12:48:00,347 - [INFO] - from play in play-internal-execution-context-1
database [default] connected at jdbc:mysql://localhost:3307/ortholive_test_1may
2020-07-09 12:48:06,872 - [INFO] - from application in play-internal-execution-context-1
Application redeployed : build V1
2020-07-09 12:48:07,032 - [INFO] - from play in play-internal-execution-context-1
Starting application default Akka system.
2020-07-09 12:48:07,043 - [INFO] - from play in play-internal-execution-context-1
Application started (Dev)
2020-07-09 12:48:07,114 - [INFO] - from akka.event.slf4j.Slf4jLogger in play-akka.actor.default-dispatcher-5
Slf4jLogger started
2020-07-09 12:48:10,439 - [WARN] - from com.jolbox.bonecp in play-akka.actor.default-dispatcher-5
Query execute time limit exceeded (1587700ms) - query: select userpracti0_.id as id1_47_, userpracti0_.created_on as created_2_47_, userpracti0_.modified_on as modified3_47_, userpracti0_.practice_id as practice4_47_, userpracti0_.user_id as user_id5_47_ from ol_user_practice userpracti0_ cross join ol_practices practices1_ cross join ol_user user2_ where userpracti0_.practice_id=practices1_.id and userpracti0_.user_id=user2_.id and practices1_.practice_id='demo' and user2_.role_id=2
2020-07-09 12:48:10,443 - [WARN] - from com.jolbox.bonecp in play-akka.actor.default-dispatcher-2
Query execute time limit exceeded (1608586ms) - query: select userpracti0_.id as id1_47_, userpracti0_.created_on as created_2_47_, userpracti0_.modified_on as modified3_47_, userpracti0_.practice_id as practice4_47_, userpracti0_.user_id as user_id5_47_ from ol_user_practice userpracti0_ cross join ol_user user1_ where userpracti0_.user_id=user1_.id and userpracti0_.practice_id=55 and user1_.role_id=3 order by userpracti0_.created_on desc
2020-07-09 12:49:07,082 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,082 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 12:49:07 IST 2020
2020-07-09 12:49:07,083 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 12:49:07 IST 2020
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:00:00,058 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ruuning scheduleForCST7AMThu Jul 09 13:00:00 IST 2020
2020-07-09 13:04:07,071 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,072 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 13:04:07 IST 2020
2020-07-09 13:04:07,073 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,086 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,087 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 13:04:07 IST 2020
2020-07-09 13:04:07,087 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 13:19:07 IST 2020
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
----------------------------------------------------------
2020-07-09 13:19:07,100 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,101 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 13:19:07 IST 2020
2020-07-09 13:19:07,103 - [INFO] - from application in application-akka.actor.default-dispatcher-2
您指定了 <root level="INFO">
,这会将所有记录器的默认日志记录级别设置为 INFO
,因此您会看到来自 akka
、play
的 INFO
日志事件, com.jolbox
等
您应该将 root 设置为不那么繁琐的日志级别。通常设置为 WARN
或 ERROR
.
<root level="WARN">
<appender-ref ref="FILE" />
</root>
确保您的应用程序的记录器已启用。
<logger name="package.to.your.classes" level="INFO" />
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<!--Appenders-->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/home/sankalp/logs/application.log</file>
<append>true</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>false</immediateFlush>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>application1-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 5MB, keep 7 days worth of history, but at most 30MB -->
<maxFileSize>5MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>30MB</totalSizeCap>
</rollingPolicy>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<!--
The logger name is typically the Java/Scala package name.
This configures the log level to log at for a package and its children packages.
-->
<!--Loggers-->
<logger name="com.exampleenter code here" level="INFO" />
<!-- <logger name="application" level="DEBUG" />-->
<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<!--Root logger-->
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
application.log 文件
2020-07-09 12:47:59,353 - [INFO] - from play in play-internal-execution-context-1
datasource [jdbc:mysql://localhost:3307/ortholive_test_1may] bound to JNDI as DefaultDS
2020-07-09 12:47:59,361 - [WARN] - from com.jolbox.bonecp.BoneCPConfig in play-internal-execution-context-1
LogStatementsEnabled is set to true, but log4j level is not set at DEBUG. Disabling statement logging.
2020-07-09 12:48:00,347 - [INFO] - from play in play-internal-execution-context-1
database [default] connected at jdbc:mysql://localhost:3307/ortholive_test_1may
2020-07-09 12:48:06,872 - [INFO] - from application in play-internal-execution-context-1
Application redeployed : build V1
2020-07-09 12:48:07,032 - [INFO] - from play in play-internal-execution-context-1
Starting application default Akka system.
2020-07-09 12:48:07,043 - [INFO] - from play in play-internal-execution-context-1
Application started (Dev)
2020-07-09 12:48:07,114 - [INFO] - from akka.event.slf4j.Slf4jLogger in play-akka.actor.default-dispatcher-5
Slf4jLogger started
2020-07-09 12:48:10,439 - [WARN] - from com.jolbox.bonecp in play-akka.actor.default-dispatcher-5
Query execute time limit exceeded (1587700ms) - query: select userpracti0_.id as id1_47_, userpracti0_.created_on as created_2_47_, userpracti0_.modified_on as modified3_47_, userpracti0_.practice_id as practice4_47_, userpracti0_.user_id as user_id5_47_ from ol_user_practice userpracti0_ cross join ol_practices practices1_ cross join ol_user user2_ where userpracti0_.practice_id=practices1_.id and userpracti0_.user_id=user2_.id and practices1_.practice_id='demo' and user2_.role_id=2
2020-07-09 12:48:10,443 - [WARN] - from com.jolbox.bonecp in play-akka.actor.default-dispatcher-2
Query execute time limit exceeded (1608586ms) - query: select userpracti0_.id as id1_47_, userpracti0_.created_on as created_2_47_, userpracti0_.modified_on as modified3_47_, userpracti0_.practice_id as practice4_47_, userpracti0_.user_id as user_id5_47_ from ol_user_practice userpracti0_ cross join ol_user user1_ where userpracti0_.user_id=user1_.id and userpracti0_.practice_id=55 and user1_.role_id=3 order by userpracti0_.created_on desc
2020-07-09 12:49:07,082 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,082 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 12:49:07 IST 2020
2020-07-09 12:49:07,083 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 12:49:07 IST 2020
2020-07-09 12:49:07,671 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:00:00,058 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ruuning scheduleForCST7AMThu Jul 09 13:00:00 IST 2020
2020-07-09 13:04:07,071 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,072 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 13:04:07 IST 2020
2020-07-09 13:04:07,073 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,086 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:04:07,087 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 13:04:07 IST 2020
2020-07-09 13:04:07,087 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
started : Thu Jul 09 13:19:07 IST 2020
2020-07-09 13:19:07,092 - [INFO] - from application in application-akka.actor.default-dispatcher-2
----------------------------------------------------------
2020-07-09 13:19:07,100 - [INFO] - from application in application-akka.actor.default-dispatcher-2
2020-07-09 13:19:07,101 - [INFO] - from application in application-akka.actor.default-dispatcher-2
Ended : Thu Jul 09 13:19:07 IST 2020
2020-07-09 13:19:07,103 - [INFO] - from application in application-akka.actor.default-dispatcher-2
您指定了 <root level="INFO">
,这会将所有记录器的默认日志记录级别设置为 INFO
,因此您会看到来自 akka
、play
的 INFO
日志事件, com.jolbox
等
您应该将 root 设置为不那么繁琐的日志级别。通常设置为 WARN
或 ERROR
.
<root level="WARN">
<appender-ref ref="FILE" />
</root>
确保您的应用程序的记录器已启用。
<logger name="package.to.your.classes" level="INFO" />