Log Output Adapter Sample

About This Sample

This sample demonstrates the Spotfire Streaming Log Output Adapter, an adapter that passes its input tuple unchanged to the currently configured StreamBase logging system, and then to its output port. The adapter provides for extensive customization of log output messages.

The sample's Input Stream has a schema of {symbol: string, price: double, numshares: double}. The Input Stream is followed by a Map operator whose sole purpose is to provide default values for the Input Stream. This allows you to click the Send Data button in the Manual Input view in StreamBase Studio without entering any values. The incoming tuple is then split into three instances of the Log adapter, each of which illustrates a different formatting option of the same log message written to the Console view.

LoggerBasic shows the output of a default-configured Log adapter, where only the Logger Name property is specified. With the default input tuple, this adapter emits a log message like the following. (The following examples are shown on two lines for clarity, but are emitted as one long line each.)

2011-08-23 20:19:56.798-0400 [ThreadPool-9] WARN  
   LoggerBasic - IBM,164.35,1000.0

LoggerTupleNames illustrates two message formatting options, the inclusion of input tuple field names, and a message prefix.

2011-08-23 20:19:56.799-0400 [ThreadPool-9] WARN  
   LoggerTupleNames - Incoming tuple: (tupleid=0,symbol="IBM",price=164.35,numshares=1000.0)

Logger3 illustrates the Custom MessageFormat control, which provides a format string in the format defined by java.text.MessageFormat, with zero-based positional parameters filled in with field values. The provided format string is:

{2, number, integer} shares of {0} traded at {1, number, currency}.

which results in a log message like the following:

2011-08-23 20:19:56.800-0400 [ThreadPool-9] WARN  
   LoggerCustomFormat - 1,000 shares of IBM traded at $164.35.

Notice that the overall format of these log messages is the default Logback message format as described in the Logback Default Configuration section of Using StreamBase Logging in the Administrator's Guide. The message formatting options described above only apply to the message text portion (%m) of the log message — the portion shown on the second line of each example above.

To change the format of the overall log message, you must configure a PatternLayout format in the Logback configuration file, as described on the Using StreamBase Logging page. To see this in action, go through the next section's extra steps when running the sample in Studio.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter log to narrow the list of options.

  • Select Logging output adapter from the StreamBase Standard Adapters category.

  • Click Import Now.

StreamBase Studio creates a single project containing the sample files.

Running This Sample in StreamBase Studio

  1. In the Project Explorer view, open the sample_adapter_embedded_log sample. (Do not confuse this sample with the sample_logging sample.)

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/packageName folder.

  3. Open the log.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  4. In the Manual Input view, make sure the fragment containing log.sbapp is selected in the Fragment drop-down.

  5. Click Send Data without entering any field values. This sends the default input tuple defined in the DefaultValues operator.

  6. As it always does, the Output Streams view shows the tuples emitted on the output port. But pay attention to the Console View, which also shows one log message for each tuple emitted.

  7. Now, enter values in the Manual Input view and click Send Data. The Output Streams view shows three emitted tuples, and the Console view shows three log messages.

  8. When done, press F9 or click the Terminate EventFlow Fragment button.

Sample Location

When you load the sample into StreamBase® Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase® Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_log

See Default Installation Directories for the default location of studio-workspace on your system.