Grails: How do I print in the cmd console?

53,428

Solution 1

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

Solution 2

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?

Solution 3

The regular java System.out.println("Your stuff"); works too.

Share:
53,428
randomizertech
Author by

randomizertech

All over the continent (from Greenland to Chile, and vice-versa)

Updated on June 05, 2020

Comments

  • randomizertech
    randomizertech about 4 years

    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.

  • L_7337
    L_7337 over 10 years
    This will work in Controllers and Services, but it does not get automatically injected in to your own custom classes. You can either manually inject it, or just use println
  • John Little
    John Little about 10 years
    I tried log.info("hello") in my controller, but nothing comes out on the console (of eclise with GTS), and there are no log directories or similar. Anyone know how to do this?
  • Dem Pilafian
    Dem Pilafian about 9 years
    @JohnLittle, log.info("hello") probably didn't display because of the logging level for your application, but log.println("hello") and log.error("hello") probably will display.
  • TBAR
    TBAR about 7 years
    For domain classes you will have to implement the toString method otherwise it won't know how to print it.