« Older Home
Loading Newer »

Log4J on websphere using Commons Logging interface without child first class loading

Ok, so this was a challenging problem.

You’ve probably read that websphere uses commons logging, and because the app server class loader loads JDK logging prior to loading your app, your app will by default load with JDK logging and you are unable to configure it.

First of all, please oh please if at all possible use the far superior solution of developing your app with child first class loading. It’ll solve so many of your problems you’ll be surprised.

Sometimes however this isn’t an option. Particularly when working with large existing code bases without the resources to re-test the entire application.

That was our scenario, and the problem was having some classes outputting masses of serialised data, which is important for us to record and have available, but is not something we want alongside all the rest of our programs output.

The solution ended up being to use PropertyConfigurator.configure(Properties), passing in the following properties:

# Set root logger level to INFO and its only appender to CONSOLE.
log4j.rootLogger=INFO, CONSOLElog4j.logger.one.of.the.big.OutputterClass=DEBUG, FILE
log4j.additivity.one.of.the.big.OutputterClass=falselog4j.logger.another.big.OutputClass=DEBUG, FILE
log4j.additivity.another.big.OutputClass=false

# ConsoleAppender.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

#RollingFileAppender
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.append=true
log4j.appender.FILE.MaxFileSize=1000KB
log4j.appender.FILE.MaxBackupIndex=5
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

We performed this configuration in one of our classes that was initialised when the web app loaded. From that point on any loggers obtained from LogFactory are log4j loggers. The file output for the logger we programmatically generated as it’ll vary from deployment to deployment and will require correct permissions.

Cute Peas patched

Ok, a patch to cute peas that gets the game in a far more playable state (in my opinion).

I may be taking another break from cute peas for a while as I’ve taken on a side project at work for the google app engine, and I’ve been told there’s limited time to play around with it before the deal changes.

I also plan on starting up a new role play campaign which will suck a lot of time

cute peas alpha released

head on over to the google code project to check out the first executable of my latest pride and joy!  Please be kind, my ego is fragile

almost functional java

This would be nicer with closers (I hope). I got the idea from spending some time working with pythons list comprehensions which I really like

public static interface StringConverter
{
String convertToString(T o);
}

public static  String getTokenSeparatedValuesFromList(final Collection list, final StringConverter converter, final String token)
{
final StringBuffer result = new StringBuffer();
for(Iterator it = list.iterator(); it.hasNext();)
{
result.append(converter.convertToString(it.next()));
if(it.hasNext())
{
result.append(token);
}
}
return result.toString();
}

So say I’ve got a lot of bins, and I want to make a comma separated list out of their contents?

getTokenSeparatedValuesFromList(appleBins,
new StringConverter(){public String convertToString(AppleBin bin)
{
return String.valueOf(bin.getNumberOfApples());
}}, ", ");

Now say I’ve got a list of kids and I want to build a column of their names and ages:

getTokenSeparatedValuesFromList(children,
new StringConverter(){public String convertToString(Child child)
{
return child.getName() + " " + child.getAge();
}}, ", ");

I wonder if anyone’s implemented map and reduce for java and I wonder if it’s at all usable…

Don’t write javascript without a debugger

I’ve been doing a fair bit of helping people on the team out with their client side javascript lately, and I’ve found that the thing that helps them the most is getting them to install firebug or venkman and play around with the code in a real developers tool.

I think most people who really dislike javascript have stopped thinking of it as a programming language.  When they get a problem in Java, they follow some good practices to isolate the problem, work out where the code is doing, what is in which scope etc, however with javascript people by default seem to have this “it’s magic” mind set which prevents them from approaching their problems rationally.

Once they’re able to see the code in a debugger, and look at the DOM in a visualized way people seem to start making the connection between xhtml elements in their jsp’s and the DOM objects in the javascript memory space, and start thinking about the problem at the right level of abstraction.  It’s really rewarding sometimes to see how much they turn around on their anti javascript sentiments.

DB Unit

DB Unit is a framework to assist with your unit tests.

At work we were finding we had a lot of trouble maintaining an integration test database. Storing a dump file was no good for version control, writing code to create and insert data for every test was an option but a fair bit of work, DB Unit however seems to have solved most of our problems, it’ll pick up an XML file at the start of our test, insert the rows straight to the DB from there, run the test, delete the rows.

There have been a few minor problems with it, timestamps lose the time, dd-mm-yyyy only, there doesn’t appear to be any way of specifying blob fields in the xml, however these we can work around.

A more major problem we’ve just run into is that you can’t use the DELETE operation on tables which don’t have primary keys. I can see the reasoning for this, there’s no way for it to ensure that it’s only deleting from the dataset if it doesn’t have an identifier, however our system has a lot of many-many tables which don’t have primary keys.

I realize that it’d work if we put composite keys on those tables, but that solution meets a bit of resistance. The only alternative I can see is to extend the framework to delete using a complete comparison where there’s no primary key instead of throwing an exception.

Unfortunately that leaves us a few glaring (albeit low risk) holes in the tests where if there’s duplicates we could stuff up our dev databases (we don’t necessarily clear before running integration tests) and if the test itself changes the data then it wouldn’t be deleted leaving ugly artifacts… Actually scratch that last one, none of our integration tests commit their transactions.

The first one is also a risk with primary keys as there could be key collisions, however we’d get an exception straight up saying primary key collision rather than unexplained failures later on, which is vastly better…

Hmm, I think I’m going to have to argue for adding more primary keys to our database

cute peas

I’ve started up another gaming project at http://code.google.com/p/cutepeas

I know I haven’t finished cutegod yet, but this one looks a lot easier, and I’ve got friends who might actually work on it, so I’ll probably finish cute peas and then go back to cutegod meets the Ogre

When Cubes BOUNCE

I posted not so long ago about my latest crack at the cuteGod prototype challenge.

Progress has been fairly slow given the 1 hour a day two days a week time commitment, however I can finally see the first minor release on the horizon.

I am starting to get excited about the project, it’s becoming fun to play around with as I develop and I’ve started to have some clear inspirations for future features.  I’ll probably spend some of my spare time today writing them up on the project’s wiki

Linux at work

I’m very happy today, for a number of reasons. A very large part of my mood is directly attributable to finishing my most recent project and getting some “free time” at the HQ.

The free time is extra great because they allow me to plug in my personal laptop here, running linux and have more or less unrestricted internet access.

So, apart from the boring work stuff like preparing presentations, chasing the next project and meetings, I’ve been tinkering around with my Ubuntu boot on my laptop. Here’s the results

  1. I finally got multiple monitors pretty close to how I want them. I had a lot of trouble with the desktop resolution being higher than the screens resolution which results in horribly disorienting scrolling to see the whole desk space. Here is the guide that helped me with that.
  2. I set up pidgin as my messaging client, it does google talk as well as msn, and has a non cluttered interface which is ALL I want my client to do (and nothing else)
  3. I got Evolution working with works exchange server, as well as my google mail and callendars. This last one is really neat, I’ve got completely disparate content providers being aggregated to the one interface, no more jumping all over the place to check my communications/schedules

So most of that is pretty cool. Probably one or two hours of tinkering around and looking at things, looks like linux has come a long way.

For posterity

Stolen from a Slashdot Comment, this held my interest briefly

Actually, it’s not the attempt to mathify that I find problematic—I find that encouraging. It is, though, the results.My (awesome) university philosophy professor had us do a very interesting exercise that was, though more logical than mathematical in nature, similar to what the author of TFA was going for. It goes like this…Write down a belief that you have. For people new to this process (the entire class), this should be a strongly held belief…doesn’t matter how controversial. Let’s say, for example: I think abortion should be a woman’s choice. (For you controversy-hounds out there, please don’t mistake this for my actual belief—I’m intentionally not going to define my actual belief on this topic here.) Don’t worry about getting the wording just right—you’re free to revisit your initial statement as many times as you like throughout and revise it to more concisely represent your intent.

Now write down the set of “sub-beliefs” that you have which form the basis of your belief. For our example: 1. Life begins at conception. 2. Every life is equally valuable. 3. A life has no quantifiable value, but is inherently precious and ought to be protected if at all possible. Etc. Next we iterate, applying the same process to each belief listed. Obviously, you will very quickly diverge into an explosion of statements that resist corralling at every effort. Do not fret—I haven’t told you about the thrust of the exercise yet.

(I should mention here that we did an entire section on identifying context-free statements, and we were asked to make our best effort to ensure that each statement was context-free, or as free of context as possible. “Context-free” means that the statement is true of our beliefs regardless of the circumstances in which the statement is tested. If that’s not possible—and it’s not often possible—we’d go for “generally” true, where “common sense”—whatever that is—dictates obvious exceptions.)

You will find it unnecessary to list each and every belief supporting your initial statement, which would quite likely fill several thick volumes if you did so exhaustively. Luckily, you don’t have to do this to satisfy the point of the exercise, which is: where necessary, skip down to “lowest level” beliefs…that is, at some point you will mentally reach a point where you have identified a belief for which you have no further basis beliefs. When you reach this point, you have identified an axiomatic belief—that is, something you accept essentially on faith, on gut feeling, because you think it is correct. If possible, identify the key beliefs that go from your initial statement to the set of axiomatic beliefs identified.

The next step is to look at your beliefs, both axiomatic and intermediate, for consistency. In every case in carrying out this exercise, one will invariably find a whole host of contradictory statements. Then we did an iteration that attempts to resolve these conflicts by tweaking our initial statement, etc…provided we were tuning up the language to indicate real intent and not moving the statements further away from our actual beliefs, great. The ultimate idea is to identify our beliefs in all their gory, inconsistent, warty detail.

Then, we make up a list of so-called axiomatic beliefs and they are given to 5 random classmates (all double-blind, of course). You then are tasked with taking home those 5 lists of axiomatic beliefs and attempt to drill down further. If they are truly axiomatic, you won’t be able to do this—the idea here is that you ultimately get back 5 people’s analysis of your list and given another chance to continue the process—most of the time, it turns out you realize your axiomatic beliefs weren’t axiomatic for you after all, and that you can actually drill down even more.

Anyway, it goes on like this, the ultimate point being that you arrive at some network of beliefs which you apparently do accept as axiomatic. The focus here is not on the logic that leads you down the path from the initial statement to the final list…the point is to show that your beliefs are not rigorously logical, even after you’ve done your level best to identify all the logical flaws, ultimately you wind up with a list of axiomatic beliefs that either directly or indirectly contradict each other to some extent. What these beliefs are, where the conflicts are, and how you resolve these conflicts all roughly correspond to your worldview.

As an entertaining add-on at the end of the course, the prof provided us with some very mild statistical metrics that told us how self-contradictory our beliefs were when pegged against our classmates, previous years, different types of statements (it was generally true that the more strongly held / the more controversial the statement, such as the abortion example above, the less self-consistent the foundational beliefs identified).

For a couple of years after doing this exercise, I found it very difficult to make strong statements of opinion about controversial topics. My mind would involuntarily start this process, identifying all the biggest logical hurdles and inconsistencies built into the statements I was about to make. This reflex also made me annoying to others with strongly held beliefs. :-)


MeeboMe

Posts

July 2008
M T W T F S S
« Jun    
 123456
78910111213
14151617181920
21222324252627
28293031  

categories