Proposals:Logging

From KitwarePublic
Revision as of 17:47, 4 March 2005 by Blezek (talk | contribs) (Initial thoughts)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

log4cxx is a logging package modeled on log4j, a popular logging package for Java.


Usage

Each class in ITK would have a static class variable pointing to a logger. The logger's are named, with the usual naming convention being org.itk.Code.Common.Object, essentially a namespace / Java package hybrid. Names define a hierarchy, so org.itk.Code is the parent of org.itk.Code.Common, org.itk.Code.BasicFilters, etc... There are different levels of log messages, debug, info, warn, error, fatal and log. The developer decides when and where to put a logging message, and it's severity.

At runtime, the application defines the threshold of messages to be logged, i.e. debug and higher, or info and higher. A logger inherits it's threshold from it's parent, if not specified. Thus it is easy to shut off logging messages from org.itk.Code all at once.

In addition to thresholds, different output options are available called Appenders. For instance:

  • Console: essentially std::cout
  • File: Log to a file
  • SMTP: Send email
  • RDBMS: Log to a database
  • RollingLogFile: Log to a file, roll to a new file at specified time/size

Documentation can be found on the log4cxx doxygen pages.

Impact to ITK

  • Augment the Error and Warning macros in ITK
  • Can be implemented in New and/or Type macro
  • Immediately available to all class developers
  • Flexible output options
  • Aid to debugging

Pros

  • Allow much more flexibility in logging messages
  • Easy configuration of logging structure
  • Applications can leverage feature
  • Can change logging options at runtime, not compile time

Cons

  • Static class variable per class
  • Need to work out default configuration
  • Run-time overhead (fairly minimal)

Proposed Plan

  • Check into Insight/Utilities
  • Write smoke test
  • Get test working on all platforms
  • Resolve integration issues (itkNewMacro / itkTypeMacro)
  • Replace Error / Warning Macros
  • Begin using in existing and new classes