Link Search Menu Expand Document

print

The action print prints messages to the stdout.

Specification

Arguments

 TypeRequired?Vars supported? 
msgstringyesyes
prefixstringnoyes
showTimestampbooleannoyes
timestampFormatstringnoyes
formatstringnoyes
descriptionstringnono
whilebooleannoyes
whenbooleannoyes
countnumericnoyes

msg ( string | required ): It contains the text to be printed out.

Example 1: Basic use of argument

print { 
  msg:"Hello Mr Doe"
}
>> Hello Mr Doe

Example 2: Argument msg support variables

vars {
  lastname = "Doe"
}

print { 
  msg:"Hello Mr ${lastname}"
}
print { 
  msg:"Hello Mr ${toUppercase(lastname)}"
}
>> Hello Mr Doe
>> Hello Mr DOE

prefix ( string | optional ): Text which is placed before the message. In case of being provided a whitespace is printed between prefix and msg.

Example 1: Basic use of argument prefix

print {
  prefix = "[DEBUG]"
  msg = "There are 20 cars."
}
>> [DEBUG] There are 20 cars.

Example 2: Argument prefix supports variables

vars {
  logLevel = DEBUG
}

print {
  prefix = substring(logLevel,0,2)
  msg = "There are ${totalCars} cars."
}
>> DEB There are 20 cars.

showTimestamp ( boolean | optional ): If this argument is true, a timestamps is placed before the msg (and the prefix if it’s provided). Default timestamp format is YYYY-MM-DD HH:mm:ss but it can be changed with argument timestampFormat.

Example 1: Basic use of argument

print {
  msg = "The pub is closed."
  showTimestamp = true
}
>> 2013-02-23 12::05:12 There pub is closed 

timestampFormat ( string | optional ): It allows you to determine the format of the timestamp. Argument showTimestamp can be omitted when timestampFormat is provided.

SymbolDesc
yyyyYear (2020-XXXX)
yyYear (00-99)
MMMonth of the year (1-12)
ddDay of the month (1-31)
HHHour (0-23)
hhHour (1-12)
mmMinutes (0-59)
ssSeconds (0-59)

Example 1: Basic use of argument timestampFormat

print {
  msg = "Hello my friend"
  timestampFormat = "HH:mm:ss"
}
>> 20:10:02 Hello my friend

format ( string | optional ) It specifies the format in which the message is printed out. Supported values for this argument are: plain or json. If argument is not provided default value is plain.

Example 1: Basic use of argument format

print {
  msg = "Hello Mr Doe"  
  format = "json"
}
>> {"msg": "Hello Mr Doe"}

Example 2: Usage of argument when timestamp & prefix are provided too.

print {
  msg           = "Hello Mr Doe"
  showTimestamp = true  
  prefix        = "[DEBUG]"  
  format        = "json"
}
>> {"msg": "[DEBUG] Hello Mr Doe", "timestamp"="23/12/2020 12:22:23"}

description ( string | optional ) It is used to apply descriptive text to the action.

Example 1: Basic use of argument

print {
  desc = "this action is used to print out the user details"
  msg = "Hello Mr Doe"  
}

when ( bool | optional ) It is used to control if the action must be executed.

var {
  open = false
}

print {
  msg = "The airport is closed"
  when = !open
}

count ( number || optional ) It determines the number of times the action is executed. Additionally, the variable _.index is increased in each iteration. The value of _.index starts with 0 and it ends with count-1.

*Example 1: Basic use of the argument *

print {
  msg = "Hello my friend"
  count = 3
}
>> Hello my friend
>> Hello my friend
>> Hello my friend

Example 2: Use of variable _.index

print {
  msg = "${_.index} Hello my friend"
  count = 3
}
>> 0 Hello my friend
>> 1 Hello my friend
>> 2 Hello my friend

while ( boolean | optional ) The action is executed repeatedly as long as the value of this argument is met. Additionally, the variable _.index is increased in each iteration. The value of _.index starts with 0 and increase in 1 in each iteration.

Example 1: Basic use of argument while

print {
  msg = "Hello my friend"
  while = _.index<=2
}
>> Hello my friend
>> Hello my friend
>> Hello my friend

Example 2: Use of variable _.index

print {
  msg = "${_.index} Hello my friend"
  count = 3
  while = _.index<=4
}

print {
  msg = "${_.index} Bye my friend"
  count = 3
  while = _.index<=1
}
>> 0 Hello my friend
>> 1 Hello my friend
>> 2 Hello my friend
>> 3 Hello my friend
>> 0 Bye my friend
>> 1 Bye my friend