2

Ok, it's a little hard to describe my problem, I will try as much as possible to explain it simply.

When my application starts up, it creates Logger from logging lib. Before loading configuration file, the only handler for logger is stdout.

After several printed logs, application finally loads configuration file which include Logger configuration options, such as file for store logs. I modify my Logger options to use file handler for this file, simultaneously with stdout handler. But i need to store all previous logs generated by my script in this file, using formatting from configuration. I was thinking about MemoryHandler, running simultaneously with stdout handler, and after loading configuration write all logs from memory to file - before creating a file handler.

The problem is that MemoryHandler is not well documented, and this way to solve the problem is not pretty looks for me. So, in brief - I looking for way to save log into file from MemoryHandler, or better way to solve this problem.

Galmi
  • 743
  • 1
  • 11
  • 18
  • 1
    DIfficult to provide a useful answer without seeing your code. I would suggest you try to load the config and configure the logger first, before doing anything else. – Rob Cowie May 21 '11 at 12:45
  • why can't the app load logger earlier on? – ashwoods May 21 '11 at 12:46
  • Because the application does not just load the configuration file. First, i use YAML files for configuration. These files must be parsed and checked if not contains syntax errors. Seconds, after load YAML file and convert into dictionary, i validate that dict, check if every item have correct value type etc. Third, just before settings up logger, i make full test on every important item in this dictionary - checks if given paths exist and is writable, checks if database setup is correct etc. Then i set up logger and else things. During this entire process, I want to print msg about progress. – Galmi May 21 '11 at 12:59
  • There will always be some part of the script that executes before the logger is set up. The logger is usually the first thing configured after loading the config file. Unders most circumstances this is not a problem as it isn't useful to log any failure during loading of the conf file. I would suggest re-arranging your code; Load the conf file (presumably with pyyaml?), then set up the logger, then check your config values and log as required. – Rob Cowie May 22 '11 at 12:14
  • What's lacking in MemoryHandler's documentation? It's a very simple handler, so there's not much to document. There are examples of its use on the Web, e.g. http://stackoverflow.com/questions/1610845/how-to-collate-output-in-python-logging-memoryhandler-smtphandler and http://nullege.com/codes/search/logging.handlers.MemoryHandler – Vinay Sajip May 29 '11 at 22:46

0 Answers0