Logging Samples

About This Sample

StreamBase uses the SLF4J logging system with the Logback framework. This sample illustrates two ways to use Logback logging in your EventFlow modules.

This sample provides three EventFlow modules:

  • LoggingInJavaOp.sbapp uses a custom Java operator that makes calls to the getLogger() method of the StreamBase client API's Operator class. Code for the custom operator is in the src/main/java folder.

  • LogAdapter.sbapp passes its flow of tuples through a StreamBase Log Adapter.

  • For comparison, NoLogging.sbapp is a simple passthrough module that does not make logging calls.

All three modules have an Input Stream with the same name, TradesIn, which allows all three to use the same feed simulation file provided with the sample. This simulation generates random data for the three fields of the Input Stream.

Finally, the sample includes a logback.xml configuration file in src/main/resources that configures the log messages shown in the Console view.

Run these modules one at a time in Studio and then run the feed simulation for each module. Watch the Console view for differences in logging output and message format.

Note

While it is possible to run two or three of these sample modules at the same time, this is likely to be confusing. You would have to carefully select one module at a time in the Fragment drop-down control in the Feed Simulation view, in order to send the feed simulation stream to the desired running module. But you would also need to select which Console view is active using the Display Selected Console button in the Console view's toolbar.

Studio is likely to automatically switch to any Console view that just received a log message, counteracting your selection of Consoles to watch.

Importing This Sample into StreamBase Studio

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

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

  • Enter logg in the Search field to narrow the list of choices.

  • Select Logging in operators and the Log Adapter from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a project for the sample.

Running This Sample in StreamBase Studio

  1. In the Project Explorer view, open the sample_logging sample. (Do not confuse this sample with the sample_adapter_embedded_log 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. Navigate into src/main/eventflow/com.tibco.sb.logging.

  3. Open the LoggingInJavaOp.sbapp file and click the Run button in Studio's top-level toolbar. This opens the SB Test/Debug perspective, installs and starts a node to contain the module.

  4. The Manual Input view shows the message Waiting for fragment to initialize. Several startup log messages appear in the Console view.

  5. When the Waiting for message clears from the Manual Input view, log messages should stop appearing in the Console view. Open the Feed Simulation view.

  6. Select the feed simulation file listed there and click Run.

  7. Watch the Console view for log messages from the running module. Scroll right and left in the Console to inspect the format of messages from this module.

  8. When done, press F9 or click the Terminate EventFlow Fragment button to stop this module.

  9. Repeat steps 3 through 8 for the LogAdapter.sbapp module. Notice that the format of log messages is different.

  10. Repeat steps 3 through 8 for the NoLogging.sbapp module. Notice that this time, tuples pass through the module without leaving an entry in the Console view.

  11. When done, terminate the last module you ran.

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_logging

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