Forum Discussion
I suppose it depends on what kind of logging you're hoping to accomplish.
For example, one option is to use the FreeMarker logging utilities if you're wanting some server-side logging to occur.
Alternatively, if you are wanting to have some client-side logging for troubleshooting/debugging purposes in the browser console (i.e. Developer Tools > Console), then you can leverage jQuery to do this.
In our environment, I created a macro called custom.macro.logging.ftl to simplify client-side logging in our customizations, which looks like this:
<#------------------------------------------------
Functions and Macros for Logging and Debugging
Created By: Jeff Shurtliff
Last Modified By: Jeff Shurtliff
Last Modified Date: 2020-11-03
------------------------------------------------->
<#-------------------- Macro: consoleLog -------------------->
<#-- This macro prints an entry to the browser JavaScript console (i.e. console.log) -->
<#macro consoleLog logEntry="">
<@liaAddScript>
; (function ($) {
console.log("${logEntry}");
})(LITHIUM.jQuery);
</@liaAddScript>
</#macro>
<#-------------------- Macro: consoleError -------------------->
<#-- This macro prints an error to the browser JavaScript console (i.e. console.error) -->
<#macro consoleError logEntry="">
<@liaAddScript>
; (function ($) {
console.error("${logEntry}");
})(LITHIUM.jQuery);
</@liaAddScript>
</#macro>
<#-------------------- Macro: consoleDebug -------------------->
<#-- This macro prints a debug message to the browser JavaScript console (i.e. console.debug) -->
<#macro consoleDebug logEntry="">
<@liaAddScript>
; (function ($) {
console.debug("${logEntry}");
})(LITHIUM.jQuery);
</@liaAddScript>
</#macro>
<#-------------------- Macro: consoleInfo -------------------->
<#-- This macro prints an info message to the browser JavaScript console (i.e. console.info) -->
<#macro consoleInfo logEntry="">
<@liaAddScript>
; (function ($) {
console.info("${logEntry}");
})(LITHIUM.jQuery);
</@liaAddScript>
</#macro>
<#-------------------- Macro: consoleWarn -------------------->
<#-- This macro prints a warning message to the browser JavaScript console (i.e. console.warn) -->
<#macro consoleWarn logEntry="">
<@liaAddScript>
; (function ($) {
console.warn("${logEntry}");
})(LITHIUM.jQuery);
</@liaAddScript>
</#macro>
Then in my other custom components/macros/functions I am able to easily generate log entries by importing the macro file and calling one of the macros above, as demonstrated below.
<#-- Import the macro file -->
<#import 'custom.macro.logging' as logging />
<#-- Attempt to get the user ID -->
<#attempt>
<#assign userId = user.id />
<@logging.consoleDebug "The User ID is ${userId}" />
<#recover>
<@logging.consoleError "Encountered an exception while retrieving the User ID" />
</#attempt>
Then while testing in the browser you can monitor the Console tab in Developer Tools and have a better understanding of what might be failing and why.
(I like to include the text "Encountered an exception while..." in error messages within the <#recover> directive because it reminds me that I should check out the Toolbox to see what the verbose FreeMarker error was so I can troubleshoot even further.)
I hope this helps!
Thank you for the quick response Jeff. I am looking at server side logging. When we use the utils where are the logs stored and how can I get a copy of it?
- jeffshurtliff5 years agoBoss
I’m actually not entirely sure, to be honest, but my assumption would be that the FreeMarker logs only appear in Toolbox, in the components (or the Studio preview) when they fail or have warnings in the Stage environment, and also in the backend server logs that only Khoros employees can access.
So if you’re looking for more real-time logging then you may need to get a little creative with a custom endpoint and something like a RabbitMQ log broker, but then you’d of course have to be careful not to accidentally chew up your quota of third-party/external API calls.
If anyone else has figured out a good way to do logging then I’m hoping they’ll chime in, but this is unfortunately the most I’ve been able to come up with thus far. - Claudius5 years agoBoss
konerus Maybe you can share a bit more about what user behaviour you are trying to create a log of. Because Khoros already has a lot of Analytics capturing built-in which you might consider "logging" in a certain way.
- konerus5 years agoAdept
Hi Cladius,
I want to log information about the output of a certain third party api output information whether the output has been as expected or not for a given user.
Thank you,
Sujana
- jeffshurtliff5 years agoBoss
What kind of retention do you need for your logging? Are you looking for continuous logging or just, for example, tracking the result of the most recent third party API call for the user?
I ask because I'm doing the latter quite a bit in my environment in one or more of the following ways:
- Storing data in the user's cache (assuming the API call is being performed by the user in question)
- Storing the data in a custom metadata field (usually as a JSON string if there's a good amount of data but other times just a string or Boolean value) for a user, node or message.
- Writing the data to a message within a hidden TKB board and then parsing the data with a component and/or function as needed.
Related Content
- 2 months ago
- 5 years ago
- 3 years ago
- 13 years ago