Charles Owen

Ranch Hand
+ Follow
since Aug 31, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Charles Owen

I have a code snippet working in which I am invoking SQL Loader from Java. However, I would like to make the table name in the control file dynamic. Is there a way to set the table name to a variable in the control file and assign this variable a value outside of the control file within Java?
13 years ago
Try the Tomcat 6 documentation. Here's a topic that discusses this very issue: http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html

Alternatively, you can just startup Tomcat via the command line or through a script:

1) Open the command line (run as administrator if necessary)
2) cd to your Tomcat installation bin directory
3) type startup.bat

Hope this helps,
13 years ago
You can also start tomcat by the command line. cd to the tomcat installation\bin directory. Then you should be able to just type startup.bat.

You may have to open the console as an administrator.
13 years ago
I found out you can create multiple file appenders in one configuration file. I found a nice tutorial online -- http://ibswings.blogspot.com/2009/03/log4j-configuration-controlling-logging.html -- but for the most part, I figured this out on my own. One of the keys is additivity. By default, one file appender's messages will be appended to another file appender until it gets to root. If you set this to false then you are able to achieve distinct log messages for specific packages, such as within your application, or even hibernate SQL messages.

I'm including the configuration file I arrived at in case it is helpful to someone else:

[code=xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">


<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c (%F:%L) - %m%n"/>
</layout>
</appender>


<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="c:\\development\\logs\\excellor.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c (%F:%L) - %m%n"/>
</layout>
</appender>

<appender name="FILE1" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="c:\\development\\logs\\controller.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c (%F:%L) - %m%n"/>
</layout>
</appender>

<appender name="FILE2" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="c:\\development\\logs\\hibernate.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c (%F:%L) - %m%n"/>
</layout>
</appender>

<appender name="FILE3" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="c:\\development\\logs\\hibernateSQL.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c (%F:%L) - %m%n"/>
</layout>
</appender>


<category name="com.excellor" additivity="false">
<priority value="debug"/>
<appender-ref ref="FILE"/>
</category>

<category name="com.excellor.contactmanager.controller" additivity="false">
<priority value="debug"/>
<appender-ref ref="FILE1"/>
</category>

<category name="org.hibernate" additivity="false">
<priority value="debug"/>
<appender-ref ref="FILE2"/>
</category>

<category name="org.hibernate.SQL" additivity="false">
<priority value="debug"/>
<appender-ref ref="FILE3"/>
</category>


<root>
<priority value="error"/>
<appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>

[/code]
13 years ago
Thanks, but I do not see a log4j forum in Java Ranch. Do you mean on the log4j web site?
13 years ago
Tim,

You're right. I was able to get the .xml configuration working.

Now I am looking to do something more sophisticated, please tell me if I should direct this to a different forum.

I only want to log application-specific messages, as in, only log.info or log.debug messages I have in code to this log file. Developer would look at this one. I would like the Tomcat-specific messages to go to catalina.out. A sysadmin would look at this one.

I would like to log hibernate messages to a competely separate log file. I would like to write out the hibernate sql to its own file. Maybe a DBA would look at this one.

This is what I have now...

[code=xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="file"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="c:/development/logs/contactmanager.log" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="debugfile" />
<appender-ref ref="file" />
</root>
</log4j:configuration>
[/code]
13 years ago
Tim, however, when the application is deployed, the log4j.xml goes to the WEB-INF/classes folder just the same. Anyway, I'll just use the properties file for web apps.
13 years ago
I found out that the xml configuration just doesn't work for a web application as it does for a regular Java application. Does anyone know why? I was able to get the logging to work when I replaced the xml configuration with a properties file.
13 years ago
I am trying to get log4j working within a Tomcat 6 application. It is a Maven project.

I have included these dependencies in Maven:

slf4j
slf4j-api
log4j

I created an xml configuration file and put it in src/main/resources (log4j.xml)

[code=java]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="file"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="test.log" />
<param name="threshold" value="info" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="file" />
</root>
</log4j:configuration>
[/code]

In a JSP, I am doing something simple like instantiating a class. Within the class constructor, I am merely logging a simple message. However, the log file never appears. I would expect to see it directly under the root of the application.

[code=java]
import org.apache.log4j.Logger;
public class Person
{
private String lastName;
private String firstname;
private String ssn;

private static Logger logger = Logger.getLogger(Person.class);
public Person(String lastName, String firstname, String ssn, int age)
{
super();
this.lastName = lastName;
this.firstname = firstname;
this.ssn = ssn;
this.age = age;
logger.debug("New Person" + lastName);
System.out.println("New Person " + lastName);
}
}
[/code]

What am I doing wrong?
13 years ago
I used a solution I found on the Spring Source site that seems to be pointing me in the right direction.

http://forum.springsource.org/showth...amp-Spring-MVC
13 years ago
I can upload one file, but for some reason it's always the first file.

<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="500000" >
</beans:bean>
13 years ago
I'm looking for a Spring 3 Multi File Upload solution. If someone could point me in the right direction, it would be much appreciated.
13 years ago
I'm seeking a good book and/or tutorial on unit testing for Spring Controllers/Views. Some books will discuss testing but then give you very simplistic examples that you couldn't use in a real project. I guess a focus I'd like to see a focus on a strategy for interacting with other application layers, such as mock objects you're accessing from the database/hibernate layer. How do I get at the request, response, and session, etc to test whether certain objects or values are present.

Thanks
13 years ago
I've created a controller that works, now I am just trying to test out the functionality with unit tests. I'm having some problems that I cannot resolve. I get a NullPointerException when I call the welcome method in the SurveyController. It seems to fail to create the SurveyControl domain object in the unit test. However, when I run the actual code it works. This is my first attempt at writing a unit test for a Spring controller, so I really don't know what I am doing.

this is the controller method--two different services are being called in order to populate the surveyControl and ncsPackage
[code=java]
@RequestMapping(value="/", method=RequestMethod.POST)
public String welcome(@RequestParam(required=true, value="solicitation") String solicitation,

ModelMap model)
{

SurveyControl surveyControl= surveyControlService.getSurveyControl(new Long(1));
SomePackage somePackage = somePackageService.getSomePackage(solicitation);


model.addAttribute("surveyControl",surveyControl);
model.addAttribute("somePackage",somePackage);

return "welcome";
}
[/code]

--here is my attempt at creating a unit test
[code]
import org.springframework.ui.ModelMap;
import org.junit.Test;
import org.springframework.mock.web.*;
import static org.junit.Assert.*;


public class SurveyControllerTest
{
private static final String SOLICITATION_NUMBER = "xxxxxxxx";

SurveyController surveyController;

@Test
public void welcomeShouldReturnCorrectView()
{
surveyController = new SurveyController();
MockHttpServletRequest request = new MockHttpServletRequest("POST","/");
request.setSession(new MockHttpSession(null));
MockHttpServletResponse response = new MockHttpServletResponse();
ModelMap model = new ModelMap();
String viewName = surveyController.welcome(SOLICITATION_NUMBER,model);

System.out.println("THIS IS THE VIEW NAME" + viewName);
}
}
[/code]
13 years ago
We resolved this by creating a tiles definition for the tabs, then using a combination of CSS, Javascript, and JSTL.
13 years ago