----- Original Message -----
From: "Alastair wilcox" <[EMAIL PROTECTED]>
To: "Cactus-User" <[EMAIL PROTECTED]>
Sent: Thursday, September 27, 2001 3:56 PM
Subject: Cannot find the file log_server.properties when using method
LogService.init() to initialise the logging system
> Hello,
>
> I am using Cactus version 1.2 with Tomcat 3.2.3, the test's are being run
> using Ant.
>
> The test appears to run fine except that I get this error message:
>
>
> run_tests:
> [junit] Running uk.co.servsoft.servc.test.CreateAccountTest
> [junit] [warning] Failed to configure logging system : Could not find
> file [C:\projects\jez_appcode\src\conf\log_client.properties]
> [junit] log4j:ERROR No appenders could be found for category
> (uk.co.servsoft.servc.test.CreateAccountTest).
> [junit] log4j:ERROR Please initialize the log4j system properly.
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.612 sec
> [junit] Testsuite: uk.co.servsoft.servc.test.CreateAccountTest
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.612 sec
> [junit]
> [junit] Testcase: testCreateAccount took 1.612 sec
>
> BUILD SUCCESSFUL
>
> Here is the log_client.properties file, where I allocate the test category
> an appender:
>
> log4j.appender.cactus = org.apache.log4j.FileAppender
> log4j.appender.cactus.File = cactus_server.log
> log4j.appender.cactus.Append = false
> log4j.appender.cactus.layout = org.apache.log4j.PatternLayout
> log4j.appender.cactus.layout.ConversionPattern = %r [%t] %-5p %c{2} %x -
%m
> %n
>
> log4j.category.org.apache.cactus = INFO, cactus
>
> log4j.category.uk.co.servsoft.servc.test = DEBUG, cactus
>
>
> This is the code that is causing the errors.
>
> public CreateAccountTest(String theName)
> {
> super(theName);
>
>
LogService.getInstance().init("C:\\projects\\jez_appcode\\src\\conf\\log_cli
> ent.properties");
> logger =
> LogService.getInstance().getLog(CreateAccountTest.class.getName());
> }
>
> JAVADOC for the method org.apache.cactus.util.log.LogService.init():
>
> public void init(java.lang.String theFileName)
> Initialize the logging system. Need to be called once before calling
> getLog().
> Parameters:
> theFileName - the file name (Ex: "/log_client.properties") or null to
> initialize a dummy logging system, meaning that all log calls will have no
> effect. This is useful for unit testing for instance where the goal is not
> to verify that logs are printed.
>
> I have read the Javadoc for this class, and I have removed the reference
to
> the log_client.properties file, I have also
> changed the back slashes in the file name to forward slashes, single
forward
> slashes, back slashes etc.
> Even when making these changes and redoing the test's I still get the same
> error.
>
> Also I have checked that the file is in the correct path ;-)
>
> I have looked in the mail archive but have not found any emails about this
> error.
>
Ok, I know what the problem is :-)
Several things :
1/ The best way to write logs in your test case is simply to use the
"logger" class variable that is inherited from ServletTestCase (or any
XXXTestCase which itself inherit from AbstractTestCase) :
public void testXXX()
{
logger.debug("some log");
[...]
}
The logging system is then automatically initialized for you and you don't
have to initialize it youself. Actually it is the only working solution and
it will fail if you try to init it yourself but that's another story (see
thread "Log4j in Cactus").
2/ You're right the javadoc for LogService.init() is not clear enough but
the file that you pass is actually a file that needs to be in the classpath.
If you drop it in the root of a directory which is in the classpath then the
string would be "/log_client.properties". If you drop it in package x.y.z
then it would be "/x/y/z/log_client.properties". But you don't have to care
about it as the logging system is initialized for you. So you simply need
either to edit the existing log_client.properties that is in cactus.jar or
create yours that you would put in a directory that you would put *before*
the cactus.jar in the classpath.
Hope it helps.
> Thank you for your time.
you're welcome :)
>
> Kind Regards,
> Alastair Wilcox
-Vincent
P.S.: We'll definitely need to improve the doc and put this at least as a
FAQ as it becomes one ... :)