Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e3RvY30&locale=en_GB&version=2" data-macro-name="toc"></p><h3>Configuration</h3><p>Basic configuration of the standard JDK to show logging methods can be accomplished with the following procedure:</p><p>In file %JAVA_HOME%/jre/lib/logging.properties or equivalent</p><ul><li><p>set the log handler is configured to show all levels</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>java.util.logging.ConsoleHandler.level = ALL </pre></td></tr></table></li><li><p>set levels for the specific logging names that you wish to log</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>com.foo.level = FINE com.foo.MyClass.level = FINEST </pre></td></tr></table></li></ul><h3>@Log</h3><p>You can annotate your classes with the @Log transformation to automatically inject a logger in your Groovy classes, under the <code>log</code> property. Four kind of loggers are actually available:</p><ul><li><a href="http://groovy.codehaus.org/api/groovy/util/logging/Log.html"><code>@Log</code></a> for java.util.logging</li><li><code><a href="http://groovy.codehaus.org/api/groovy/util/logging/Commons.html">@Commons</a></code> for Commons-Logging</li><li><a href="http://groovy.codehaus.org/api/groovy/util/logging/Log4j.html"><code>@Log4j</code></a> for Log4J</li><li><code><a href="http://groovy.codehaus.org/api/groovy/util/logging/Slf4j.html">@Slf4j</a></code> for SLF4J</li></ul><p>Here's a sample usage of the @Log transformation:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import groovy.util.logging.* @Log class Car { Car() { log.info 'Car constructed' } } def c = new Car() </pre></td></tr></table><p>You can change the name of the logger by specifying a different name, for instance with <code>@Log('myLoggerName')</code>.</p><p>Another particularity of these logger AST transformations is that they take care of wrapping and safe-guarding logger calls with the usual <code>isSomeLevelEnabled()</code> calls. So when you write <code>log.info 'Car constructed'</code>, the generated code is actually equivalent to:</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>if (log.isLoggable(Level.INFO)) { log.info 'Car constructed' } </pre></td></tr></table><h3>Tracing Method Calls</h3><p>In order to enable tracing of how Groovy calls MetaMethods, use the following settings:</p><p>in file %JAVA_HOME%/jre/lib/logging.properties or equivalent</p><ul><li><p>make sure your log handler is configured to show level 'FINER' at least,<br />e.g.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>java.util.logging.ConsoleHandler.level = ALL </pre></td></tr></table></li><li><p>set MetaClass logging to 'FINER' at least,<br />e.g.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>groovy.lang.MetaClass.level = FINER </pre></td></tr></table></li><li><p>set the appropriate Level for the Classes and optionally method names<br /> that you want to trace. The name for the appropriate logger starts with<br /> 'methodCalls' and optionally ends with the method name,<br />e.g.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># trace all method calls methodCalls.level = FINER # trace method calls to the 'String' class methodCalls.java.lang.String.level = FINER # trace method calls to Object.println() methodCalls.java.lang.Object.println.level = FINER </pre></td></tr></table></li></ul><p>Example:<br /> with tracing enabled for all method calls a Groovy command line<br /> script appears as follows (German locale)</p><pre>$ groovy -e "println 'hi'" 13.09.2005 14:33:05 script_from_command_line run() FEINER: called from MetaClass.invokeMethod 13.09.2005 14:33:05 script_from_command_line println('hi') FEINER: called from MetaClass.invokeMethod hi </pre><h3>See Also</h3><ul><li><a href="http://groovy.codehaus.org/api/groovy/util/logging/package-summary.html">groovy.util.logging</a> package</li></ul>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced