Object | +---DTextWritableLogger
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
#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;
}
Instance Variables
Method Index
message - the message to be logged
dateTime - the date/time of the event
level - the level of the event
message - the message of the event
low - the lowest active level
message - the message of the event