Skip to content

Commit

Permalink
Add log rotation test
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Aug 16, 2016
1 parent 4b61ba5 commit e8cf548
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions wvlet-log/src/main/scala/wvlet/log/LoggerJMXConfig.scala
Expand Up @@ -20,6 +20,8 @@ import javax.management._
/**
* Logger configuration API for JMX
*
* TODO: Move this to wvlet-log-jmx project, and use wvlet-jmx
*
*/
@MXBean abstract trait LoggerJMXConfig {
def getDefaultLogLevel: String
Expand Down
18 changes: 17 additions & 1 deletion wvlet-log/src/test/scala/wvlet/log/LogRotationHandlerTest.scala
Expand Up @@ -13,6 +13,8 @@
*/
package wvlet.log

import java.io.File

/**
*
*/
Expand All @@ -22,7 +24,7 @@ class LogRotationHandlerTest extends Spec {

"rotate log files" in {
val l = Logger("wvlet.log.rotation")
val h = new LogRotationHandler("target/log-rotation-test", 5, 10)
val h = new LogRotationHandler("target/log-rotation-test.log", 5, 10)

l.resetHandler(h)

Expand All @@ -31,6 +33,20 @@ class LogRotationHandlerTest extends Spec {
l.info("this is the end of log files")
h.flush()
h.close()

new File("target/log-rotation-test.log").exists() shouldBe true
}

"rescue orphaned log files" in {
val l = Logger("wvlet.log.rotation")
val tmp = new File("target/log-rotation-test.log.tmp")
if(!tmp.exists()) {
tmp.createNewFile()
}
tmp.exists() shouldBe true
val h = new LogRotationHandler("target/log-rotation-test.log", 5, 10)

tmp.exists() shouldBe false
}

}
Expand Down

0 comments on commit e8cf548

Please sign in to comment.