The Problem with Advice

Posted by wsargent Thu, 27 Sep 2007 07:21:00 GMT

The novice comes in to the monastery and says “I really want to be a monk. What is it you do at one of your sesshins?”
The monk thinks about it and says “I sit on a cushion and I stare at a wall. Oh, and I breathe.”
The novice says “Okay, I’ll do that. How do I do that, exactly?”
The monk gets him a cushion to sit on, and tells him “Now breathe.”
The kettle whistles and the monk leaves the room to take it off the heat.
The monk comes back in a minute later, and looks at the novice.
The novice looks frantic. The monk sighs.
“Breathe out. Once you’ve finished breathing out, breathe in again. Keep doing that.”

Biking Lessons 1

Posted by wsargent Mon, 24 Sep 2007 17:06:00 GMT

Today I learnt that human beings cannot fly. At least, not for very long.

Also, Sports Basement does not sell Neosporin.

Environment specific settings for Log4J 1

Posted by wsargent Tue, 04 Sep 2007 05:59:00 GMT

Finally scratched a long standing itch today and wrote something to break up Log4J configuration and enable parameter substitution. You can download it here: layered-configurator.zip

LayeredConfigurator will go through a properties files with references to DOM or Property configurator references (files or URLs), and will call the appropriate configurator in the order they are defined.

This doesn’t mean much in theory, so let’s explain why this package exists, and give an example.

Log4J lacks a way to spread configuration over several files. You have one configuration file, either log4j.properties or log4j.xml, and that’s it.

In projects where you have several environments to keep track of, you may want to have some loggers set to DEBUG in the development environment, but set to WARN on the production environment. However, you usually want to keep all the appenders and logging infrastructure the same.

Because Log4J defines appenders and loggers in the same file, you either have to define several almost identical files with the appropriate changes for the environment, or you have to have an Ant script that goes through and replaces tokens for the appropriate environment.

The file syntax for the configurators is simple. Here’s an example log4j-config.properties file:

# The complicated appenders are rendered in XML.
base-appenders.xml

# The logging levels can be defined in properties, and can use system properties
# as parameters. (in this case we assume -Dmy.environment=dev is defined)
${my.environment}-loggers.properties

The class is called LayeredConfigurator because it’s meant to work in layers. The configurators are not reset, so all the settings from the previous configurator will still apply unless you override them.

When you define -Dmy.environment=dev, then your development settings will be loaded. When you define -Dmy.environment=prod, then your production settings will be loaded. Either way, your binary distribution is exactly the same, with only the environment specific properties

To enable this class, you must start the JVM with the following system properties:

 -Dlog4j.configuratorClass=com.tersesystems.log4j.LayeredConfigurator
 -Dlog4j.configuration=log4j-config.properties

And that’s it. Pretty simple solution for something that’s bugged me for at least three years now.