-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
78 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
core/jvm/src/test/scala/zio/logging/ConsoleLoggerConfigSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package zio.logging | ||
|
||
import zio.test._ | ||
import zio.{ Config, ConfigProvider, LogLevel } | ||
|
||
object ConsoleLoggerConfigSpec extends ZIOSpecDefault { | ||
|
||
val spec: Spec[Environment, Any] = suite("ConsoleLoggerConfig")( | ||
test("load valid config") { | ||
|
||
val logPattern = | ||
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}" | ||
|
||
val configProvider: ConfigProvider = ConfigProvider.fromMap( | ||
Map( | ||
"logger/pattern" -> logPattern, | ||
"logger/filter/rootLevel" -> LogLevel.Info.label, | ||
"logger/filter/mappings/zio.logging.example.LivePingService" -> LogLevel.Debug.label | ||
), | ||
"/" | ||
) | ||
|
||
configProvider.load(ConsoleLoggerConfig.config.nested("logger")).map { _ => | ||
assertTrue(true) | ||
} | ||
}, | ||
test("fail on invalid config") { | ||
|
||
val logPattern = | ||
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}" | ||
|
||
val configProvider: ConfigProvider = ConfigProvider.fromMap( | ||
Map( | ||
"logger/pattern" -> logPattern, | ||
"logger/filter/rootLevel" -> "INVALID_LOG_LEVEL" | ||
), | ||
"/" | ||
) | ||
|
||
configProvider | ||
.load(ConsoleLoggerConfig.config.nested("logger")) | ||
.exit | ||
.map { e => | ||
assert(e)(Assertion.failsWithA[Config.Error]) | ||
} | ||
} | ||
) | ||
} |
57 changes: 57 additions & 0 deletions
57
core/jvm/src/test/scala/zio/logging/FileLoggerConfigSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package zio.logging | ||
|
||
import zio.test._ | ||
import zio.{ Config, ConfigProvider, LogLevel } | ||
|
||
import java.net.URI | ||
import java.nio.charset.StandardCharsets | ||
import java.nio.file.Paths | ||
|
||
object FileLoggerConfigSpec extends ZIOSpecDefault { | ||
|
||
val spec: Spec[Environment, Any] = suite("FileLoggerConfig")( | ||
test("load valid config") { | ||
|
||
val logPattern = | ||
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}" | ||
|
||
val configProvider: ConfigProvider = ConfigProvider.fromMap( | ||
Map( | ||
"logger/pattern" -> logPattern, | ||
"logger/path" -> "file:///tmp/test.log", | ||
"logger/filter/rootLevel" -> LogLevel.Info.label, | ||
"logger/filter/mappings/zio.logging.example.LivePingService" -> LogLevel.Debug.label | ||
), | ||
"/" | ||
) | ||
|
||
configProvider.load(FileLoggerConfig.config.nested("logger")).map { loadedConfig => | ||
assertTrue(loadedConfig.charset == StandardCharsets.UTF_8) && | ||
assertTrue(loadedConfig.destination == Paths.get(URI.create("file:///tmp/test.log"))) && | ||
assertTrue(loadedConfig.autoFlushBatchSize == 1) && | ||
assertTrue(loadedConfig.bufferedIOSize.isEmpty) | ||
} | ||
}, | ||
test("fail on invalid config") { | ||
|
||
val logPattern = | ||
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}" | ||
|
||
val configProvider: ConfigProvider = ConfigProvider.fromMap( | ||
Map( | ||
"logger/pattern" -> logPattern, | ||
"logger/charset" -> "INVALID_CHARSET", | ||
"logger/filter/rootLevel" -> "INVALID_LOG_LEVEL" | ||
), | ||
"/" | ||
) | ||
|
||
configProvider | ||
.load(FileLoggerConfig.config.nested("logger")) | ||
.exit | ||
.map { e => | ||
assert(e)(Assertion.failsWithA[Config.Error]) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters