Important note! Logging must always be performed responsively with special precaution regarding personal data. Logging will end up in files on the server and GDPR must always be respected. A very good rule is to never include any personal data in any message you log!
The LogUtil utility in the Sitevision API provides logging capabilities for apps and functions. LogUtil supports different log levels (debug, info, warn and error) and output is written to the server.log and also to the app.log.
const logUtil = require('LogUtil'); logUtil.debug('Details for devs'); logUtil.info('All is nice'); logUtil.warn('Hm, this might cause trouble'); logUtil.error('Oops, something is really bad here');
Accessing LogUtil in Velocity
#set ($logUtil = $sitevisionUtils.LogUtil) $logUtil.debug('Details for devs'); $logUtil.info('All is nice'); $logUtil.warn('Hm, this might cause trouble'); $logUtil.error('Oops, something is really bad here');
console.log [@since 8]
All console logging is dispatched to LogUtil.
console.log('Details for devs'); // Equivalent with console.debug console.debug('Details for devs'); console.info('All is nice'); console.warn('Hm, this might cause trouble'); console.error('Oops, something is really bad here');
Note! The server-side console log does not support string substitution or complex objects/arguments that the client variant typically does in all modern browsers.
console.log("Hello, %s. You've called me %d times.", "Bob", 7);
To log complex objects you would typically use JSON.stringify:
Live log monitoring
Live log monitoring is a valuable tool during development, testing and when tracking down problems in production. Developers (i.e. authenticated users with the "developer" permission) can monitor the server.log and the app.log via the admin UI.
Monitor the server.log
The server log contains all system logging, including LogUtil logging.
Current logging to the server.log can be viewed via
/admin/log by authenticated users with the "developer" permission.
Monitor the app.log
The app log contains all LogUtil logging.
Current logging to the app.log can be viewed via
/admin/applog by authenticated users with the "developer" permission.