• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Logging in JSP - Log4j  RSS feed

 
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?
 
Marshal
Posts: 67257
170
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
Marshal
Posts: 67257
170
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.
 
Paper beats rock. Scissors beats tiny ad.
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!