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.sbappuses 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
LogAdapter.sbapppasses its flow of tuples through a StreamBase Log Adapter.
NoLogging.sbappis 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.
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.
In StreamBase Studio, import this sample with the following steps:
From the top-level menu, select→ .
loggin the Search field to narrow the list of choices.
Select Logging in operators and adapters from the Extending StreamBase category.
StreamBase Studio creates a project for the sample.
In the Project Explorer view, open the
sample_loggingsample. (Do not confuse this sample with the
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→ from the context menu.
LoggingInJavaOp.sbappfile 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.
The Manual Input view shows the message Waiting for fragment to initialize. Several startup log messages appear in the Console view.
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.
Select the feed simulation file listed there and click.
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.
When done, press F9 or click the Terminate EventFlow Fragment button to stop this module.
Repeat steps 3 through 8 for the
LogAdapter.sbappmodule. Notice that the format of log messages is different.
Repeat steps 3 through 8 for the
NoLogging.sbappmodule. Notice that this time, tuples pass through the module without leaving an entry in the Console view.
When done, terminate the last module you ran.
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.
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:
See Default Installation Directories for the default location of
studio-workspace on your system.