How to set Log Level in custom Java Operator

How to set Log Level in custom Java Operator

book

Article ID: KB0074744

calendar_today

Updated On:

Products

TIBCO Streaming

Description

What are the steps needed to add a Log Level property to my custom Java operator?
Picture of the LogLevel property in Studio when correctly implemented.

Issue/Introduction

Most included StreamBase operators and adapters have an operator property for setting the Log Level. This describes how to add this property to your own custom Java operator or adapter.

Resolution

A Log Level property is added just like any other custom operator property, and used in the init() method to have an effect.

Steps:
1. Add the property:
 private LogLevel logLevel = LogLevel.INFO;

2. Add the getter and setter:
 public LogLevel getLogLevel() {     return this.logLevel; } public void setLogLevel(LogLevel level) {     this.logLevel = level; }

3. Use the value in init():
     public void init() throws StreamBaseException {         super.init();         Operator.setLogLevel(logger, getLogLevel());     }
    
4. Wherever needed, call the logger:
     if (logger.isDebugEnabled()) {         logger.debug("operator processing a tuple at input port" + inputPort + ", value: " + tuple.toString());     }
                       
5. In the BeanInfo.java file, tell Studio that the Log Level property exists:                        
     public SBPropertyDescriptor[] getPropertyDescriptorsChecked() throws IntrospectionException {         return new SBPropertyDescriptor[] {                 new JavaEnumPropertyDescriptor<Operator.LogLevel>("logLevel", MyOperator.class, Operator.LogLevel.class).optional().                 displayName("Log Level").                 description("The log level used by the operator. Independent of the top-level StreamBase log level value.")         };     }