cancel
Showing results for 
Search instead for 
Did you mean: 

I'm new JAVA developer, I want to log in my code. What is the best practice

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

I create a listener and I want to in logs information of the document.

Here is my code:

public class MyListener implements EventListener {
    public void handleEvent(Event event) throws ClientException {
        EventContext ctx = event.getContext();
        DocumentEventContext docCtx = (DocumentEventContext) ctx;
        // Here log doc title
    }    
}

What is best practive ?

1 ACCEPTED ANSWER

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Nuxeo uses the Log4J framework.

First you must add this static attribute:

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

 public class MyListener implements EventListener {

     private static final Log log = LogFactory.getLog(MyListener.class);

And use it to log your messages:

log.info("your message");

Choose a log level between fatal, error, warn, info, debug and trace.

Please see that thread and How to configure Nuxeo logging documentation.

Logging SomeException will look like:

catch (SomeException e) {
    log.error(String.format("Failed with transition %s on doc %s", transition, doc.getId), e);
}

Important: don't let the default logging suggested by your IDE:

e.printStackTrace();

View answer in original post

1 REPLY 1

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Nuxeo uses the Log4J framework.

First you must add this static attribute:

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

 public class MyListener implements EventListener {

     private static final Log log = LogFactory.getLog(MyListener.class);

And use it to log your messages:

log.info("your message");

Choose a log level between fatal, error, warn, info, debug and trace.

Please see that thread and How to configure Nuxeo logging documentation.

Logging SomeException will look like:

catch (SomeException e) {
    log.error(String.format("Failed with transition %s on doc %s", transition, doc.getId), e);
}

Important: don't let the default logging suggested by your IDE:

e.printStackTrace();
Getting started

Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.