You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by PW New Media Support <su...@liquidsix.com> on 2004/10/29 02:16:03 UTC
[sup #ASX-79647-333]: Re: Log4j with Tomcat .. (3 questions)
Thank you for contacting PW New Media. We have recieved your request (Re: Log4j with Tomcat .. (3 questions)) and it has been assigned a Ticket ID of ASX-79647-333. If you have further information or comments about this ticket, please reply to this email so that it can be logged with the ticket you originally sent.
To be fair, unless marked as urgent (and it is decided that the content is urgent), we will answer all tickets in the order that they were submitted, and aim to reply as soon as possible.
This helpdesk deals with support queries for the following products and services:
- LiquidSix Hosting (www.liquidsix.com)
- Helm Extensions (www.helmextensions.com)
- General PW New Media Enquiries (www.pwnewmedia.com)
Regards,
LiquidSix Support
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Log4j with Tomcat .. (3 questions)
Posted by Ben Souther <bs...@fwdco.com>.
Ah, sorry. I didn't look closely enough at your code.
The first example on this page shows how to read a properties file
using getResourceAsStream(). Use that to get the properties file for the
Configurator.
http://nagoya.apache.org/wiki/apachewiki.cgi?Tomcat/Howto
On Thu, 2004-10-28 at 20:25, Ben Souther wrote:
> Try pulling out the:
> PropertyConfigurator.configure("log4j.properties")
> line.
>
> You shouldn't need it.
> Just let log4j find it in your classes directory.
>
>
> On Thu, 2004-10-28 at 20:14, Mufaddal Khumri wrote:
> > I just did that. I have a WEB-INF/classes/log4j.properties file with
> > the following:
> >
> > # initialise root logger with level DEBUG and call it A1
> > log4j.rootLogger=DEBUG, A1
> > # set the appender to be FileAppender
> > log4j.appender.A1=org.apache.log4j.FileAppender
> > # set set that layout to be SimpleLayout
> > log4j.appender.A1.layout=org.apache.log4j.SimpleLayout
> >
> > I have this in the java code:
> > Logger logger = Logger.getLogger(Helper.class);
> > PropertyConfigurator.configure("log4j.properties");
> >
> > I get the following exception:
> > java.io.FileNotFoundException: log4j.properties (No such file or
> > directory)
> > at java.io.FileInputStream.open(Native Method)
> > at java.io.FileInputStream.<init>(FileInputStream.java:106)
> > at java.io.FileInputStream.<init>(FileInputStream.java:66)
> > at
> > org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.j
> > ava:297)
> >
> >
> > On Oct 28, 2004, at 4:56 PM, Ben Souther wrote:
> >
> > > Log4j looks on your class path for a properties file
> > > "log4j.properties". If you put the file in WEB-INF/classes
> > > it will find it.
> > >
> > > Here's a real simple example:
> > > log4j.rootCategory=DEBUG, dest1
> > > log4j.appender.dest1=org.apache.log4j.RollingFileAppender
> > > log4j.appender.dest1.file=/usr/local/tomcat/logs/myapp.log
> > > log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
> > > log4j.appender.dest1.layout.ConversionPattern=%-5p: %m%n
> > >
> > >
> > >
> > >
> > >
> > > On Thu, 2004-10-28 at 19:08, Mufaddal Khumri wrote:
> > >> Hi,
> > >>
> > >> Am new to log4j. Am using Tomcat 5 and my webapp-myNiceWebApp is in
> > >> Tomcat/webapps/myNiceWebApp
> > >>
> > >> I have a class that I have the following code in:
> > >>
> > >> Logger logger = Logger.getLogger(Helper.class);
> > >> SimpleLayout layout = new SimpleLayout();
> > >>
> > >> FileAppender appender = null;
> > >> try
> > >> {
> > >> appender = new FileAppender(layout,"output1.txt",false);
> > >> }
> > >> catch(Exception e)
> > >> {
> > >> e.printStackTrace();
> > >> }
> > >>
> > >> logger.addAppender(appender);
> > >> logger.setLevel((Level)Level.DEBUG);
> > >>
> > >> logger.debug("some message");
> > >>
> > >> Que 1. Where does the file output1.txt get created?
> > >> Que 2. How does log4j know where to create it and can it be
> > >> controlled?
> > >> Que 3. I am going to use a configuration file either use the
> > >> DOMConfigurator or PropertyConfigurator to load the log4j properties.
> > >> Where do i place this file log4j configuration file?
> > >>
> > >> Thanks,
> > >>
> > >>
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > Mufaddal Khumri
> > Software Developer
> > Waves In Motion
> > Phone: 602 956 7080 x 26
> > Email: mufaddal@wmotion.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How to Display a byte array (contents of a MS DOC fie, Excel,
..) in web browser
Posted by Ben Souther <bs...@fwdco.com>.
Set the content type.
Set the content disposition.
Get a servletOutputStream from the response object.
Write the bytes to the outputStream.
Flush the stream.
Sort of like this...
You'll need to add exception handling and probably buffering if you're
streaming the byte array in and out at the same time.
There are lots of examples on the web for doing that.
This should get you started.
response.setContentType("application/vnd.ms-word");
response.setHeader(
"Content-Disposition", "attachment; filename=myFile.doc");
ServletOutputStream out = response.getOutputStream();
for(int i = 0; i < byteArray.length; i++){
out.write(byteArray[i]);
}
out.flush();
On Thu, 2004-10-28 at 21:11, Daxin Zuo wrote:
> I receive a byte array from a remote server, and the servlet will display it
> on the browser. The byte array contains a MS DOC file. If I simply convert
> it to a String, the contents will be meaningless.
> Please forward instruction.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
How to Display a byte array (contents of a MS DOC fie, Excel, ..) in web browser
Posted by Daxin Zuo <dz...@techexcel.com>.
I receive a byte array from a remote server, and the servlet will display it
on the browser. The byte array contains a MS DOC file. If I simply convert
it to a String, the contents will be meaningless.
Please forward instruction.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Log4j with Tomcat .. (3 questions)
Posted by Ben Souther <bs...@fwdco.com>.
Try pulling out the:
PropertyConfigurator.configure("log4j.properties")
line.
You shouldn't need it.
Just let log4j find it in your classes directory.
On Thu, 2004-10-28 at 20:14, Mufaddal Khumri wrote:
> I just did that. I have a WEB-INF/classes/log4j.properties file with
> the following:
>
> # initialise root logger with level DEBUG and call it A1
> log4j.rootLogger=DEBUG, A1
> # set the appender to be FileAppender
> log4j.appender.A1=org.apache.log4j.FileAppender
> # set set that layout to be SimpleLayout
> log4j.appender.A1.layout=org.apache.log4j.SimpleLayout
>
> I have this in the java code:
> Logger logger = Logger.getLogger(Helper.class);
> PropertyConfigurator.configure("log4j.properties");
>
> I get the following exception:
> java.io.FileNotFoundException: log4j.properties (No such file or
> directory)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(FileInputStream.java:106)
> at java.io.FileInputStream.<init>(FileInputStream.java:66)
> at
> org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.j
> ava:297)
>
>
> On Oct 28, 2004, at 4:56 PM, Ben Souther wrote:
>
> > Log4j looks on your class path for a properties file
> > "log4j.properties". If you put the file in WEB-INF/classes
> > it will find it.
> >
> > Here's a real simple example:
> > log4j.rootCategory=DEBUG, dest1
> > log4j.appender.dest1=org.apache.log4j.RollingFileAppender
> > log4j.appender.dest1.file=/usr/local/tomcat/logs/myapp.log
> > log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
> > log4j.appender.dest1.layout.ConversionPattern=%-5p: %m%n
> >
> >
> >
> >
> >
> > On Thu, 2004-10-28 at 19:08, Mufaddal Khumri wrote:
> >> Hi,
> >>
> >> Am new to log4j. Am using Tomcat 5 and my webapp-myNiceWebApp is in
> >> Tomcat/webapps/myNiceWebApp
> >>
> >> I have a class that I have the following code in:
> >>
> >> Logger logger = Logger.getLogger(Helper.class);
> >> SimpleLayout layout = new SimpleLayout();
> >>
> >> FileAppender appender = null;
> >> try
> >> {
> >> appender = new FileAppender(layout,"output1.txt",false);
> >> }
> >> catch(Exception e)
> >> {
> >> e.printStackTrace();
> >> }
> >>
> >> logger.addAppender(appender);
> >> logger.setLevel((Level)Level.DEBUG);
> >>
> >> logger.debug("some message");
> >>
> >> Que 1. Where does the file output1.txt get created?
> >> Que 2. How does log4j know where to create it and can it be
> >> controlled?
> >> Que 3. I am going to use a configuration file either use the
> >> DOMConfigurator or PropertyConfigurator to load the log4j properties.
> >> Where do i place this file log4j configuration file?
> >>
> >> Thanks,
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> Mufaddal Khumri
> Software Developer
> Waves In Motion
> Phone: 602 956 7080 x 26
> Email: mufaddal@wmotion.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org