mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Completely rewritten by Adam Fedor.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2009 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0051a4adcb
commit
b5b84194f3
1 changed files with 50 additions and 21 deletions
|
@ -1,11 +1,11 @@
|
||||||
/* Implementation of NSLog() error loging functions for GNUStep
|
/* Interface for NSLog for GNUStep
|
||||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||||
Created: Nov 1995
|
Date: November 1996
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Library General Public
|
modify it under the terms of the GNU Library General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
@ -21,22 +21,51 @@
|
||||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
`void NSLog(NSString *format,...'
|
#include <Foundation/NSObjCRuntime.h>
|
||||||
) Writes to stderr an error message of the form:
|
#include <Foundation/NSDate.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSProcessInfo.h>
|
||||||
|
|
||||||
ª \i time processName processID format\i0 º. The format argument
|
NSLog_printf_handler *_NSLog_printf_handler;
|
||||||
to `NSLog()' is a format string in the style of the standard C
|
|
||||||
function `printf()', followed by an arbitrary number of arguments
|
|
||||||
that match conversion specifications (such as %s or %d) in the
|
|
||||||
format string. (You can pass an object in the list of arguments by
|
|
||||||
specifying % in the format stringÐthis conversion specification
|
|
||||||
gets replaced by the string that the object's description method
|
|
||||||
returns.)
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
NSLogv(NSString* format, va_list args)
|
_NSLog_standard_printf_handler (NSString* message)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "", );
|
fprintf (stderr, [message cStringNoCopy]);
|
||||||
vfprintf(stderr, [[NSString stringWithFormat:format
|
|
||||||
arguments:args] cString]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NSLog (NSString* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, format);
|
||||||
|
NSLogv (format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NSLogv (NSString* format, va_list args)
|
||||||
|
{
|
||||||
|
NSString* prefix;
|
||||||
|
NSString* message;
|
||||||
|
|
||||||
|
if (_NSLog_printf_handler == NULL)
|
||||||
|
_NSLog_printf_handler = *_NSLog_standard_printf_handler;
|
||||||
|
|
||||||
|
prefix = [NSString
|
||||||
|
stringWithFormat: @"%@ %@[%d] ",
|
||||||
|
[[NSCalendarDate calendarDate]
|
||||||
|
descriptionWithCalendarFormat: @"%b %d %H:%M:%S"],
|
||||||
|
[[[NSProcessInfo processInfo] processName] lastPathComponent],
|
||||||
|
getpid()];
|
||||||
|
|
||||||
|
/* Check if there is already a newline at the end of the format */
|
||||||
|
if (![format hasSuffix: @"\n"])
|
||||||
|
format = [format stringByAppendingString: @"\n"];
|
||||||
|
message = [NSString stringWithFormat: format arguments: args];
|
||||||
|
|
||||||
|
prefix = [prefix stringByAppendingString: message];
|
||||||
|
_NSLog_printf_handler (prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue