Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-10263

Several log refactoring/improvement suggestions



    • Task
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 2.17.3
    • 2.18.0
    • None
    • None
    • Novice


      method invocation replaced by variable

      file: apache-camel-2.17.3/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java

      method: void beforeProcess (Exchange exchange, Processor processor, ProcessorDefinition<?> definition)

      logger.log("NodeBreakpoint at node " + toNode + " is waiting to continue for exchangeId: "+ exchange.getExchangeId());

      file: apache-camel-2.17.3/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java

      method : ServiceRegistration<?> registerCamelContext (CamelContext camelContext)

      log.debug("Registering CamelContext [{}] of in OSGi registry",camelContext.getName());

      The method invocations in above examples are assigned to variables before, we should replace the method invocation with the variable for simpliciy and readabiliy of logs.

      method invocation in return statement

      file: apache-camel-2.17.3/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
      void doForceCompletionOnStop ()

      LOG.trace("Waiting for {} inflight exchanges to complete",inProgressCompleteExchanges.size());
      public int getInProgressCompleteExchanges() {
          return inProgressCompleteExchanges.size();

      file: apache-camel-2.17.3/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorReference.java

      method:void removeEndpoint (final DisruptorEndpoint disruptorEndpoint)

      LOGGER.debug("Endpoint removed: {}, new total endpoints {}",disruptorEndpoint,endpoints.size());
      public synchronized int getEndpointCount() {
          return endpoints.size();

      file: apache-camel-2.17.3/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java

      method: void configureListenerContainer (AbstractMessageListenerContainer listenerContainer, JmsConsumer consumer)

      log.debug("Deferring creation of TaskExecutor for listener container: {} as per policy: {}",listenerContainer,configuration.getDefaultTaskExecutorType());
      public DefaultTaskExecutorType getDefaultTaskExecutorType() {
          return configuration.getDefaultTaskExecutorType();

      In the above examples, the method invocations are in the return statements of the method in the same class. Replace the method invocations with the methods will make the log more readable and easy to maintain.

      Check if variable is null

      file: apache-camel-2.17.3/components/camel-guice/src/test/java/org/apache/camel/guice/testing/InjectorManager.java

      void afterClasses ()

      System.out.println("Could not close Class scope as there is no Injector for module type " + injector);

      file: apache-camel-2.17.3/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java

      void processPdu (CommandResponderEvent event)

      LOG.debug("Received invalid trap PDU: " + pdu);

      In the above examples, the variable is null in the log. There is no need to print the invalid variable in the logs. Suggestion: delete the variables in the logs to avoid confusion.


        Issue Links



              acosentino Andrea Cosentino
              chenfsd Nemo Chen
              0 Vote for this issue
              4 Start watching this issue