VMWarevRO

vRealize Orchestrator: Standardized Logger Action

Below is the logger action that I am using (this is the only action I have that does not conform to my template).

/*

Purpose:

This action is used to provide consistent logging output for the calling actions/workflows.

This allows greater visibility into what code is executing and where, which makes troubleshooting easier.

Parameters:

– logType (string)

– logName (string)

– logLevel (string)

– logMessage (Any)

Return Type : void

*/

switch(logLevel) {

    case “log”:

        System.log(“[” + logType + “: ” + logName + “]: ” + logMessage);

        break;

    case “debug”:

        System.debug(“[” + logType + “: ” + logName + “]: ” + logMessage);

        break;

    case “error”:

        System.error(“[” + logType + “: ” + logName + “]: ” + logMessage);

        break;

    case “warn”:

        System.warn(“[” + logType + “: ” + logName + “]: ” + logMessage);

        break;

    default:

        System.log(“[” + logType + “: ” + logName + “]: ” + logMessage);

}

The action takes 4 parameters (inputs)

logType – Should be set to ‘Action‘ or ‘Workflow‘.

logName – Should be set to the ‘Action‘ or ‘Workflow‘name.

logLevel – The log level, one of ‘log‘, ‘warn‘, ‘error‘, ‘debug‘.

logMessage – The message to output to the console (can also be a non-string such as an object)

To use this action in any of my other actions, I place the following lines of code inside the variable block.

var logger = System.getModule(“com.kumar.library.util”).logger; // variable to store the default logging action.

var logType = “Action”; // The callee type;

var logName = “getDataCollectionEnabledStatus”; // This must be set to the name of the action / callee

And simply use the following line anywhere/everywhere that I want to perform some form of logging output.

logger(logType,logName,”log”,”message”);

You can see that I am passing 4 parameters to the ‘logger‘ function, which match the inputs for the logger action that is being called. In the above example, “log” has been set, but this can also be any of “debug“, “error” or “warn“. It will default to “log” if for some reason no valid value has been specified.

 

There is one overhead that you are probably thinking about and that is, yes, you need to manually set the variable ‘logName‘ to match the name of the action itself. This seems a bit dull at first, but in my experience, action names very rarely change.

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close