---
title: "Grails - Logging from a Controller or Service"
author: "MafiaDada"
date: "2011-08-11T14:55:16Z"
tags: []
categories: ["编程语言"]
slug: "grails-logging-from-a-controller-or-service"
draft: false
lastmod: "2011-08-11T14:55:16Z"
id: 1146501
url: "https://mafiadada.iteye.com/blog/1146501"
---

Logging informational messages from a controller or service is the sort of thing I wish I'd figured out how to do when I first started playing around with Grails. All the information is in the docs, but it took me a while to find it and it could be a bit obscure for someone just getting started.

Here's all you have to do:

1. Open **Config.groovy** and find the log4j block.
2. At the bottom, add a line like this:

```java
info 'grails.app'
```


3. In your controller action, wherever you want to log something, just add a line something like this:

```java
log.info "In myController, my Action myVar is: ${myVar}"
```


Reference Link：
<http://dowdrake.com/showthread.php?86-Grails-Logging-from-a-Controller-or-Service>