Skip to content

Logging from scripts

The log is the only witness to most workflow runs. Nobody watches a scheduled run at three in the morning, and nobody remembers next month why a run skipped a VM. What the scripts wrote down is all there is. Good logging costs a few lines per script, and saves hours the first time something goes wrong.

Orchestrator gives JavaScript two families of log calls: System.*, which writes to the run’s log, and Server.*, which writes a persistent entry to the database. In this recipe you build a small writeLog action that writes every line in the same format and at the right level, use it from a workflow, find the lines afterwards, and then see how the other runtimes log.

Getting ready

  • The action module com.vcfguide.chapter4 and the workflow folder VCF Orchestrator Guide/Chapter 4.
  • The vCenter vc01.vmw.lab with a few VMs, some of them powered off. The workflow only reads.
  • For step 11, a root shell on the appliance: SSH in as vmware-system-user, then sudo su - (recipe 2.1).

How to do it

One action for every log line

  1. In Library > Actions, create the action writeLog in com.vcfguide.chapter4.
  2. Add three inputs of type string: level, source, and message. Set the Return type to void, enter this script, and click Save:
com.vcfguide.chapter4/writeLog
// Writes one line as "[source] message" at the given level:
// debug, info, warn, or error. Warnings and errors also go to the
// persistent server log, so they outlive the run's own log.
var text = "[" + (source || "unknown") + "] " + message;
switch (String(level || "info").toLowerCase()) {
case "debug":
System.debug(text);
break;
case "warn":
System.warn(text);
Server.warn(text, message);
break;
case "error":
System.error(text);
Server.error(text, message);
break;
default:
System.log(text);
}

Use it from a workflow

  1. Create the workflow Log at every level in the folder VCF Orchestrator Guide/Chapter 4. It needs no inputs.
  2. Add one scriptable task, Check power states, with this script:
Log at every level / Check power states
var chapter4 = System.getModule("com.vcfguide.chapter4");
// The workflow's name and this run's ID tie every line to the run
var source = workflow.currentWorkflow.name + " " + workflow.id;
chapter4.writeLog("debug", source, "Reading all VMs from the vCenter plug-in");
var vms = VcPlugin.getAllVirtualMachines();
chapter4.writeLog("info", source, "Found " + vms.length + " VMs");
var notRunning = 0;
for (var i = 0; i < vms.length; i++) {
var state = vms[i].runtime.powerState.value;
chapter4.writeLog("debug", source, vms[i].name + " is " + state);
if (state !== "poweredOn") {
notRunning++;
}
}
if (notRunning > 0) {
chapter4.writeLog("warn", source, notRunning + " of " + vms.length + " VMs are not powered on");
}
try {
throw new Error("Simulated failure, to show the error level");
} catch (e) {
chapter4.writeLog("error", source, "Caught: " + e.message);
}
  1. Save the workflow and run it. The run completes: the error is caught, so it’s only logged.

Read the run’s log

  1. Open the run and its Logs tab. Each line shows its time, its level, and the text with the [Log at every level …] prefix. Use the Severity filter (ALL, DEBUG, INFO, WARNING, ERROR) to show only warnings and errors: that’s the view you want on a run with hundreds of lines.
The run of Log at every level. Its log shows an INFO line Found 94 VMs, two WARNING lines and two ERROR lines, all prefixed with [Log at every level and the run ID]; the second of each pair, in purple, carries the long text in brackets.
Figure 4.16. A run's log with lines at three levels. The purple lines are the Server.* entries.
  1. Look for the debug lines, one per VM. Whether they appear depends on the scripting log level, which is INFO by default. Raise it to DEBUG (step 10), run the workflow again, and they appear.

On 9.1.1, workflow.currentWorkflow.name and workflow.id give the workflow name and the run ID, as the prefix in figure 4.16 shows. In our run, with the scripting log level at its default, INFO, the System.debug lines didn’t appear in the run’s log at all.

Find the persistent entries

  1. The warning and the error were also written with Server.warn and Server.error. Those entries are stored in Orchestrator’s database with the run. Look for them on the run’s Logs tab.
Close-up of the Logs tab: the Severity filter and the SERVER and SYSTEM buttons above the log, and the Server entries in purple, each with the short text followed by the long text in brackets.
Figure 4.17. Persistent entries written with Server.warn and Server.error, shown in the run's own log.

On 9.1.1, Server.warn and Server.error entries appear in the run’s own Logs tab, next to the System.* lines, in purple. Each shows the short text, then the long text in brackets. The SERVER and SYSTEM buttons above the log switch each kind on and off.

Log from the other runtimes

  1. Python, Node.js, and PowerShell actions don’t have System.log. They write to their own output, and Orchestrator copies it to the run’s log:
Runtime Information Warning or error
Python print("…") print("…", file=sys.stderr)
Node.js console.log("…") console.warn("…"), console.error("…")
PowerShell, PowerCLI Write-Host "…" Write-Warning "…", Write-Error "…"

Keep the [source] message format there too, so that one search finds the lines of a run whatever runtime wrote them. A Python action can pass context["executionId"] as its source, for example.

Needs a lab check. For each runtime on 9.1.1, record how lines written to standard error, console.warn, console.error, Write-Warning, and Write-Error appear on the run’s log: at warning or error level, or as ordinary lines. Check also whether Write-Error fails the PowerShell action.

Change the log levels

  1. As an administrator, open System Settings and click Open on the Log Configuration card. The page has Server log level, Scripting log level, Scripting log max file count and Scripting log max size (MB) (in the lab, 5 files of 20 MB). Set the Scripting log level to DEBUG while you investigate, and back to INFO when you’re done. The lab in figure 4.18 had both levels at ALL, the most detailed, which is fine for a lab and too noisy for production. The same setting is available from the appliance shell with vracli vro logs configure (recipe 1.8).
System Settings, Log Configuration page: Configure logging and log rotation parameters. Edit server log settings and built-in logging agent using the vracli command line tool. Server log level ALL, Scripting log level ALL, Scripting log max file count 5, Scripting log max size (MB) 20, Save and Cancel.
Figure 4.18. The server and scripting log levels, and the rotation of the scripting log.

Follow the scripting log on the appliance

  1. Every run’s script lines also go to log files on the appliance, which is handy for following several runs at once. Where they are depends on the kind of Orchestrator.

On an embedded Orchestrator, SSH in to the VCF Automation appliance as vmware-system-user. You don’t need root to read these files:

vmware-system-user@auto — embedded
ls -l /var/log/services-logs/prelude/vco-app/file-logs/
tail -f /var/log/services-logs/prelude/vco-app/file-logs/vco-server-app_scripting.log | grep "Log at every level"
Checked on an embedded Orchestrator 9.1.1, inside VCF Automation, 1 Dec 2026. The scripting log is vco-server-app_scripting.log, and each System.log() line in it is tagged SCRIPTING_LOG with the action or workflow it came from. Recipe 2.7 lists the other files in the folder.

On a standalone appliance, in a root shell on vco01.vmw.lab (recipe 2.1):

root@vco01 — standalone
ls -l /services-logs/prelude/vco-app/file-logs/
tail -f /services-logs/prelude/vco-app/file-logs/vco-server-app_scripting.log | grep "Log at every level"
Needs a lab check. Not yet checked on a standalone 9.1.1 appliance: that the logs are under /services-logs/prelude/vco-app/file-logs/ there (the 8.x path), with the same file names as on embedded.

How it works

Two kinds of log. Broadcom’s documentation divides script logging into two types:

  • System.log, System.debug, System.warn, and System.error write a non-persistent log line. The server sends it to every client that’s watching the run, and it’s shown on the run’s Logs tab and written to the scripting log file. It isn’t a database record. The documentation warns that this information can be lost when the server restarts, and older runs lose their lines when log files rotate.
  • Server.log, Server.debug, Server.warn, and Server.error write a persistent entry to Orchestrator’s database. They take two texts, a short one and a long one, and the entry stays as long as the run it belongs to.

That’s why writeLog sends warnings and errors to both. The System.* line keeps the run’s log complete and in order, and the Server.* entry is still there after the log files have moved on. Don’t send every line to Server.*: each one is a database write, and a busy workflow can write thousands.

Levels. Each line has a level, from DEBUG up through INFO, WARN, and ERROR. Two settings decide what’s kept: the server log level, for the server’s own messages, and the scripting log level, for script lines. Both are INFO by default. Lines below the level aren’t written, so System.debug costs almost nothing in production and gives you detail the moment you lower the level. Broadcom warns against leaving DEBUG or ALL on in production, because the volume slows the server down.

Retention. Run logs are kept on disk and rotated. A KB article for 8.x describes old runs showing an empty log because one very busy workflow filled the rotation buffer, which pushed everyone else’s lines out early. The cure is the same as for any log: log less from the noisy workflow, or keep more on disk.

One format. A prefix such as [Log at every level <run ID>] turns a log into something you can search. When the lines leave Orchestrator, through syslog (recipe 2.5) or the appliance’s log files, the run’s ID is the only thing that links a line back to the run and the workflow.

Back in vRO 5.5–7Read script logs in the Java client's Logs tab, set the log level in Control Center, and find scripts-logs.log in the server's log folder.
In Orchestrator 9.xRead them on the run's Logs tab in the browser client, set the levels under System Settings > Log Configuration or with vracli vro logs configure, and find the files under /services-logs/prelude/vco-app/file-logs on the appliance.

There's more

What to log. One line when a script starts, with the inputs that matter. One line for each decision, saying what was chosen and why: “skipping vm-db01: powered off”. One line with the result. Put details for each item of a loop at debug, so they’re there when you need them and silent when you don’t.

What never to log. Passwords, tokens, and other secrets. A SecureString input is a plain string inside a script, and System.log("Connecting as " + user + " / " + password) writes it to the log, to the scripting log file, and to every syslog server that log is forwarded to. Log the user name, never the password. The same goes for a whole REST response or request, which may carry an authorization header.

Log objects readably. System.log(vm) prints the object’s type and ID, not its contents. For a plain JavaScript object, use JSON.stringify(obj). For a Properties object, which JSON.stringify can’t see into, log its keys and values in a loop over props.keys.

Errors that are thrown. You don’t need to log an error you then throw. Orchestrator logs the failure and its message with the run, and the exception path (recipe 3.4) gets the message too. Log what you know at that point that the message doesn’t say, such as the item the script was working on.

Log levels for one workflow. The levels are server-wide, so lowering them for one workflow lowers them for all. An alternative is an input or a configuration element value such as verbose (recipe 4.7) that makes writeLog write its debug lines at info while you investigate.

See also