Best practise to log in JSP file | Community
Skip to main content
Level 6
Dec 6, 2016 6:45 AM UTC

Best practise to log in JSP file

Hi,

 

I would appreciate it if anyone could please point out to me any development article that would help me follow best practices in logging errors on a try {} catch () {} in JSP.

Regards

Clive Stewart

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Peter_Puzanovs
New Participant
Dec 6, 2016 12:03 PM UTC

Hi Clive,

It seems like Adobe(view from outside) are moving away from jsp code with lot's of inline Java code.

Have you looked at more modern practices such as HTL's and Sling Models(look like more modern practices)?

Regards,

Peter

Translate
Level 6
Dec 7, 2016 5:47 AM UTC

Hi Peter,

 

Unfortunately I am working on code written by other developers. They do not want to move to HTL. So when I look through their code all try {} catch() {} code suppress all errors. E.g
try {
Some Java code to read a resource
} catch (Exception e) {}

 

So I must make best of it as I cannot follow the best practice, which to me is use HTL (avoid JSP) and OSGI for business logic (i.e. do not have the java code for this in a jsp) , and where JSP is used keep the java simple. If its complex place it in OSGI. If it acceses JCr and othe Db resources, place it in OSGI.

 

But that is not up to me, so hence I am trying to think of what is the best way in AEM with JSP.
The simplest answer is to use the available implicit object, log as follows
=>  log.error("my error",e).

Translate
diptinarang
Level 3
Dec 6, 2016 10:10 AM UTC

Hi Cleve

I generally use Approach 1 mentioned here: http://www.codejava.net/java-ee/jsp/how-to-handle-exceptions-in-jsp

~Dipti

Translate
Level 6
Dec 6, 2016 11:59 AM UTC

Thank you for the helpful information

Translate