How can I write to the previous line in a log file using Python's Logging module? -


Lurker for a long time, finally emerging from wood.

Basically, what I'm trying to do is to write my logger to the logfile like this:

  Connecting to the database. . done.  

I need to 'connect to database'. . The function should be written after calling, and 'Done' written after the function has been successfully executed.

I am using Python 2.6 and logging modules. Apart from this, I really want to avoid using decorators for this. Any help would be most appreciated!

write a log, and should, atom action - this is important , And a key feature of any logging package (which is in a Python's standard library) which separates the information from being easily added to files (where bits of things are being written by different processes and threads are well "Punching" - write a part of one of these lines, l Not until the end of the line, as you wish, and then perhaps someone else joins the person later, what he thinks before writing the work ends on the other line in fact on the last part of the line. Full delusion often results in; -).

It is not mandatory that the nuclear unit "one line" (logs can be recorded from elsewhere in a text file, of course, and some things that are "sync" acceptable for logs, They will not even be the concept of "one line"!), But for logging, the atomic units should be there if you want some non-atom, then you are actually logging Do not want to, but in a file or other stream Ral (and, for the delusion described in the first paragraph ;-))

For a momentary update about what your task is doing (between X, X, Y start, etc.), you can think of a special log-loader (example For the first words, explains such sections of the update, a subatus-identifier (the subcategory-identifier (improving the formation and displaying the overall message about "the whole composite" elsewhere), while recognizing the sub- No Less identifier changes, the previous subtask takes Done or clear "Sbtask finished" message ends, and only writes the entries continually log Sbtask-Occurring end).

This is a very special requirement, so you can not find a pre-built tool for it, but you have to do your own roll. To help you with it, it is important to understand what you are trying to achieve (if you want do non-atomic logging entries, if such a concept has any meaning - Are the deployment or system administration work trying to improve using such imaginary tools?) So that special subsidies can be prepared according to your actual needs. So can you please expand on this?


Comments