You could use this class. It takes the ServletContext as a constructor and extends PrintWriter.
org.apache.struts.util.ServletContextWriter But I think using Commons Logging with Log4J is nicer. You can define that certain packages are logged to different loggers in the Log4J configuration file. This example would log the package 'org.apache.struts' to MyAppender. You can setup as many of these as you need. You could have a master one and one for each main package. You can also control the log level for each appender. log4j.appender.MyAppender=org.apache.log4j.DailyRollingFileAppender log4j.appender.MyAppender.File=../log/my.log log4j.appender.MyAppender.DatePattern='.'yyyy-MM-dd log4j.appender.MyAppender.layout=org.apache.log4j.PatternLayout log4j.appender.MyAppender.layout.ConversionPattern=%d{MM/dd/yyyy HH:mm:ss} %-5p %c - %m%n log4j.category.org.apache.struts=DEBUG, MyAppender David --- Ben Liang <[EMAIL PROTECTED]> wrote: > Can't you have a logger point to tomcat log file? > > Ben > ----- Original Message ----- > From: "Charlie Toohey" <[EMAIL PROTECTED]> > To: "Struts Users Mailing List" > <[EMAIL PROTECTED]> > Sent: Tuesday, February 26, 2002 1:18 PM > Subject: Re: Logging in beans > > > > Thanks for all of the responses. They've gotten > away from my original > > question just a bit. > > > > Assuming that I am using the Commons Logging > package/Log4j in my beans, > and I > > want to log something to the Tomcat log file, how > can the bean obtain the > > output stream for the Tomcat log file in a webapp > framework independent > way > > --- i.e. I don't want to pass the ActionServlet > object to the bean and use > > its log method, as the bean would then be tied to > a particular web > > application framework (in this case, Struts), > which would inhibit its > > reusability. Instead, I would want to pass > something more generic, > > java.io.OuputStream-like, to the bean, so that it > can use whatever logging > > package I have chosen to log to this stream. The > question is really, how > do I > > obtain the java.io.OutputStream for the Tomcat log > file in my Struts > action > > class so that I can pass it as a parameter to my > bean methods. > > > > Charlie > > > > > > On Tuesday 26 February 2002 10:04 am, you wrote: > > > I think it is nice to use Commons Logging just > so you > > > have the option of easily switching to another > logging > > > framework. You may want to use some other > logging > > > framework other than Log4J (my choice) or Jdk1.4 > at > > > some point. You won't have to change any of you > code > > > if you use Commons Logging. Struts 1.1 is going > to > > > use Commons Logging. The Struts shared source > is > > > using it as of last nights build. > > > > > > David > > > > > > --- keithBacon <[EMAIL PROTECTED]> > wrote: > > > > Does anybody know how the new Java 1.4 logging > API > > > > affects things? > > > > My guess is it increases the desirability of > using > > > > the > > > > jakarta Commons Logging Package. You can use > log4j > > > > for now & easily switch > > > > later. > > > > But for students or people that can gurantee > they > > > > will deploy on Java 1.4 > > > > shouldn't they just use the JDK logging API > > > > directly? > > > > But then surely the next release of struts > will use > > > > the Commons logging so we > > > > should too? Oh boy. > > > > > > > > > > > > --- David Winterfeldt <[EMAIL PROTECTED]> > > > > > > > > wrote: > > > > > I would suggest using the Commons Logging > Package > > > > > > (http://jakarta.apache.org/commons/logging.html). > > > > > This is a generic interface to logging > packages. > > > > > > > > If > > > > > > > > > Log4J is detected, it will use it. > > > > > > > > > > excerpt from the website: > > > > > "The Logging package is an ultra-thin bridge > > > > > > > > between > > > > > > > > > different logging libraries. Commons > components > > > > > > > > may > > > > > > > > > use the Logging API to remove compile-time > and > > > > > run-time dependencies on any particular > logging > > > > > package, and contributors may write Log > > > > > implementations for the library of their > choice." > > > > > > > > > > > > > > > David > > > > > > > > > > --- Phase Web and Multimedia <[EMAIL PROTECTED]> > > > > > > > > wrote: > > > > > > log4j would work well. Schedule away a day > or so > > > > > > > > to > > > > > > > > > > become familiar with it > > > > > > and download the 1.2b3 version. This will > insure > > > > > > that you are prepared for > > > > > > the future changes in log4j and will keep > you > > > > > > > > from > > > > > > > > > > programming with > > > > > > deprecated code. > > > > > > > > > > > > http://jakarta.apache.org/log4j/ > > > > > > > > > > > > Brandon Goodin > > > > > > Phase Web and Multimedia > > > > > > P (406) 862-2245 > > > > > > F (406) 862-0354 > > > > > > [EMAIL PROTECTED] > > > > > > http://www.phase.ws > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > > From: Charlie Toohey > > > > > > > > [mailto:[EMAIL PROTECTED]] > > > > > > > > > > Sent: Monday, February 25, 2002 7:28 PM > > > > > > To: [EMAIL PROTECTED] > > > > > > Subject: Logging in beans > > > > > > > > > > > > > > > > > > I would like to log some information in > the > > > > > > > > Tomcat > > > > > > > > > > log file from my beans. > > > > > > But I don't want to use the ActionServlet > log > > > > > > method, as passing an > > > > > > ActionServlet object as a parameter to a > bean > > > > > > > > would > > > > > > > > > > violate the bean > > > > > > philosophy that beans should be completely > > > > > > independent of a web application > > > > > > framework, such as Struts, for > reusability. How > > > > > > could I just pass in the > > > > > > Stream to the Tomcat log file to a bean so > that > > > > > > > > it > > > > > > > > > > can log to the Stream and > > > > > > maintain its web app framework > independence ? > > > > > > > > > > > > Thanks, > > > > > > Charlie > > > > > > > > > > > > -- > > > > > > To unsubscribe, e-mail: > > > > > > > > > <mailto:[EMAIL PROTECTED]> > > > > > > > > > > For additional commands, e-mail: > === message truncated === __________________________________________________ Do You Yahoo!? Yahoo! Greetings - Send FREE e-cards for every occasion! http://greetings.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>