3

Using Apache velocity in xwiki, how do I create a console.log() like one would in JavaScript? I know the log will probably be server side. I really just want to print the values of variables as it is rendered for debugging purposes.

I should add that the page I'm trying to debug is a form .post page, thus not rendered by its self, only returns data. Thus {{velocity output="false"}} mode, so simply printing the variable is not an option.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Gerrie van Wyk
  • 679
  • 8
  • 27
  • Maybe helpful: http://stackoverflow.com/a/7972815 To inject the logger, maybe a groovy macro will be useful - use the XWiki `xcontext` to put the logger into and fetch it in the velocity macro. – Clemens Klein-Robbenhaar Jan 19 '16 at 09:33

2 Answers2

3

Since XWiki 6.1 you can use logging script service to get a standard logger:

$services.logging.getLogger('My script').info('Hello {}', 'world')

See http://extensions.xwiki.org/xwiki/bin/view/Extension/Logging+Module#HGetaLoggerfromscript for more details.

Thomas Mortagne
  • 397
  • 1
  • 7
0

I had trouble to figure out what's the value for 'My Script'. Turns out the function getLogger() will take a logger_name as input parameter, where logger_name can be any of the logger name in ..WEB-INF/classes/logback.xml. For example, this works for me: $services.logging.getLogger('org.xwiki').info('Hello {}', 'world')

XC2000
  • 1