Explicit Logging

The syntax of an explicit logging expression is:


where <expr> is any valid KRL expression. The expression is returned, and something like the following is added to the console log (and the "Logging" tab of the UI if enabled):

[KLOG] <message> <expr converted to a string>

The syntax of an explicit logging statement in the postlude is:

log <level> <expr> 

where <level> is one of info, warn, error, or debug; and <expr> is any valid KRL expression that results in a string (or something that can be cast as a string such as a number). Explicit logging statements also place the log message in the console log, and the "Logging" tab of the UI if enabled.

The following example would place a string with the value of a variable named query in the log if the rule fired:

fired { log debug "query:"+query } 

The following would only log with an empty query:

fired { log debug "Empty query" if(query like "^$") }

The following rule is selected when an http:post() event is seen with a status code indicating an error. The error is logged and then processing is stopped. 

rule r3 is active {
  select when http post label re#ex# status_code re#([45]\d\d)# setting (status)
  fired {
    log error <<Error: #{status}: #{event:attr("status_line")}>>

Another approach to logging would use explicit error handling.

Copyright Picolabs | Licensed under Creative Commons.