dnim
dnim

Reputation: 2530

How to redirect println output from console to specified log file in grails using log4j (Config.groovy)

In my application I use println "Some text here ${var}" statements to send some "debug" info to the console. But I want to send data to the specified file.

Could it be done via configuration of Config.groovy file?

Upvotes: 1

Views: 2363

Answers (2)

Ken Liu
Ken Liu

Reputation: 22914

You can't. Log messages have to go through log4j for them to be handled by Grails and log4j.

What you could do is replace all instances of println in your code with log.debug; that should be a simple search and replace with your text editor or IDE.

If that isn't possible you could try to replace the global System.out object with a File-backed PrintStream object in BootStrap.groovy.

Upvotes: 1

AA.
AA.

Reputation: 4606

You should to use logger directly. It's easy, clean, documented and flexible.

http://grails.org/doc/latest/guide/single.html#logging

Upvotes: 1

Related Questions