Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -16,13 +16,14 @@ #include #import "OFSeekableStream.h" -@class OFString; @class OFArray; @class OFDate; + +extern void of_log(OFConstantString*, ...); /** * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -16,10 +16,11 @@ #include "config.h" #include #include +#include #include #include #include #include @@ -35,10 +36,11 @@ #import "OFArray.h" #ifdef OF_THREADS # import "OFThread.h" #endif #import "OFDate.h" +#import "OFApplication.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" #ifdef _WIN32 @@ -100,10 +102,30 @@ if (!strcmp(mode, "ab+") || !strcmp(mode, "a+b")) return O_RDWR | O_CREAT | O_APPEND | O_BINARY; return -1; } + +void +of_log(OFConstantString *fmt, ...) +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFString *date, *me, *msg; + va_list args; + + date = [[OFDate date] localDateStringWithFormat: @"%Y-%m-%dT%H:%M:%S"]; + me = [OFFile lastComponentOfPath: [OFApplication programName]]; + + va_start(args, fmt); + msg = [[[OFString alloc] initWithFormat: fmt + arguments: args] autorelease]; + va_end(args); + + [of_stderr writeFormat: @"[%@ %@(%d)] %@\n", date, me, getpid(), msg]; + + [pool release]; +} @interface OFFileSingleton: OFFile @end @implementation OFFile