Log Output Adapter Sample

About This Sample

This sample demonstrates the TIBCO StreamBase® Log File Output Adapter, an output adapter that passes its input tuple unchanged to the currently configured StreamBase logging system and then to it its output port. The Log adapter participates automatically in the logging system currently in use by its containing StreamBase Server.

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)

LoggerCustomFormat 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 or Log4j 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 FileLoad StreamBase Sample.

  • Type log to narrow the list of options.

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

  • Click OK.

StreamBase Studio creates a single project containing the sample files.

Running log.sbapp in StreamBase Studio

  1. In the Project Explorer, open the sample you just loaded.

  2. Open the src/main/eventflow folder.

  3. Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).

  4. Open the named application file and click the Run button. This opens the SB Test/Debug perspective and starts the application.

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

    If red marks do not resolve themselves in a moment, select the project and right-click MavenUpdate Project from the context menu.

  5. In the Manual Input view, 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 Application Output 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 Application Output view shows three emitted tuples, and the Console view shows three log messages.

  8. When done, press F9 or click the Stop Running Application 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.