Striim 3.9.4 / 3.9.5 documentation

Configuring Log4j

Edit the conf/log4j.server.properties file and add the following new section:

log4j.logger.com.mycompany.custom.packagename.MyCustomFunctions=debug, MyCustomFunctionsAppender
log4j.additivity.com.mycompany.custom.packagename.MyCustomFunctions=false
log4j.appender.MyCustomFunctionsAppender=org.apache.log4j.FileAppender
log4j.appender.MyCustomFunctionsAppender.File=logs/MyCustomFunctions.log.out
# Define the layout for file appender
log4j.appender.MyCustomFunctionsAppender.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.MyCustomFunctionsAppender.layout.conversionPattern=%-6p:%-15M:%m%n

In this example, a separate logs/MyCustomFunctions.log.out file will be created. Its log level will be debug, and it will output the log level, method, and message.

In the following Java class, the logger is used to output the running sum and count values:

    @AggHandlerDesc(handler=AvgDebug_Float.class)
    public abstract Float AvgDebug( String sKey, Float fArg );
    public static class AvgDebug_Float
    {
        float fRunningSum = 0;
        int iRunningCount = 0;
        
        public Float getAggValue()
        {
            logger.debug( "RunningSum: " + fRunningSum + ",  RunningCount: " + iRunningCount + "\n");
            return (iRunningCount == 0) ? 0 : (fRunningSum / iRunningCount);
        }
        public void incAggValue(String sKey, Float fArg)
        {
            if(fArg != null) {
            	iRunningCount++;
                fRunningSum += fArg;
            }
            logger.debug( "[Key: " + sKey + ", Value: " +  fArg + "] RunningSum is now:
              " + fRunningSum + ",  RunningCount is now: " + iRunningCount );
        }
        public void decAggValue(String sKey, Float fArg)
        {
            if(fArg != null) {
            	iRunningCount--;
                fRunningSum -= fArg;
            }
            logger.debug( "[Key: " + sKey + ", Value: " +  fArg + "] RunningSum is now:
              " + fRunningSum + ",  RunningCount is now: " + iRunningCount );
        }
    }

One recommendation for your logging applications is to use StringBuffer to concatenate the strings used in your logging output. This will increase efficiency and ensure greater security in your applications.