mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
Bring NSLog up to spec.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3876 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
342162cfaf
commit
e85feec4a4
5 changed files with 727 additions and 447 deletions
|
@ -26,8 +26,13 @@
|
|||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
@ -37,7 +42,16 @@ NSLog_printf_handler *_NSLog_printf_handler;
|
|||
static void
|
||||
_NSLog_standard_printf_handler (NSString* message)
|
||||
{
|
||||
fputs ([message cString], stderr);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
const char *txt = [message cString];
|
||||
|
||||
if (fputs(txt, stderr) == EOF)
|
||||
{
|
||||
syslog(LOG_INFO, "%s", txt);
|
||||
}
|
||||
#else
|
||||
fputs([message cString], stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -53,9 +67,12 @@ NSLog (NSString* format, ...)
|
|||
void
|
||||
NSLogv (NSString* format, va_list args)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSString* prefix;
|
||||
NSString* message;
|
||||
static NSRecursiveLock *myLock = nil;
|
||||
NSAutoreleasePool *arp;
|
||||
NSString *prefix;
|
||||
NSString *message;
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
if (_NSLog_printf_handler == NULL)
|
||||
_NSLog_printf_handler = *_NSLog_standard_printf_handler;
|
||||
|
@ -73,7 +90,22 @@ NSLogv (NSString* format, va_list args)
|
|||
message = [NSString stringWithFormat: format arguments: args];
|
||||
|
||||
prefix = [prefix stringByAppendingString: message];
|
||||
|
||||
if (myLock == nil)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (myLock == nil)
|
||||
{
|
||||
myLock = [NSRecursiveLock new];
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
[myLock lock];
|
||||
|
||||
_NSLog_printf_handler (prefix);
|
||||
|
||||
[myLock unlock];
|
||||
|
||||
[arp release];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue