February 23, 2009
About Log Files: Part 2Multithreaded Logging
Multithreaded applications need some additional handling for log files. Specifically two problems have to be addressed:
In general, it isn't a good idea to log separate threads to separate log files. The most difficult problems arise from thread synchronization. These problems can be found when all actions are written to one file; see Listing Two.
CRITICAL_SECTION gLoggingMutex;
Listing Two: Multithreaded Logging Function
Logging Multi-tier Applications
Applications that are spread across several modules, components, or even machines add a level of complexity that makes it much more difficult to find bugs. Log files can help here too, but using them gets harder too. For instance, you may think about writing a centralized log server application that all components use. Such an application would do nothing but collect all log statements from all modules and synchronize and stream them to file. This has the advantage that only one log file at a time is used. But such a server adds problems: It is a active component itself and may lead to behaviors different from that without such a server. Moreover such a server will not be practically possible in many cases. Having said that, sometimes a log server might be a good idea.
Without a logging server, you are confronted with the problem of more than a single log file at a time. It's very important here to frequently synchronize the system time of all machines, but an offset of a single or some seconds will usually remain. Still, working with a number of log files at a time is a tedious task.
In general it's best, if each module can log all needed information locally by itself, and if the need to analyze across modules is only a rare event. Applications and also modules shall always either success (with or without notice) or fail with more or less detailed notification of the cause to do so, but we are coming away from log files onwards to architecture here.
Conclusion
Even in the most difficult situations such as with large datasets or very rarely occurring problems log files can help you more than every other tool. They are also useful in modern environments such as multi threaded and multi tiered application. But still log files are the most simple technique at all. So in short, every program should write a log file. Log files will save hours and sometimes days. Period.
|
|
||||||||||||||||||||||||||||||
|
|
|
|