Proposals:Logging

From KitwarePublic
Jump to navigationJump to search

Requirements

Current Status

Logging capabilities are currently available in ITK through very limited mechanism that involve the use of the following element

  • itkWarningMacro
  • itkExceptionMacro
  • TextOutput

Advantages

  • It is already there  :-)
  • It is fully implemented using ITK classes. We have complete control over the code
  • It is compact and easy to maintain

Drawbacks

The drawbacks of the current functionalities are

  • The TextOutput is by default sent to an OutputWindow that lacks an event-loop. It is then usually the case that users/developers dont have a chance to look at the error messages because they are scrolled rapidly and there is no way to get them back.
  • Messages are not send to files. Currently this could only be done by each developer creating a class deriving from the OutputWindow and redirecting the messages to a file.
  • Level of granularity. The current approach only have "ERROR" messages that are thrown through exceptions and warning messages.

Wish List of Logging Features

Here are the features that ITK developer would like to have available in a logging infrastructure

  • Possibility of selecting the level of granularity at run time
  • Possibility of sending logging messages to multiple destinations (files, sockets, console, GUI windows) some of them simultaneously
  • Suitable for being used in multi-threaded environments.
  • Possibility of selecting the objects that send logging messages
  • Possibility of having multiple receivers for the messages. e.g. several Logger instances
  • Formatting log messages in such a way that they can be sorted and greped later on
  • Possibility of adding time stamps to the messages
  • Integrate with ITK such that appropriate filters (optimizers, registrators) would provide a basic level of progress reporting that could be enabled/disabled at run-time.
  • Minimize performance impacts on the applications being logged. (important for release version of applications)
  • Possibility of limiting the size of a log file (for saving storage space)
  • Possibility of aging log files (for archiving)
  • Possibility of guaranteeing messages to be logged (important when messages are critical)
  • Possibility of loading an XML setting file at run time (level of granularity, destinations, format, etc.)
  • Possibility of having hierarchy of loggers and inheritance of settings (convenience of setting and managing loggers)
  • Possibility of having logger ID and being able to get and designate a logger with a specified ID (logger-wise run-time setting is possible, not application-wise)

Option of using Log4cxx

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. Experience have proved Singletons to be conflictive when dealing with shared libraries.
  • The library is in version 0.93. Its developers have gone through a refactoring process and the new version depends on a systems service library from Apache.
  • 30K lines of code to maintain
  • 2 Megabytes of source code
  • It wasn't supported in all the ITK platforms. It required substantial work to port it to all of them.
  • 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


Option of Writing our own

This option involves to develop a set of new ITK classes intended for providing the logging functionalities.

Pros

  • Complete control over the code
  • Only implements what we need
  • Focus on performance on the context of ITK uses

Cons

  • Potentially reinventing the wheeel

Potential Implementations

Adapt IGSTK classes

Sohan Rajan from the ISIS Center at Georgetown University has already develop a starting framework for providing logging capabilities. We could take these classes and extend them as appropriate in order to fulfill the needs of the ITK community.

Issues from Hee-Su(ISIS)

In addition to wish list update, here are some issues.

OS-independent timestamps

for datetime

  • vtkTimerLog : better but it's dependent on vtk
  • time(), strftime(), gmtime(), localtime(), asctime() : ANSI but 32bits

for real-time clock

  • QueryPerformanceCounter(), QueryPerformanceFrequency() : Win32
  • gettimeofday() : UNIX, Linux

Alternatives for guaranteeing messages to be logged

  • flush to a disk immediately (slow, overhead on a disk)
  • run a separate logging service and forward messages to it. (slow because of IPC)
  • flush manually by a programmer
  • flush automatically when the level of message is above certain level. (e.g. CRITICAL, ERROR)
  • don't care (do nothing)
  • user could set an option for this. but option checking(if-then) might reduce performance.



ITK: [Welcome | Site Map]