0

Programs always generates large volumes of log for trouble shooting. My question is when should programmers use log. For example, when the status changes, a log should be print; or log should be called when calling a function or returning from a function indicates the calling stack.

1 Answers1

0

There are no rules, only best practices.

In general, you want to be able to dump out as much information as possible should the need ever arise for you to debug some strange piece of code. This may also be after the fact you've gone to production, so you may not have a chance to change the code to see what's going on. Good logging statements would contain sufficient enough information to know what part of the stack you are on without printing the stack every line.

Logging is normally done at several levels (eg. trace, debug, minimal) to give the admin/developer the ability to turn up or down logging to see more or less information. It should be agreed among development what is a proper type of log message for each level.

Logging is not the same as auditing, and shouldn't normally be read by anyone other than development, administrators, or support teams.

ergonaut
  • 6,929
  • 1
  • 17
  • 47