Using own log4j file on JBoss 5.0.1 Enterprise

This took me some time to figure out. The task should be a small one, but quickly got somewhat  complicated.

I wanted to separate the log4j configuration for my webapps from JBoss’ own configuration when using log4j. When webapplications all share the same server.log instead of having a log file of their own, it quickly gets crowded. There are two ways of avoiding this.

The first option is to add appenders to jboss-log4j.xml in jboss-as/server/default and to create a chain of filters in FILE. This option is described here. I almost got this approach to work, but then JBoss support told me about a small overhead. The overhead isn’t significant at first, but it will get bigger as more webapplication are added to jboss-log4j.xml. So I decided to not use this approach.

The second option is what worked. The option is slightly more complicated, but with no overhead. It is described in detail here.

But all was not well when I tried the second option. Following the to-do I got a java.io.FileNotFoundException when the application was deployed. Apparently the xml parser in AppRepositorySelector couldn’t find the log4j.dtd. No wonder. It looked in a path relative to JBoss’ bin directory and not in the classpath resources for the dtd.

Terra Java made his own entity resolver to solve the path problem, but actually there’s already an entity resolver in log4j (quite handy that). So after changing this in AppRepositorySelector:

Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(log4JConfig);

into this:

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.setEntityResolver(new Log4jEntityResolver());
Document doc = builder.parse(log4JConfig);

I got it fixed. And now logging works as specified in the application’s own, local log4j.xml configuration.

Akut?

Ordet akut betyder heftig eller pludselig opstående og dets modsætning er ordet kronisk. Det er ihvertfald, hvad Dansk Fremmedordbog mener. Herning Hospital er slet ikke enig.

Søndag aften slog Amanda, som er min 12-årige datter, en tand ud. Min kone og jeg hørte faldet og gråden, og vi fandt Amanda siddende i armene på Cathrine, som er hendes søster. Amanda  blødte meget, og hun var meget chokeret. Hendes tand, den ene fortand, lå på gulvet ved siden af. Næsten ligeså chokeret ringede min kone til lægevagten på Herning Sygehus, og jeg fandt en kold klud for at standse blødningen. Efter en hurtig tur til Herning blev Amanda tilset af en læge. Det skete uden ventetid. Lægen kunne ikke gøre andet end at sætte tanden op, så godt han kunne – og så sendte han os videre til skadestuen. Da var klokken cirka 21.15

Nu forventede jeg, at Amanda blev sendt til en røntgen-undersøgelse og kigget på af en tandlæge. Sådan gik det imidlertid ikke. Skadestuens personale tilbød Amanda en Panodil – og så ventede vi. Efter en tid tilbød jeg min hjælp – vi kunne da køre til en anden skadestue, hvor der måske var en tandlæge? – men personalet informerede os om, at de skam havde en aftale med en tandlæge, og at vi selv skulle betale, hvis vi fandt en anden tandlæge. Således beroliget – nogen var i gang med at finde tandlægen – ventede vi igen. I mere end 4 timer. Da klokken var cirka 02.00 blev Amanda så tilset af endnu en læge. Som godt kunne se problemet, men som heller ikke rigtigt kunne gøre noget ved det. Men han kunne da godt ringe til skadestuen i Århus.

Skadestuen i Århus reagerede helt anderledes. De ville se os så hurtigt som muligt. Akut. Og efter en hurtig køretur til Århus Universitetshospital kom Amanda endelig i kyndige hænder på afdelingen for tand-, mund- og kæbekirurgi. Her kunne en kæbekirurg sætte tanden helt på plads og sikre den. Behandlingen startede ifølge journalen klokken 03.30 og varede en time.

Nu ved jeg godt, at vi har en økonomisk krise, og at vi skal spare på de offentlige budgetter. Men jeg ved også, at et samfund kan måles på, hvordan det behandler sine svageste. Og jeg ved, at ingen økonomiske kalkuler kan forsvare, at en lille pige venter tappert i mere end 6 timer på at få hjælp for en tand, der er slået ud. Det er uanstændigt, det er skammeligt – og det er ihvertfald ikke akut.

JBoss remote debugging

Just wanted to setup JBoss for remote debugging using Eclipse. Turns out that remote debugging is quite simple, but I’ll have forgotten the specifics tomorrow, so I’d better jot down a quick note.

In JBoss bin/run.sh there’s a few references to JAVA_OPS. Find the one that looks like this:

# Setup JBoss specific properties
JAVA_OPTS="-Dprogram.name=$PROGNAME $JAVA_OPTS"

- and add the line below:

JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

This addition to JAVA_OPTS lets JBoss start in debug mode with no suspend during startup.

To enable Eclipse to do remote debug after JBoss startup, click run > debug configurations and select Remote Java Application. Fill in host and port – in the example the host is localhost and the port is 8787.

Now JBoss is ready to deploy your web-application with breakpoints.

Globalization

Andy Grove, senior advisor of Intel, asks an excellent question:

You could say, as many do, that shipping jobs overseas is no big deal because the high-value work — and much of the profits — remain in the U.S. That may well be so. But what kind of a society are we going to have if it consists of highly paid people doing high-value-added work — and masses of unemployed?

It seems like an understatement to say that the answers to this question – and what we all chose to do about it – is what the next decade will be all about…