Friday, December 28, 2007

Python - log viewer

I am as such a newbie to Python. I arrived at python after looking at all the other languages and I was totally impressed with ease of python and its power. Python is well designed for beginners. So if you are new into programming, I think you should start with python right away.

Python is also object oriented, which means you can scale to current day requirements and also scale up very easily in future.

It has rich collection of modules, which makes most of your development fairly easy.

I did a bit of research before I arrived into Python. My background has been implementation/ consultancy in Banking and my experience has been or rather my bread has been universe initially and then jbase because the product I was working with adapted to jbase. Programming is called infobasic or jbc. It is quite a self-sufficient language for any activities. I think only thing missing in that is the object orientation other than that we can do most of the stuff there. Ofcourse they miss modules for networking (other things) and are quite slow for large amount of data. jbase/jbc is quite extend able in its own sense, because you can call 'c' function quite easily from jbase or viceversa.

Ok Back to how I arrived at Python. I was looking for new languages (rather more powerful and faster) to equip myself and my team and I evaluated few,

1. c++ - too complicated for me
2. perl - i didnt like it.
3. c - no object orientation

then i was left with java and python. Java is quite power full and eventually I think every programmer has to arrive at java. But writing a small programs or quick utility is bleady time consuming (probably not for those java geeks!!). I felt next natural progression from jbc/info basic should be to Python. I have been dealing with lots of T24 consultants, they are so comfortable with jbc that they choke when it comes to latest languages like java or c++ or c#. These consultants are high in demand and low in technical knowledge in true market sense (ofcourse, other than product (read as t24) and jbc).

I observe that when ever I wanted to do new products with new technology(with my team of t24 consultants - i had eventually recruit new people) there was so much resistance (from the so called technical architects/ experts{of t24}) that either people quit my team or my company. They are so comfortably placed with the current demand in their knowledge that they are not willing to spend time to learn new technologies and if u ask them to look into java or c++ or any thing else then my utilisation of these people becomes really low(as time required to be expert in these languages are quite high). So I strongly feel answer to all this and taking a route of natural progression, obvious next step for info basic programmers(rather t24 consultants) should be to python and then eventually they could arrive at Java or which ever(not a very big fan for windows languages-except c# {looks interesting}).


I have started using python for writing small utilities for my day to day activities. During my recent visit to one of the t24 sites, the client wanted(rather I wanted) a utility to view the como created by the t24 cob process in a single window. t24 allows cob to be run in multiple threads and the logging (or COMO) is stored AS 'n' number of files(Where 'n' is number of threads).


So I did the following program to view the same. The lazy that I am, I did the first search for available program with Google God!!. I eventually found what I was looking for at

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414771

I modified that to my requirements. The code is at following location as text file to maintain the indentation(yeah sometimes it is irritating),

comoviewer source




The code does the following,

1. takes directory to be monitored for log files
2. scan through all the files in the directory with the name starting with tSA
3. get the number of lines and stores them in a dictionary
4. scans the next time and checks whether the previous lines is less then the current number of lines in the file, if so then display them.

example of usage

python comoviewer.py /hds2/temp/bnk/bnk.run/'&COMO&'


Ofcourse if you want to use this you need to install python first.

No comments: