You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Nemo Chen (JIRA)" <ji...@apache.org> on 2016/08/23 01:45:21 UTC

[jira] [Updated] (CAMEL-10263) Several log refactoring/improvement suggestions

     [ https://issues.apache.org/jira/browse/CAMEL-10263?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nemo Chen updated CAMEL-10263:
------------------------------
    Description: 
*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)

{code}exchangeId=exchange.getExchangeId(){code}

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


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)

{code}name=camelContext.getName(){code}

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

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 ()

{code}LOG.trace("Waiting for {} inflight exchanges to complete",inProgressCompleteExchanges.size());{code}

{code}
public int getInProgressCompleteExchanges() {
    return inProgressCompleteExchanges.size();
}
{code}

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)

{code}LOGGER.debug("Endpoint removed: {}, new total endpoints {}",disruptorEndpoint,endpoints.size());{code}

{code}
public synchronized int getEndpointCount() {
    return endpoints.size();
}
{code}

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)
{code}
log.debug("Deferring creation of TaskExecutor for listener container: {} as per policy: {}",listenerContainer,configuration.getDefaultTaskExecutorType());
{code}
{code}
@ManagedAttribute
public DefaultTaskExecutorType getDefaultTaskExecutorType() {
    return configuration.getDefaultTaskExecutorType();
}
{code}

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 ()
{code}
System.out.println("Could not close Class scope as there is no Injector for module type " + injector);
{code}
file: apache-camel-2.17.3/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java

void processPdu (CommandResponderEvent event)
{code}
LOG.debug("Received invalid trap PDU: " + pdu);
{code}

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.


  was:
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)

{code}exchangeId=exchange.getExchangeId(){code}

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


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)

{code}name=camelContext.getName(){code}

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

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 ()

{code}LOG.trace("Waiting for {} inflight exchanges to complete",inProgressCompleteExchanges.size());{code}

{code}
public int getInProgressCompleteExchanges() {
    return inProgressCompleteExchanges.size();
}
{code}

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)

{code}LOGGER.debug("Endpoint removed: {}, new total endpoints {}",disruptorEndpoint,endpoints.size());{code}

{code}
public synchronized int getEndpointCount() {
    return endpoints.size();
}
{code}

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)
{code}
log.debug("Deferring creation of TaskExecutor for listener container: {} as per policy: {}",listenerContainer,configuration.getDefaultTaskExecutorType());
{code}
{code}
@ManagedAttribute
public DefaultTaskExecutorType getDefaultTaskExecutorType() {
    return configuration.getDefaultTaskExecutorType();
}
{code}

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 ()
{code}
System.out.println("Could not close Class scope as there is no Injector for module type " + injector);
{code}
file: apache-camel-2.17.3/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java

void processPdu (CommandResponderEvent event)
{code}
LOG.debug("Received invalid trap PDU: " + pdu);
{code}

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.



> Several log refactoring/improvement suggestions
> -----------------------------------------------
>
>                 Key: CAMEL-10263
>                 URL: https://issues.apache.org/jira/browse/CAMEL-10263
>             Project: Camel
>          Issue Type: Bug
>            Reporter: Nemo Chen
>              Labels: easyfix, easytest
>
> *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)
> {code}exchangeId=exchange.getExchangeId(){code}
> {code}logger.log("NodeBreakpoint at node " + toNode + " is waiting to continue for exchangeId: "+ exchange.getExchangeId());{code}
> 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)
> {code}name=camelContext.getName(){code}
> {code}log.debug("Registering CamelContext [{}] of in OSGi registry",camelContext.getName());{code}
> 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 ()
> {code}LOG.trace("Waiting for {} inflight exchanges to complete",inProgressCompleteExchanges.size());{code}
> {code}
> public int getInProgressCompleteExchanges() {
>     return inProgressCompleteExchanges.size();
> }
> {code}
> 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)
> {code}LOGGER.debug("Endpoint removed: {}, new total endpoints {}",disruptorEndpoint,endpoints.size());{code}
> {code}
> public synchronized int getEndpointCount() {
>     return endpoints.size();
> }
> {code}
> 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)
> {code}
> log.debug("Deferring creation of TaskExecutor for listener container: {} as per policy: {}",listenerContainer,configuration.getDefaultTaskExecutorType());
> {code}
> {code}
> @ManagedAttribute
> public DefaultTaskExecutorType getDefaultTaskExecutorType() {
>     return configuration.getDefaultTaskExecutorType();
> }
> {code}
> 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 ()
> {code}
> System.out.println("Could not close Class scope as there is no Injector for module type " + injector);
> {code}
> file: apache-camel-2.17.3/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java
> void processPdu (CommandResponderEvent event)
> {code}
> LOG.debug("Received invalid trap PDU: " + pdu);
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)