Archive for the ‘Python’ Category

It’s a bird, it’s a plane, it’s a python?

by on Friday, September 9th, 2011

Introductions Are In Order

Sometimes at work I have the need to get distracted. You can only work on the some programs so much before you just want to tear it to little bits and start it over from scratch (programming rule #4). So in order to combat this impulse I find little side programs I can create that I can somewhat realistically say is work related. That’s my story and I’m sticking to it! This one involves an experiment in the wonderful language of Python. It’s a fun language, in my opinion. Very powerful and flexible. It takes a little bit of getting used to, but it’s my scripting language of choice. But watch out, it’s pooooiisssoonnous.

We were using Apache Solr on a project (which I lurve) but had some constraints adjusting the log level. We’d typically see a gig or so a day of log traffic that we really didn’t need. Solr uses SLF4J logging. It’s a handy packing that abstracts the logging calls, and you instead provide another library that has the actual implementation. AFAIK there is only JDK and Log4j implementations, but I haven’t really looked. By default, the logging library provided is JDK which is all well and good. JDK logging relies on the container to control what is being logged and where. The problem was, we use Weblogic :( Not that I have a whole lot against Weblogic, but in order to hook into its logging mechanism, the implementation needs to extend the commons logging API that Weblogic provides. We could have gone Log4j, but didn’t really have the bandwidth to spare. Or more acurately, since the project was being transitioned off, we didn’t have the ability to make code changes.

Enter the python (it’s like a baby dragon or something). Solr comes with a very nice logging console where, at runtime, you can tweak log levels. It only affects JDK logging (conveniently) and gets reset with a server bounce (which happens regularly). So I came up with the program concept to use a script set these levels somehow. I took a look at the server, and lo and behold (for fun go look up the definition of lo) there was a python staring right at me. So I told my co-workers to move slowly, they’re not poisonous, but can constrict you to death with powerful squeezes. After a few turns, and a lucky critical, we took care of the python. I returned to my search and found that the server had python installed and available for use. I had my language of choice and started looking at what I could do. The result? A pretty nifty command line utility that can submit a Web form with parameters of your own design. It’s so good, it has almost completely overflowed the good and rolled over to evil. Luckily we use unsigned values here. Take that evil!