Calling the Logger from a custom Java function

Calling the Logger from a custom Java function

book

Article ID: KB0076358

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

If I'm writing a custom Java Embedded Adapter, I call com.streambase.sb.operator.Operator.getLogger().
How do I get a reference to the current logger from a custom Java Function which does not have access to the Operator class?

Issue/Introduction

Calling the Logger from a custom Java function

Resolution

Here is an example based on the code generated by the Java Function Wizard
package com.sb.support;
import org.slf4j.*;
public class LogIt {
    public static boolean logWarn(String arg0) {
        final Logger logger = LoggerFactory.getLogger(LogIt.class);
        logger.warn(arg0);
        return true;
    }
}

This function, for example, can then be used in a Map operator expression as:
calljava("com.sb.support.LogIt","logWarn","Hello Test")

The Function Wizard in Studio creates the necessary configuration file settings to access the function from within the EventFlow application.