How To Set Up A Splunk Logger


At the top of your TypeName.js file where you are implementing the method you would like to log from, put the following line at the top to instantiate your logger (following the following format for easy splunk searching later):

var log = C3.logger("c3.packageName.TypeName");

Then, in your .js method, you can add statements like this to log items:

if (log.isDebugEnabled()) {
   log.debug("note about some variable you want to log: " + someVariableInYourJavascriptMethod);

Note that the someVariableInYourJavascriptMethod must be a string. JSON.stringify() can be helpful to turn an object into a string if you wish to log an object.

Now, the above statement will be logged to splunk IF you have turned on the logging to the correct level.

To turn on detailed logging, run this in console:

var loggerName = 'c3.packageName.TypeName';
var loggerLevel = 'DEBUG'
var logLevelDuration = 600  // how long you wish the log to be turned on to the loggerLevel of detail.
Cluster.setLogLevel(loggerName, loggerLevel, logLevelDuration)

Then you can execute the method you implemented logging in and check splunk for details.