150 likes | 329 Views
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
E N D
New Classes forDebug, 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 • Don’t want to miss important messages among thousands of unimportant messages • No debug output
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
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
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);
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
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
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);)
AliError Macros (continued) • C++ stream syntax: AliErrorStream() << “message” << object; • Redirection of stdout/stderr:ToAliError( Function(); object.Print(); );
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
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;
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;
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
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