Class DTextWritableLogger

Inherits from:
Object
Conforms to:
DLogger
Declared in:
DTextWritableLogger.h

Class Hierarchy

    Object
      |
      +---DTextWritableLogger

Class Description

The DTextWritableLogger class implements methods for a continuous logging to a class implementing the protocol DTextWritable. The logger changes identical sequential log messages to two lines: first the message and then a line with the number of occurences. The layout of the log line is: yyyy-mm-dd hh:mm:ss.mmm message.

Example:
#include <stdio.h>
#include "ofc/DTextWritableLogger.h"
#include "ofc/DLog.h"
#include "ofc/DFile.h"

int main(int argc, char *argv[])
{
  DTextWritableLogger *logger = [DTextWritableLogger new];
  DFile               *file   = [DFile new];
  char                 name[] = "example.log";
  int                  i;

  if ([file open :name :"w"])
  {
    [logger writer :file];             // Give to the textwriteable logger the destination file

    dlogger(logger);                   // Give to the base logger the textwritable logger as destination

    dlog(DLOG_ALERT, "Alert!!");       // Log an alert

    for (i = 0; i < 10; i++)           // Add a repeated error message
    {
      dlog(DLOG_ERROR, "Errors");
    }

    dlogmask(DLOG_NOTICE|DLOG_DEBUG);  // Mask some log levels

    dlog(DLOG_WARNING, "Warning..masked"); // Masked warning
    dlog(DLOG_DEBUG,   "Debug:%d",7);  // Debug message
    dlog(DLOG_NOTICE,  "Notice.");     // Notice message

    dlogger(nil);                      // Stop logging via the textwritable logger

    [file close];                      // Close the destination file

    printf("Events succesfully logged in \"%s\".\n", name);
  }
  else
    printf("Could not open \"%s\" for writing:%d.\n", name, [file error]);

  [logger free];                       // Cleanup
  [file   free];

  return 0;
}
Last modified:
09-Aug-2008 (DTextWritableLogger.h)

Instance Variables

protected unsigned _mask
the active mask
protected id<DTextWritable> _writer
the reference to the writer
protected DText *_previous
the previous message
protected DDateTime *_time
the time
protected long _repeated
the number of identical messages
protected DText *_output
the output for the logger

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0