Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 744731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:00:45+00:00 2026-05-14T09:00:45+00:00

I setup some stop watch calls in my code to measure some code blocks

  • 0

I setup some stop watch calls in my code to measure some code blocks and all the messages are going into my primary log and not into the timing log. The perfStats.log file gets created just fine but all the messages go to the root log which I didn’t think was supposed to happen according to the docs I’ve read. Is there something obvious I’m missing here?

perf4j tutorial link

Example code

import org.apache.log4j.Logger;
import org.perf4j.LoggingStopWatch;
import org.perf4j.StopWatch;

public class PerfLogger {

    /**
     * @param args
     */
    public static void main(String[] args) 
    {
        Logger  logger = Logger.getLogger(PerfLogger.class.getName());

        logger.info("Starting perf log test");

        StopWatch stopWatch = new LoggingStopWatch("test time");

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        stopWatch.stop();

    }

}

Example log4j.xml

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>    

    <appender name="STDOUT-DEBUG" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p [%t]%x %M (%F:%L) - %m%n"/>
        </layout>
    </appender>


   <!-- Perf4J appenders -->
    <!--
       This AsyncCoalescingStatisticsAppender groups StopWatch log messages
       into GroupedTimingStatistics messages which it sends on the
       file appender defined below
    -->
    <appender name="CoalescingStatistics"
              class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
        <!--
          The TimeSlice option is used to determine the time window for which
          all received StopWatch logs are aggregated to create a single
          GroupedTimingStatistics log. Here we set it to 10 seconds, overriding
          the default of 30000 ms
        -->
        <param name="TimeSlice" value="10000"/>
        <appender-ref ref="fileAppender"/>
    </appender>


    <!-- This file appender is used to output aggregated performance statistics -->
    <appender name="fileAppender" class="org.apache.log4j.FileAppender">
        <param name="File" value="perfStats.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%m%n"/>
        </layout>
    </appender>

    <!-- Loggers -->
    <!--
      The Perf4J logger. Note that org.perf4j.TimingLogger is the value of the
      org.perf4j.StopWatch.DEFAULT_LOGGER_NAME constant. Also, note that
      additivity is set to false, which is usually what is desired - this means
      that timing statements will only be sent to this logger and NOT to
      upstream loggers.
    -->
    <logger name="org.perf4j.TimingLogger" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="CoalescingStatistics"/>
    </logger>

    <root>
        <priority value="info"/>
        <appender-ref ref="STDOUT-DEBUG"/>
    </root>

</log4j:configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:00:45+00:00Added an answer on May 14, 2026 at 9:00 am

    I checked the jar and there is no class named TimingLogger in the perf4j jar, this can also be seen here by searching their code repository, which would explain the messages not going to the file you would expect them to. If you use the default LoggingStopWatch class they show in the example it looks like the only thing it will ever do is print to std err which you can see here . I tried changing the logger in my code to use their Log4JStopWatch class instead and changed the logger in the xml file to be org.perf4j.log4j.Log4JStopWatch but the messages go stdout instead of the file, which is probably because it isn’t using the configs specified in the log4j.xml I’m guessing. I’ll try and follow up with the team maintaining the project to see if they have an updated example or bug fix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all I implemented my first PowerShell script, that does some setup, sets registry keys
I have setup some simple associations in my rails app: resources :properties do resources
I would like to setup some automated testing of test cases upon Fortran binaries
I've setup some Nunit tests for validating my statistical formulas within my .net v2
I'm trying to setup some friendly URLs on a SharePoint website. I know that
I originally setup some conditions using CGRectIntersectsRect for some collision detection which worked fine.
I need to setup some 301 permanent redirects in the web.config of an ASP.NET
I am trying to setup some decorators so that I can do something like:
I've setup some background colors for my Labels in order to position them. Now
Trying to setup some validation on the add to cart button for the dropdown

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.