Logging in Python
I’ve been using log4j for a long time, but never got into Python’s logging module. But last week I was sitting in a class about logging and my company’s new standard and toolset. The instructor kept giving Python as an example (as well as log4j) of a logging system that worked with our logging repository. During a break, I asked the instructor if there was a pocket of Python users in the company. Alas he said no, but he used it as an example of something that used the same logging standard as log4j and other Java logging utilities.
Later in the week, I was faced with a problem that needed to be solved with a Python script. I thought to myself, “Why not use Python’s logging?” I did, and it was good. Very good.
I could give examples, etc. on it, but I really don’t need to — the documentation is quite good by itself. But I didn’t see a concrete example on how to get the function name into the log message, so here is my example, as simple as it is:
def saveXml(xml):log = logging.getLogger("saveXml")