| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Logging Standards

Page history last edited by Manuel Kueblboeck 14 years, 7 months ago
  • Use TRACE only for tracing execution flow

    In general, trace-level logging should be used only for tracing the flow of execution through a program and for flagging particular positions in a program (i.e. to ensure they have been reached). While you may want to trace every method of a class in early stages of development, you should ensure that you are only tracing key aspects of the flow when it is time to pass the code onto other developers. An overabundance of TRACE statements (especially in simple getter and setter methods) can hinder others rather than help them.

  • Use DEBUG to report results to yourself and other developers
  • Use INFO to report results to Administrators and Users
  • Use Guarded Logging

    "Guarded logging" is a pattern that checks to see if a log statement will result in output before it is executed. Since the logger itself makes this check, it may seem redundant to do this for every call. However, as almost every logging call creates String objects, it is critical. The accumulation of these Strings causes memory fragmentation and unnecessary garbage collection. Garbage collection, while beneficial, also produces significant performance loss. To reduce this as much as possible, always guard logging statements with a severity less than SEVERE. Since SEVERE is always expressed by the logger, these do not need a guard.

  • Use toString() or toPrint() to ease and improve logging

    When you want to print all the values of an object, it is helpful to use the toString() method of the class you want to log. In this way, you can assemble all of the data into one clean output statement and avoid cluttering up your log file with redundant data (i.e. multiple lines with several time and level stamps for just one object). Also, this way, all developers can simply call the toString() method to get a print of all the object's current data.

Comments (0)

You don't have permission to comment on this page.