1
1
package java .util .logging
2
2
3
+ import java .lang .StringBuilder
4
+
3
5
abstract class Formatter protected () {
4
6
5
7
def format (record : LogRecord ): String
@@ -17,7 +19,7 @@ abstract class Formatter protected () {
17
19
// Instead we'll do simple text replacement, very imperative
18
20
var msgAccumulator = new StringBuilder ()
19
21
var inParam = false
20
- var paramInFlight : StringBuilder = null
22
+ var paramInFlight : StringBuilder = null
21
23
var substitutionFailure = false // track failure to break the loop
22
24
var i = 0
23
25
@@ -31,13 +33,13 @@ abstract class Formatter protected () {
31
33
paramInFlight = new StringBuilder ()
32
34
} else if (inParam && currentChar != '}' ) {
33
35
// accumulate the param
34
- paramInFlight += currentChar
36
+ paramInFlight.append( currentChar)
35
37
} else if (currentChar == '}' ) {
36
38
// end of param, replace placeholder by value if possible
37
39
inParam = false
38
40
val (failed, replacement) = {
39
41
try {
40
- val index = paramInFlight.toInt
42
+ val index = paramInFlight.toString(). toInt
41
43
if (index >= 0 && index < params.length) {
42
44
(false , params(index).toString)
43
45
} else if (index > 0 ) {
@@ -55,15 +57,17 @@ abstract class Formatter protected () {
55
57
56
58
// The JVM will fail if e.g. there are bogus params and would not replace
57
59
// any parameter
58
- if (failed) substitutionFailure = failed
59
- else msgAccumulator ++= replacement
60
+ if (failed)
61
+ substitutionFailure = failed
62
+ else
63
+ msgAccumulator.append(replacement)
60
64
} else {
61
- msgAccumulator += currentChar
65
+ msgAccumulator.append( currentChar)
62
66
}
63
67
}
64
68
65
69
if (substitutionFailure || inParam) msg
66
- else msgAccumulator.result ()
70
+ else msgAccumulator.toString ()
67
71
} else {
68
72
msg
69
73
}
0 commit comments