Skip to content

Commit

Permalink
Change recommendation to use Slf4j's formatting anchors with common e…
Browse files Browse the repository at this point in the history
…x… (#493)

* Change recommendation to use Slf4j's formatting anchors with common examples and link to FAQ.

* Fix log statment to work in 3.2
  • Loading branch information
erichelgeson authored and graemerocher committed Sep 15, 2016
1 parent e6b780b commit a90c196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/en/guide/scaffolding.gdoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BookController {

def show() {
def book = Book.get(params.id)
log.error(book)
log.error("{}", book)
[bookInstance : book]
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/en/guide/upgrading/upgrading31x.gdoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ Double notAString = 9.2
log.info notAString
{code}

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

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.

{code}
log.info "{}", 9.2D
log.debug "Key: {}, Value: {}", key, value
log.error "{}", exception.message, exception
{code}

See the [Slf4j FAQ|http://www.slf4j.org/faq.html#string_or_object] for more information.

h4. Spring 4.3

Expand Down

0 comments on commit a90c196

Please sign in to comment.