ObjFW  Check-in [17338ef1d5]

Overview
Comment:Add of_log for easy logging to stderr.

Uses OFConstantString* for the format to prevent users from doing stupid
things like of_log([of_stdin readLine]).

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 17338ef1d5dc20589c2049e9f21d965c826630847197401c8ca752bc889b53c3
User & Date: js on 2011-02-01 14:27:31
Other Links: manifest | tags
Context
2011-02-01
15:55
Add missing files to .xcodeproj and adjust tests. check-in: eb260acec9 user: js tags: trunk
14:27
Add of_log for easy logging to stderr. check-in: 17338ef1d5 user: js tags: trunk
2011-01-31
23:15
Work around glibc weirdness. check-in: 41af19cfbc user: js tags: trunk
Changes

Modified src/OFFile.h from [f2bde54c77] to [4e34f334ab].

14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
 * file.
 */

#include <sys/types.h>

#import "OFSeekableStream.h"

@class OFString;
@class OFArray;
@class OFDate;



/**
 * \brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  fd;







<


>
>







14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
 * file.
 */

#include <sys/types.h>

#import "OFSeekableStream.h"


@class OFArray;
@class OFDate;

extern void of_log(OFConstantString*, ...);

/**
 * \brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  fd;

Modified src/OFFile.m from [946463e8bc] to [00f92e27f7].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
 * file.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>

#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

#ifndef _WIN32
# include <pwd.h>
# include <grp.h>
#endif

#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
#ifdef OF_THREADS
# import "OFThread.h"
#endif
#import "OFDate.h"

#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

#ifdef _WIN32
# import <windows.h>
#endif







>



















>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 * file.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

#ifndef _WIN32
# include <pwd.h>
# include <grp.h>
#endif

#import "OFFile.h"
#import "OFString.h"
#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
# import <windows.h>
#endif
98
99
100
101
102
103
104




















105
106
107
108
109
110
111
	if (!strcmp(mode, "a+"))
		return O_RDWR | O_CREAT | O_APPEND;
	if (!strcmp(mode, "ab+") || !strcmp(mode, "a+b"))
		return O_RDWR | O_CREAT | O_APPEND | O_BINARY;

	return -1;
}





















@interface OFFileSingleton: OFFile
@end

@implementation OFFile
+ (void)load
{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	if (!strcmp(mode, "a+"))
		return O_RDWR | O_CREAT | O_APPEND;
	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
+ (void)load
{