Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: How do I print in the cmd console?

I wanna print a few values in the console, how do I do this?

Every time I get into a function, I want it to print a line with whatever text, I just wanna know if I'm getting into the function, and for some if-else statements. Mostly for debugging.

like image 673
randomizertech Avatar asked Oct 08 '10 20:10

randomizertech


2 Answers

If you mean "print to the console output panel", then you simply need to use println:

println "Hello, world"

Results in printed output:

groovy> println "Hello, world" 

Hello, world

If that's not what you mean, can you clarify your question to be more specific?

like image 158
Rob Hruska Avatar answered Sep 17 '22 18:09

Rob Hruska


you might want to consider grails built in logging functionality which provides the same functionality as println plus more

http://grails.github.io/grails-doc/3.0.x/guide/single.html#logging

in your app just say

log.info "Hello World"

to print something everytime you enter an action in a controller you can do something like this

class UserController {

    def beforeInterceptor = {
       log.info "Entering Action ${actionUri}"
    }

    def index = {
    }

    def listContributors = {
    }
}

this will print out to the log whenever the controller methods are entered because of the controller interceptor

like image 28
Aaron Saunders Avatar answered Sep 19 '22 18:09

Aaron Saunders