I'm new JAVA developer, I want to log in my code. What is the best practice
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 ?
0 votes
1 answers
1626 views
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();