Feb 162010
 

Thanks to the awesome groovy-ness of groovy this is crazy easy!

Controller action:

    def appLog = {
        def file = new File("pathToApplicationLog.log")
 
        // Success.
        [log: file.text]
    }

appLog.gsp:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Application Log</title>
    </head>
    <body onload="textAreaScrollBottom('log');">
        <h1>Application Log</h1>
        <div class="body">
 
            <textarea rows="30" cols="90" id="log" name="log" readonly="yes">
                ${log.encodeAsHTML()}
            </textarea>
 
        </div> <!--End body-->
    </body>
</html>

CSS:

#log {
    width: 920px;
    height: auto;
}

JavaScript:

function textAreaScrollBottom(id) {
    $(id).scrollTop = $(id).scrollHeight;
}

Gavin Kromhout:


Thank you for visiting.
Do look around.
Do leave a comment.

  One Response to “Render a log or text file with Grails”

  1. Render a log or text file with Grails…

    Thanks to the awesome groovy-ness of groovy this is crazy easy!

    Controller action:

    def appLog = {
    def file = new File(“pathToApplicationLog.log”)

    // Success.
    [log: file.text]
    }…

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)