Skip to content

Commit 02c9c2d

Browse files
authored
Add logging (#13)
* Started adding logging * Fixed warnings * Added RegexBuilderLoggingTest * Added RegexBuilderDslLoggingTest * Updated README.md
1 parent e300c2d commit 02c9c2d

File tree

6 files changed

+1028
-67
lines changed

6 files changed

+1028
-67
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,49 @@ It offers a lot of benefits over using raw regex syntax in strings:
1414

1515
It is fully documented in the [project wiki](https://github.com/markwhitaker/RegexToolbox.kt/wiki).
1616

17-
## New in version 2.0
17+
## New in 2.2
18+
19+
### Logging
20+
21+
Use the new `addLogger()` method to connect a logger of your choice and see how your regex is built, step by step. For example:
22+
23+
```kotlin
24+
val regex = RegexBuilder()
25+
.addLogger {
26+
println(it)
27+
}
28+
.wordBoundary()
29+
.text("Regex")
30+
.anyOf("Builder", "Toolbox")
31+
.wordBoundary()
32+
.buildRegex()
33+
```
34+
35+
or this:
36+
37+
```kotlin
38+
val regex = regex {
39+
addLogger {
40+
println(it)
41+
}
42+
wordBoundary()
43+
text("Regex")
44+
anyOf("Builder", "Toolbox")
45+
wordBoundary()
46+
}
47+
```
48+
49+
will output this to your console:
50+
51+
```text
52+
RegexBuilder: wordBoundary(): \b
53+
RegexBuilder: text("Regex"): Regex
54+
RegexBuilder: anyOf("Builder", "Toolbox"): (?:Builder|Toolbox)
55+
RegexBuilder: wordBoundary(): \b
56+
RegexBuilder: buildRegex(): \bRegex(?:Builder|Toolbox)\b
57+
```
58+
59+
## New in 2.0
1860

1961
### New builder syntax
2062

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
buildscript {
22
ext.junit_version = '4.12'
3+
ext.mockk_version = '1.9.3.kotlin12'
34
}
45

56
plugins {
@@ -24,6 +25,7 @@ sourceCompatibility = 1.8
2425
dependencies {
2526
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
2627
testImplementation "junit:junit:$junit_version"
28+
testImplementation "io.mockk:mockk:$mockk_version"
2729
}
2830

2931
compileKotlin {

0 commit comments

Comments
 (0)