Event Logger Expressions example

In this example, we use svc_expr to create an alternative Logger, which logs certain SPARKL events, and writes them to a file on the local file system.

Figure: Event Logger Expressions


Tip: Get the code from the SPARKL public repository.
Table 1. Event Logger Expressions - Markup
Example Description
<folder name="Event_logger">
  <field name="event" 
    type="term"/>
  <service name="Logger" 
    provision="expr"/>
  <consume name="Logprime"
    service="Logger" 
    fields="event">
    <prop name="sse.log" 
      sources="dispatcher" 
      keys="prime"/>
    <prop name="expr.bind.in" 
      Event="event"/>
    <prop name="expr.src" 
      content-type="text/x-erlang"><![CDATA[
file:write_file(
       "my_log.txt",
        io_lib:format("~p~n~n", [Event]),
        [append]).
    ]]></prop>
  </consume>
  <folder name="Primes_expr">
  ...
  </folder>
</folder>
The Event_logger folder contains:
  • event, a field of type term
  • Logger, an svc_expr service
  • Logprime, a Log Consume operation
The Logprime operation has a single input field and the sse.log property. This property specifies:
  • That Logprime can log SPARKL dispatcher, that is, data events
  • The key prime

Logprime can only log data events, which are generated by components that:

  • Are lower than Logprime in the Navigation Tree panel
  • Have a matching key specified either on them, or the mix or folder that contains them

The expr.bind.in property binds the event field to the Event static variable. The expressions in Logprime:

  1. Create the my_log.txt file in the node's directory, if it is not already there
  2. Write the consumed events to this file, appending any content that already exists

The Primes_expr folder is a child of the Event_Logger folder. Events generated within Primes_expr can be offered for logging by Logprime.

<folder name="Primes_expr">
  ...
  <mix name="Mix">
    <folder name="Frontend">
      ...
      <consume name="Log" 
        service="Backend" 
        fields="YES n">
        <prop name="sse.log" 
          keys="prime"/>
      </consume>
    </folder>
    ...
  </mix>
</folder>
The Log operation in the Primes mix has the sse.log property.

Events generated by this operation can be logged by any consume that:

  • Is higher up the Navigation Tree panel
  • Has a single input field
  • Also has the sse.log property, which specifies that the consume:
    • Listens for dispatcher events
    • Has a matching key

The Logprime operation satisfies all these conditions. Therefore, all data events generated by the Log operation are logged by Logprime, and are written to the my_log.txt file.

Note: We could just as well use the Tabserver version of the Primes example. The sse.log property is not extension specific.