Skip to content

Commit a90c196

Browse files
erichelgesongraemerocher
authored andcommitted
Change recommendation to use Slf4j's formatting anchors with common ex… (#493)
* Change recommendation to use Slf4j's formatting anchors with common examples and link to FAQ. * Fix log statment to work in 3.2
1 parent e6b780b commit a90c196

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/en/guide/scaffolding.gdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class BookController {
8585

8686
def show() {
8787
def book = Book.get(params.id)
88-
log.error(book)
88+
log.error("{}", book)
8989
[bookInstance : book]
9090
}
9191
}

src/en/guide/upgrading/upgrading31x.gdoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ Double notAString = 9.2
1616
log.info notAString
1717
{code}
1818

19-
The latter call to the `info` method will throw an exception and `toString()` must be called to resolve the issue.
19+
The latter call to the `info` method will throw an exception as it is not a String.
2020

21+
Instead you should use Slf4j's formatting anchors to log. The advantage is the `toString()` method is not called unless the message will be logged.
22+
23+
{code}
24+
log.info "{}", 9.2D
25+
log.debug "Key: {}, Value: {}", key, value
26+
log.error "{}", exception.message, exception
27+
{code}
28+
29+
See the [Slf4j FAQ|http://www.slf4j.org/faq.html#string_or_object] for more information.
2130

2231
h4. Spring 4.3
2332

0 commit comments

Comments
 (0)