logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daling Xu" <daling...@sonexent.com>
Subject RE: config log4j to print to console from applet and logfile from servlet --- Please HELP!
Date Fri, 07 Jun 2002 16:42:48 GMT
Hi, All

Thank you very much for the reply.

Could you explain a little detail how to have multiple config file? I am an
absolutly beginner on  this topic, only know to use log4j.properties, the
default config file, now. Could you point out some links of manual for
log4j. I heard of there is a detail manul for log4j, but I can't find it in
jakarta.apache.org's log4j site.

Thanks.

Daling

-----Original Message-----
From: Klein, Scott @ TW [mailto:scott.klein@L-3com.com]
Sent: Thursday, June 06, 2002 6:11 PM
To: 'Log4J Users List'
Subject: RE: config log4j to print to console from applet and logfile
from servlet --- Please HELP!


Well, I have been mucking around in the config files so here is my
observation:

<snip>
log4j.logger.servlet.Register=DEBUG, dest1
log4j.logger.applet.myApplet=DEBUG, dest2
</snip>

the only thing that changed in the last version was the addition of the
appenders. And since dest2 is definitely NOT causing any problems, it has to
be the dest1 entry...

I think the problem is that when you specify an Appender it will create it
for you - and if this config file is used in an Applet then, of course,
there are going to be problems opening the file (without permission, that
is). So, have a config file for your server and a seperate one that gets
deployed with your applet (which makes sense anyway, right?)

hope that helps (and works)

-----Original Message-----
From: Daling Xu [mailto:daling.xu@sonexent.com]
Sent: Thursday, June 06, 2002 2:58 PM
To: Log4J Users List
Subject: config log4j to print to console from applet and logfile from
servlet --- Please HELP!


Hi, All

I posted a message here two days ago, but nobody replied :(
Please take a look at this, any help will be warmly appreciated.

I am considering using log4j in my project, which is a web-application. I
used
j2sdk1.4, servlet 2.3 , java plug in 1.4, and log4j 1.2.3.  When I use log4j
to log informations in the jsp or servlet, every thing is fine, I can write
to both the console or a file in the server side.

Here is the log4j.properties I used, you can notice I configed two servlets
to log into different  destinations: console and file. It works.

log4j.rootLogger=FATAL, dest2
log4j.logger.servlet.UserLogin=FATAL
log4j.logger.servlet.Register=DEBUG, dest1

log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.File=logExample.log
log4j.appender.dest1.MaxFileSize=100KB
log4j.appender.dest1.MaxBackupIndex=1
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

log4j.appender.dest2=org.apache.log4j.ConsoleAppender
log4j.appender.dest2.layout=org.apache.log4j.PatternLayout

Then I added an applet into my project and try to use logger in it also. If
I use the following log4j.prpoerties, it also works well, I can print to
console from both applet and servlet.

#every logger log to console
log4j.rootLogger=FATAL, dest2
log4j.logger.servlet.UserLogin=FATAL
log4j.logger.servlet.Register=DEBUG
log4j.logger.applet.myApplet=DEBUG

log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.File=logExample.log
log4j.appender.dest1.MaxFileSize=100KB
log4j.appender.dest1.MaxBackupIndex=1
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

log4j.appender.dest2=org.apache.log4j.ConsoleAppender
log4j.appender.dest2.layout=org.apache.log4j.PatternLayout

But, I still want the logger to write to a file, because I can't access the
console of our deployed server. So I changed the log4j.properties to:

log4j.rootLogger=FATAL, dest2
log4j.logger.servlet.UserLogin=FATAL
#set servlet Register log to a file
log4j.logger.servlet.Register=DEBUG, dest1
log4j.logger.applet.myApplet=DEBUG, dest2

log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.File=logExample.log
log4j.appender.dest1.MaxFileSize=100KB
log4j.appender.dest1.MaxBackupIndex=1
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

log4j.appender.dest2=org.apache.log4j.ConsoleAppender
log4j.appender.dest2.layout=org.apache.log4j.PatternLayout

Now, there is a java.security.AccessControlException, the exception
information is attached at end of this mail.

Is this a bug? How can I fix it?

I understand that in the applet I can't write to a file in the server side.
But I still want to have the flexibility to log to the file from the
servlet. Now it looks that I can only log to console if I want the applet
also use log4j.

Here is the error message from the applet:

java.lang.ExceptionInInitializerError

	at org.apache.log4j.Category.getInstance(Category.java:517)

	at
com.myCompany.myProject.myPackage.myApplet.<clinit>(myApplet.java:84)

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)

	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)

	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)

	at java.lang.reflect.Constructor.newInstance(Unknown Source)

	at java.lang.Class.newInstance0(Unknown Source)

	at java.lang.Class.newInstance(Unknown Source)

	at sun.applet.AppletPanel.createApplet(Unknown Source)

	at sun.plugin.AppletViewer.createApplet(Unknown Source)

	at sun.applet.AppletPanel.runLoader(Unknown Source)

	at sun.applet.AppletPanel.run(Unknown Source)

	at java.lang.Thread.run(Unknown Source)

Caused by: java.security.AccessControlException: access denied
(java.io.FilePermission logFile.log write)

	at java.security.AccessControlContext.checkPermission(Unknown
Source)

	at java.security.AccessController.checkPermission(Unknown Source)

	at java.lang.SecurityManager.checkPermission(Unknown Source)

	at java.lang.SecurityManager.checkWrite(Unknown Source)

	at java.io.FileOutputStream.<init>(Unknown Source)

	at java.io.FileOutputStream.<init>(Unknown Source)

	at org.apache.log4j.FileAppender.setFile(FileAppender.java:272)

	at
org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:156)

	at
org.apache.log4j.FileAppender.activateOptions(FileAppender.java:151)

	at
org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:248)

	at
org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:124
)

	at
org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:88)

	at
org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.jav
a:645)

	at
org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.jav
a:603)

	at
org.apache.log4j.PropertyConfigurator.parseCatsAndRenderers(PropertyConfigur
ator.java:524)

	at
org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:
408)

	at
org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:
432)

	at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.
java:456)

	at org.apache.log4j.LogManager.<clinit>(LogManager.java:145)

	... 13 more

Any information will be appreciated.

Daling



--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message