This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Logging in JSP - Log4j  RSS feed

 
Madhumitha Baskaran
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use Logging in JSP pages.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ page import="org.apache.log4j.Logger" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

Logger log1=Logger.getLogger(this.getClass());

log1.info("Information");
log1.debug("Hello");
%>
<%= new String("Hello") %>

<% %>
</body>
</html>

Still I dont see any error . I dont see log file also getting generated. Can you please help?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, logging should not be necessary in a JSP as a modern JSP should contain no Java code.

That said, how did you enable the debug level for the logger?
 
Madhumitha Baskaran
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

log4j.rootCategory=debug,stdout1

# A1 is set to be a LF5Appender which outputs to a swing
# logging console.

log4j.appender.stdout1=org.apache.log4j.FileAppender
log4j.appender.stdout1.File=SampleLogFile
log4j.appender.stdout1.layout=org.apache.log4j.PatternLayout

This is how I had log4j file.

My primary intent of using log file is to track all the activities happening in a web page. What would you suggest for that?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I wouldn't. Activities that are interesting enough to log should be happening in the controller, rather than the JSP.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!