1 / 15

New Classes for Debug, Info and Error Messages

New Classes for Debug, Info and Error Messages. Thomas Kuhr Offline Week 15/09/2004. Requirements. During Development: Need detailed debug output for certain class / module During production: Keep log files small Only relevant messages

elin
Download Presentation

New Classes for Debug, Info and Error Messages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. New Classes forDebug, Info and Error Messages Thomas Kuhr Offline Week 15/09/2004

  2. Requirements • During Development: • Need detailed debug output for certain class / module • During production: • Keep log files small • Only relevant messages • Don’t want to miss important messages among thousands of unimportant messages • No debug output

  3. Current Situation • Debug output with cout/cerr, printf, TObject::Info, … • Debug flag fDebug, Set/GetDebug() • Need access to object • Difficult to set Possible improvements: • Dedicated output method for debug information • Common and flexible way of (debug) output steering • Setting of debug level by class / module, not by object

  4. New Scheme Steering of output by the user: • AliLog class • Macro • Aliroot prompt • .rootrc file Output messages put into the detector code by the developers: • AliError macros

  5. AliLog Class • (Debug) output managed by singleton class AliLog • Access via static methods • Detailed steering of output level: EnableDebug(Bool_t enabled); SetGlobalLog/DebugLevel(Int_t level); SetModuleDebugLevel(const char* module, Int_t level); SetClassDebugLevel(const char* class, Int_t level); • ROOT TError messages included:SetHandleRootMessages(Bool_t on);

  6. AliLog Class (continued) • Steering of output streams:SetStandardOutput(EType type);SetErrorOutput(EType type);SetFileOutput(EType type, const char* fileName); • Steering of displayed information:SetPrintType(EType type, Bool_t on);SetPrintModule(EType type, Bool_t on);SetPrintScope(EType type, Bool_t on);SetPrintLocation(EType type, Bool_t on); • All options can be steered via .rootrc

  7. AliError Macros Preprocessormacros:AliDebug(level, “message”);AliInfo/Warning/Error/Fatal(“…”); • Automatically get: • Module name • Class name (via virt. meth. ClassName()) • Function name (not on all platforms) • Source file name • Source line number • Complete removal of debug messages possible with compiler flag

  8. AliError Macros (continued) • Inside static class method: AliErrorClass(“message”);(Root: ::Error(…);) • Outside of classes: AliErrorGeneral(“scope”, “message”); • Message parameters: AliError(Form(“i=%d”, i));(Root: Error(“…”, “i=%d”, i);)

  9. AliError Macros (continued) • C++ stream syntax: AliErrorStream() << “message” << object; • Redirection of stdout/stderr:ToAliError( Function(); object.Print(); );

  10. Migration to New Scheme • Replace Root Error by AliError, etc. • Replace printf, cout, cerr by AliDebug, AliInfo, etc. • Exception: Print method • Print to stdout • Consistent with Root • Redirection to different message types possible • Reminder: Use right signature:void Print(Option_t* opt=““) const; • Remove Get/SetDebug(), fDebug, use AliDebug instead • Use appropriate type of message

  11. When to Use What Kind of Message?

  12. Examples • Error(“method”, “…”); • AliError(“…”); • Info(“method”, “i=%d”, i); • AliInfo(Form(“i=%d”, i)); • AliDebug(1, Form(“i=%d”, i)); • if (GetDebug()>1) Info(“method”, “…”); • AliDebug(2, “…”); • SetDebug(2);fDebug=3;

  13. Examples • printf(“data=%f\n”, data); • AliDebug(3, Form(“data=%f”, data)); • cerr << i << endl; • AliDebug(5, Form(“%d”, i)); • cout << object; • AliDebugStream(4) << object; • Warning(“method”, “…”); • object.Print(); • AliWarning(“…”);ToAliWarning(object.Print();); • void PrintStatus(Option_t*); • void Print(Option_t* opt=“”) const;

  14. Scenario for Production • Disable debug output with compiler flag (-D LOG_NO_DEBUG) • Send error, warning and info messages to a log file • Send rest (printf, cout, cerr) to /dev/null • Read log file: • Error messages Fix code • Warning messages Explain and accept or fix code • No error or warning messages Assume proper execution

  15. Summary • No consistent treatment of debug messagesso far • No switch “debug mode” ↔ “production mode” • AliLog class and AliError macros provide: • A dedicated and common method for debug output • Detailed information automatically available • Easy and flexible steering of debug levels • Easy and flexible steering of output streams • Integration of root messages • Removal of debug output possible with compiler flag (production mode) • No Set/GetDebug() methods needed any more • Migrate to new scheme

More Related