
Image via Wikipedia
We needed different log files for a common web project, this gateway project simply loads web services dynamically and generates the wsdd files at runtime, but the problem was huge size of the common log file used by all services. So we needed different log files for different services.
Here is the step by step solution to separate&customize the log files:
- The first step is adding a filter to web.xml file so we can set the service names:
<filter>
<filter-name>WSLoggerFilter</filter-name>
<filter-class>com.logger.WSLoggerFilter</filter-class>
<description></description>
</filter>
<filter-mapping>
<filter-name>WSLoggerFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Here is the simple filter – WSLoggerFilter.java:
public final class WSLoggerFilter implements Filter {
private static final String SERVICE_NAME = "serviceName";
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String[] url = ((HttpServletRequest)request).getRequestURI().split("/");
MDC.put(SERVICE_NAME, url != null ? url[url.length - 1] : "");
// Forward the request to the next resource in the chain
chain.doFilter(request, response);
MDC.remove(SERVICE_NAME);
} .....
- Next step is implementing the custom appender. I used DailyRollingFileAppender to change the name of the logging file, simply by adding service name. Simply do not forget to override close method to close all the appenders we used. The custom adapter file WSLoggerAppender.java:
public class WSLoggerAppender extends DailyRollingFileAppender {
private String mdcName;
private Map<string, dailyrollingfileappender=""> map = new HashMap<string, dailyrollingfileappender="">();
@Override
public synchronized void doAppend(LoggingEvent event) {
Object key = MDC.get(getMdcName());
if (key == null) {
super.doAppend(event);
return;
}
String serviceName = key.toString();
if (serviceName != null && serviceName.length() > 0 && !map.containsKey(serviceName)) {
try {
DailyRollingFileAppender dailyRollingFileAppender = new DailyRollingFileAppender(layout, fileName + "." + serviceName, getDatePattern());
map.put(serviceName, dailyRollingFileAppender);
} catch (IOException e) {
}
}
DailyRollingFileAppender ap = (DailyRollingFileAppender) map.get(serviceName);
if (ap != null)
ap.doAppend(event);
else
super.append(event);
}
@Override
public void close() {
for (Iterator iter = map.values().iterator(); iter.hasNext();) {
DailyRollingFileAppender appender = (DailyRollingFileAppender) iter.next();
appender.close();
}
super.close();
}
public void setMdcName(String mdcName) {
this.mdcName = mdcName;
}
public String getMdcName() {
return mdcName;
}
}
That was all!
I started a toy project just to give Grails a try and want to share the project setup, and other steps. I were really impressed by the demo applications: painless, easy startup and CRUD applications, but yes a bit too late but I were really busy at my new job, and also trying to get used to my new country, and of course I admit that I am a bit lazy too 
After reading the Getting Started with Grails free booklet, and well prepared Grails Documentation I started playing with it
more…
The books we ordered have just arrived: great gifts for the new year
I will start with classic book of software engineering – The Mythical Man-Month: Essays on Software Engineering first which was first published in 1975 by Fred Brooks. This anniversary edition includes four new chapters and I really wonder about the evolution of software engineering and the human factor in the past 33 years. I can’t wait especially for the legendary The Mythical-Man Month and No Silver Bullet essays.
more…
We started to work on some projects, and after getting the source code, we could not use the web projects in eclipse because they were not defined as Eclipse Dynamic Web projects. Here is a small trick to convert these general projects to Dynamic Web projects.
more…

I upgraded my blog to WordPress 2.7 Beta 3 and i am very impressed at first sight
Also with very nice plugins like Zemanta and Organize Series blogging is really a pleasure, thanks to them.
You can also upgrade your WordPress if you do not like installing your plugins every time by ftp, instead of manual install you can easily install/upgrade your plugins just like Firefox
more…
After a very long time, i just returned to blogging and of course i have lot’s of things to tell
We just moved to Amsterdam, as expats and i changed my job, and to be honest it is a busy one, i work as Software Engineer at a bank… I do not know why but as far as i know banks are really busy and unfortunately stressful compared to the software development jobs in other sectors.
I would appreciate if you can comment if i have the wrong impression but this is my third banking experience and all the issues are fatal, all the problems & solutions are so urgent and all the deadlines are so close, generally because of the legal obligations…
Amsterdam, if you have not visited yet is a nice city to live and travel… Wish me luck at this fresh start
I also have a new personal blog for sharing my experiences about Amsterdam&Netherlands, but this one is in Turkish, my native language
I migrated Eclipse 3.2 to 3.3.1, at first I used the same workspace and I had some problems with myln plugins and the server did not start correctly. Then i tried with a new workspace and everything was smooth except at server startup:
Timeout waiting for Tomcat v5.5 Server at localhost to start. Server did not start after 45s.
You need to set server timeout delay = Unlimited from Window>Preferences>Server…
I needed to merge the branch changes into trunk of the project, after many changes at both the branch and trunk…
First we have to commit all changes, in case of some failure at the merge operation we may revert all changes.
Select from menu, select the path of the branch and the revision. Revision number is selected from the Show Log, and is number when we created the branch.

Some useful links for SVN merge:
Eclipse SDK – Subversion Eclipse Plugin Manual
SVN Book
I tried Maven plugins for code analysis and finding duplicate/similar code.
CPD-PMD’s Copy/Paste Detector can be used for finding duplicate code, which is included in PMD, a Java code analysis tool.
run mvn pmd:cpd ,
The report is displayed at cpd.html file, and the results are very efficient.
Simian – Similarity Analyser is also an alternative for finding duplicates.
We started code review using Crucible, so i searched for some code analysis maven plugins. PMD is a Java code analysis tool and used to find potential problems like unused code, duplicate code, unused variables… PMD is useful and easy:
pom.xml:
<reporting>
<outputdirectory>target/reporting/pmd</outputdirectory>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-pmd-plugin</artifactid>
</plugin>
</plugins>
</reporting>
more…