Contents
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 thegetLogger()
method of the Spotfire Streaming client API's Operator class. Code for the custom operator is in thesrc/main/java
folder. -
LogAdapter.sbapp
passes its flow of tuples through a Spotfire Streaming 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.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
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
.
StreamBase Studio creates a project for the sample.
-
In the Project Explorer view, open the
sample_logging
sample. (Do not confuse this sample with thesample_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
> from the context menu. -
Navigate into
src/main/eventflow/com.tibco.sb.logging
. -
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. -
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.sbapp
module. Notice that the format of log messages is different. -
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. -
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.
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.