Reputation: 69707
Logging can get complicated, quickly. Considering that you have some code, how do you add logging to it? What library(ies) do you use?
What are some good code techniques for getting the most out of your logging statements while having minimal impact on your application?
Upvotes: 6
Views: 1754
Reputation: 376
There are few things to consider when you decide your logging philosophy to make it performance conscious. First let us breakdown the resources spent on logging.
Following are the things that you can do to minimize the above.
Upvotes: 0
Reputation: 3287
Some aspects I would like to add about logging practices.
Upvotes: 0
Reputation: 10475
There has been quite some discussion on this in other questions. If you a C# man take a look at What is the best logging solution for a c# net 3.5 project or What’s your logging philosophy?
Search for Logging and you will find many more. :)
Upvotes: 2
Reputation: 89232
Libraries: Log4J and Log4Net (for Java and .NET respectively)
From Log4J site:
Inserting log statements into your code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.
On the other hand, some people argue that log statements pollute source code and decrease legibility. (We believe that the contrary is true). In the Java language where a preprocessor is not available, log statements increase the size of the code and reduce its speed, even when logging is turned off. Given that a reasonably sized application may contain thousands of log statements, speed is of particular importance.
With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.
Logging equips the developer with detailed context for application failures. On the other hand, testing provides quality assurance and confidence in the application. Logging and testing should not be confused. They are complementary. When logging is wisely used, it can prove to be an essential tool.
Upvotes: 3