Back when I was still writing a lot of Win32 apps in Delphi, one of my favorite tools was Smart Inspect, a very nice logging tool that also ships with Java und .NET libraries. Unfortunately, I never got to use it that much, since shortly after I bought it I started to drift more and more into web development.
So, three days ago, I had the sudden impulse to take a break from my regular projects and write a Python client library. Just for fun, mostly, but I can see some opportunities in the future where it might come in handy. I wasn’t expecting that it would take three days either, but some of the final bugs in the end took some time to iron out.
I should also note that:
- It’s a pretty direct port of the Delphi implementation, and thus not as pythonic as it could be, though I took some liberties where it seemed to make a lot of sense. Most significantly, the identifier names were converted to Python style guidelines (using underscores in method names).
- It isn’t complete, either. Apart from some minor stuff, the big things missing are the file and text protocols – I plan to add those at some point later on. Only the TCP and memory protocols are supported right now.
Here are some random examples – more in the readme and test files:
>>> from smartinspect.auto import * >>> si.enabled = True >>> si.log_debug("hello world!")
Manual initialization, without using the smartinspect.auto module:
>>> from smartinspect import * >>> si = SmartInspect("myapp") >>> si.connections = "tcp(port=4444, timeout=10)" >>> si.enabled = True >>> logger = si.add_session("main") >>> logger.log_debug("hello world!")
Manually logging process flow:
>>> def append(self, obj): >>> logger.enter_method("append", self) >>> try: >>> pass # so something >>> finally: >>> logger.leave_method("append", self)
Logging process flow using the decorator:
>>> @logger.track >>> def append(self, obj): >>> pass # so something
Download: smartinspect.zip
Looks quite interesting. Have you given any thought to extending this to be a plug-in handler for the standard Python logging module? That’d make it much easier for existing applications to start using this.
LikeLike
Jason, yes, I believe I even listed that somewhere as a TODO. Note sure if or when I’ll find the time of course, but it might be something I am going to need/want at some point myself.
LikeLike