Skip to content

Commit fbfcb88

Browse files
committed
added LogFile
1 parent d3cad8d commit fbfcb88

File tree

5 files changed

+1325
-0
lines changed

5 files changed

+1325
-0
lines changed

RestKit.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
204C3B831830737600069F56 /* LCLLogFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 204C3B801830737600069F56 /* LCLLogFile.h */; };
11+
204C3B841830737600069F56 /* LCLLogFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 204C3B811830737600069F56 /* LCLLogFile.m */; };
12+
204C3B851830737600069F56 /* LCLLogFileConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 204C3B821830737600069F56 /* LCLLogFileConfig.h */; };
1013
2501405315366000004E0466 /* RKObjectiveCppTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2501405215366000004E0466 /* RKObjectiveCppTest.mm */; };
1114
2501405415366000004E0466 /* RKObjectiveCppTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2501405215366000004E0466 /* RKObjectiveCppTest.mm */; };
1215
25055B8414EEF32A00B9C4DD /* RKMappingTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 25055B8014EEF32A00B9C4DD /* RKMappingTest.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -775,6 +778,9 @@
775778
/* End PBXCopyFilesBuildPhase section */
776779

777780
/* Begin PBXFileReference section */
781+
204C3B801830737600069F56 /* LCLLogFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCLLogFile.h; sourceTree = "<group>"; };
782+
204C3B811830737600069F56 /* LCLLogFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCLLogFile.m; sourceTree = "<group>"; };
783+
204C3B821830737600069F56 /* LCLLogFileConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCLLogFileConfig.h; sourceTree = "<group>"; };
778784
2501405215366000004E0466 /* RKObjectiveCppTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RKObjectiveCppTest.mm; sourceTree = "<group>"; };
779785
25055B8014EEF32A00B9C4DD /* RKMappingTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RKMappingTest.h; path = Testing/RKMappingTest.h; sourceTree = "<group>"; };
780786
25055B8114EEF32A00B9C4DD /* RKMappingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RKMappingTest.m; path = Testing/RKMappingTest.m; sourceTree = "<group>"; };
@@ -1293,6 +1299,16 @@
12931299
/* End PBXFrameworksBuildPhase section */
12941300

12951301
/* Begin PBXGroup section */
1302+
204C3B861830737B00069F56 /* LogFile */ = {
1303+
isa = PBXGroup;
1304+
children = (
1305+
204C3B801830737600069F56 /* LCLLogFile.h */,
1306+
204C3B811830737600069F56 /* LCLLogFile.m */,
1307+
204C3B821830737600069F56 /* LCLLogFileConfig.h */,
1308+
);
1309+
name = LogFile;
1310+
sourceTree = "<group>";
1311+
};
12961312
250CA67A147D8E7F0047D347 /* OCHamcrest */ = {
12971313
isa = PBXGroup;
12981314
children = (
@@ -1651,6 +1667,7 @@
16511667
children = (
16521668
25160EA11456532C0060A5C5 /* Core */,
16531669
25160EAE1456532C0060A5C5 /* NSLog */,
1670+
204C3B861830737B00069F56 /* LogFile */,
16541671
);
16551672
path = LibComponentLogging;
16561673
sourceTree = "<group>";
@@ -2180,6 +2197,7 @@
21802197
25160E1A145650490060A5C5 /* RKObjectMapping.h in Headers */,
21812198
25160E1C145650490060A5C5 /* RKObjectMappingDefinition.h in Headers */,
21822199
25160E1D145650490060A5C5 /* RKObjectMappingOperation.h in Headers */,
2200+
204C3B831830737600069F56 /* LCLLogFile.h in Headers */,
21832201
25160E1F145650490060A5C5 /* RKObjectMappingProvider.h in Headers */,
21842202
25160E21145650490060A5C5 /* RKObjectMappingResult.h in Headers */,
21852203
25160E23145650490060A5C5 /* RKObjectPropertyInspector.h in Headers */,
@@ -2221,6 +2239,7 @@
22212239
25B408261491CDDC00F21111 /* RKDirectory.h in Headers */,
22222240
2513504E14B8FE6B00A7E893 /* RKConfigurationDelegate.h in Headers */,
22232241
250DF22A14C5190E0001DEFA /* RKOrderedDictionary.h in Headers */,
2242+
204C3B851830737600069F56 /* LCLLogFileConfig.h in Headers */,
22242243
49D2759D14C9EF1E0090845D /* ISO8601DateFormatter.h in Headers */,
22252244
49A66B0C14CEFB0400A6F062 /* XMLReader.h in Headers */,
22262245
250DF25F14C680F90001DEFA /* RKObjectMappingProvider+Contexts.h in Headers */,
@@ -2732,6 +2751,7 @@
27322751
25160E1B145650490060A5C5 /* RKObjectMapping.m in Sources */,
27332752
25160E1E145650490060A5C5 /* RKObjectMappingOperation.m in Sources */,
27342753
25160E20145650490060A5C5 /* RKObjectMappingProvider.m in Sources */,
2754+
204C3B841830737600069F56 /* LCLLogFile.m in Sources */,
27352755
25160E22145650490060A5C5 /* RKObjectMappingResult.m in Sources */,
27362756
25160E24145650490060A5C5 /* RKObjectPropertyInspector.m in Sources */,
27372757
25160E26145650490060A5C5 /* RKObjectRelationshipMapping.m in Sources */,
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
//
2+
//
3+
// LCLLogFile.h
4+
//
5+
//
6+
// Copyright (c) 2008-2013 Arne Harren <ah@0xc0.de>
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
#define _LCLLOGFILE_VERSION_MAJOR 1
27+
#define _LCLLOGFILE_VERSION_MINOR 2
28+
#define _LCLLOGFILE_VERSION_BUILD 3
29+
#define _LCLLOGFILE_VERSION_SUFFIX ""
30+
31+
//
32+
// LCLLogFile
33+
//
34+
// LCLLogFile is a logging back-end implementation which writes log messages to
35+
// an application-specific log file. LCLLogFile can be used as a logging
36+
// back-end for LibComponentLogging, but it is also useable as a standalone
37+
// logging class without the Core files of LibComponentLogging.
38+
//
39+
// The log file is opened automatically when the first log message needs to be
40+
// written to the log file. There is no need to call open, close, reset, etc.
41+
// manually.
42+
//
43+
// The log file gets rotated if a given maximum file size is reached.
44+
//
45+
// LCLLogFile is configured via the following #defines in LCLLogFileConfig.h
46+
// (see #import below):
47+
//
48+
// - Full path of the log file (type NSString *)
49+
// #define _LCLLogFile_LogFilePath <definition>
50+
//
51+
// - Append to an existing log file on startup? (type BOOL)
52+
// #define _LCLLogFile_AppendToExistingLogFile
53+
//
54+
// - Maximum size of the log file in bytes (type size_t)
55+
// #define _LCLLogFile_MaxLogFileSizeInBytes <definition>
56+
//
57+
// - Mirror log messages to stderr? (type BOOL)
58+
// #define _LCLLogFile_MirrorMessagesToStdErr <definition>
59+
//
60+
// - Escape ('\\' and) '\n' line feed characters in log messages (type BOOL)
61+
// #define _LCLLogFile_EscapeLineFeeds <definition>
62+
//
63+
// - Maximum size of a log message in characters (type NSUInteger)
64+
// #define _LCLLogFile_MaxMessageSizeInCharacters <definition or 0>
65+
//
66+
// - Show file names in the log messages? (type BOOL)
67+
// #define _LCLLogFile_ShowFileNames <definition>
68+
//
69+
// - Show line numbers in the log messages? (type BOOL)
70+
// #define _LCLLogFile_ShowLineNumbers <definition>
71+
//
72+
// - Show function names in the log messages? (type BOOL)
73+
// #define _LCLLogFile_ShowFunctionNames <definition>
74+
//
75+
//
76+
// When using LCLLogFile as a back-end for LibComponentLogging, simply add an
77+
// #import "LCLLogFile.h"
78+
// statement to your lcl_config_logger.h file and use the LCLLogFileConfig.h
79+
// file for detailed configuration of the LCLLogFile class.
80+
//
81+
82+
83+
#import <Foundation/Foundation.h>
84+
#import "LCLLogFileConfig.h"
85+
86+
87+
@interface LCLLogFile : NSObject {
88+
89+
}
90+
91+
92+
//
93+
// Logging methods.
94+
//
95+
96+
97+
// Writes the given log message to the log file.
98+
+ (void)logWithIdentifier:(const char *)identifier level:(uint32_t)level
99+
path:(const char *)path line:(uint32_t)line
100+
function:(const char *)function
101+
message:(NSString *)message;
102+
103+
// Writes the given log message to the log file (format and va_list var args).
104+
+ (void)logWithIdentifier:(const char *)identifier level:(uint32_t)level
105+
path:(const char *)path line:(uint32_t)line
106+
function:(const char *)function
107+
format:(NSString *)format args:(va_list)args;
108+
109+
// Writes the given log message to the log file (format and ... var args).
110+
+ (void)logWithIdentifier:(const char *)identifier level:(uint32_t)level
111+
path:(const char *)path line:(uint32_t)line
112+
function:(const char *)function
113+
format:(NSString *)format, ... __attribute__((format(__NSString__, 6, 7)));
114+
115+
116+
//
117+
// Configuration.
118+
//
119+
120+
121+
// Returns/sets the path of the log file. Setting the path implies a reset.
122+
+ (NSString *)path;
123+
+ (void)setPath:(NSString *)path;
124+
125+
// Returns the path of the backup log file.
126+
+ (NSString *)path0;
127+
128+
// Returns/sets whether log messages get appended to an existing log file on
129+
// startup.
130+
+ (BOOL)appendsToExistingLogFile;
131+
+ (void)setAppendsToExistingLogFile:(BOOL)value;
132+
133+
// Returns/sets the maximum size of the log file (as defined by
134+
// _LCLLogFile_MaxLogFileSizeInBytes).
135+
+ (size_t)maxSize;
136+
+ (void)setMaxSize:(size_t)value;
137+
138+
// Returns/sets whether log messages are mirrored to stderr.
139+
+ (BOOL)mirrorsToStdErr;
140+
+ (void)setMirrorsToStdErr:(BOOL)value;
141+
142+
// Returns/sets whether ('\\' and) '\n' line feed characters are escaped in
143+
// log messages.
144+
+ (BOOL)escapesLineFeeds;
145+
+ (void)setEscapesLineFeeds:(BOOL)value;
146+
147+
// Returns/sets the maximum size of a log message in characters (without
148+
// prefixes). The value 0 indicates that there is no maximum size for log
149+
// messages.
150+
+ (NSUInteger)maxMessageSize;
151+
+ (void)setMaxMessageSize:(NSUInteger)value;
152+
153+
// Returns/sets whether file names are shown.
154+
+ (BOOL)showsFileNames;
155+
+ (void)setShowsFileNames:(BOOL)value;
156+
157+
// Returns/sets whether line numbers are shown.
158+
+ (BOOL)showsLineNumbers;
159+
+ (void)setShowsLineNumbers:(BOOL)value;
160+
161+
// Returns/sets whether function names are shown.
162+
+ (BOOL)showsFunctionNames;
163+
+ (void)setShowsFunctionNames:(BOOL)value;
164+
165+
166+
//
167+
// Status information and internals.
168+
//
169+
170+
171+
// Returns the current size of the log file.
172+
+ (size_t)size;
173+
174+
// Opens the log file.
175+
+ (void)open;
176+
177+
// Closes the log file.
178+
+ (void)close;
179+
180+
// Resets the log file. This also deletes the existing log file.
181+
+ (void)reset;
182+
183+
// Rotates the log file.
184+
+ (void)rotate;
185+
186+
187+
//
188+
// Methods for creating log file paths.
189+
//
190+
191+
192+
// Returns a default path for a log file which is based on the Info.plist
193+
// files which are associated with this class. The returned path has the form
194+
// ~/Library/Logs/<main>/<this>.log
195+
// where
196+
// <main> is the name (or identifier) of the application's main bundle, and
197+
// <this> is the name (or identifier) of the bundle to which this LCLLogFile
198+
// class belongs.
199+
// This method is a convenience method which calls defaultPathWithPathPrefix
200+
// with the prefix ~/Library/Logs and the given fallback path.
201+
+ (NSString *)defaultPathInHomeLibraryLogsOrPath:(NSString *)path;
202+
203+
// Returns a default path for a log file which is based on the Info.plist
204+
// files which are associated with this class. The returned path has the form
205+
// <path>/<main>/<this>.log
206+
// where
207+
// <path> is the given path prefix,
208+
// <main> is the name (or identifier) of the application's main bundle, and
209+
// <this> is the name (or identifier) of the bundle to which this LCLLogFile
210+
// class belongs.
211+
// If the name or identifier cannot be retrieved from the main bundle, the
212+
// returned default path has the form
213+
// <path>/<this>/<this>.<pid>.log
214+
// where
215+
// <pid> is the current process id.
216+
// If the name or identifier cannot be retrieved from the bundle which
217+
// corresponds to this LCLLogFile class, or if the given path prefix <path> is
218+
// nil, the given fallback path is returned.
219+
+ (NSString *)defaultPathWithPathPrefix:(NSString *)pathPrefix
220+
orPath:(NSString *)path;
221+
222+
// Returns a default path component for a log file which is based on the given
223+
// bundles' Info.plist files. The returned path has the form
224+
// <path>/<file>.log
225+
// where
226+
// <path> is the name (or identifier) of the given path bundle, and
227+
// <file> is the name (or identifier) of the given file bundle.
228+
// If the name or identifier cannot be retrieved from the path bundle, the
229+
// returned default path has the form
230+
// <file>/<file>.<pid>.log
231+
// where
232+
// <pid> is the current process id.
233+
// If the name or identifier cannot be retrieved from the file bundle, the
234+
// given fallback path component is returned.
235+
+ (NSString *)defaultPathComponentFromPathBundle:(NSBundle *)pathBundle
236+
fileBundle:(NSBundle *)fileBundle
237+
orPathComponent:(NSString *)pathComponent;
238+
239+
// Returns the name from the given bundle's Info.plist file. If the name doesn't
240+
// exist, the bundle's identifier is returned. If the identifier doesn't exist,
241+
// the given fallback string is returned.
242+
+ (NSString *)nameOrIdentifierFromBundle:(NSBundle *)bundle
243+
orString:(NSString *)string;
244+
245+
246+
@end
247+
248+
249+
//
250+
// Integration with LibComponentLogging Core.
251+
//
252+
253+
254+
// ARC/non-ARC autorelease pool
255+
#define _lcl_logger_autoreleasepool_arc 0
256+
#if defined(__has_feature)
257+
# if __has_feature(objc_arc)
258+
# undef _lcl_logger_autoreleasepool_arc
259+
# define _lcl_logger_autoreleasepool_arc 1
260+
# endif
261+
#endif
262+
#if _lcl_logger_autoreleasepool_arc
263+
# define _lcl_logger_autoreleasepool_begin \
264+
@autoreleasepool {
265+
# define _lcl_logger_autoreleasepool_end \
266+
}
267+
#else
268+
# define _lcl_logger_autoreleasepool_begin \
269+
NSAutoreleasePool *_lcl_logger_autoreleasepool = [[NSAutoreleasePool alloc] init];
270+
# define _lcl_logger_autoreleasepool_end \
271+
[_lcl_logger_autoreleasepool release];
272+
#endif
273+
274+
#ifndef _LCL_NO_IGNORE_WARNINGS
275+
# ifdef __clang__
276+
// Ignore some warnings about variadic macros when using '-Weverything'.
277+
# pragma clang diagnostic push
278+
# pragma clang diagnostic ignored "-Wunknown-pragmas"
279+
# pragma clang diagnostic ignored "-Wvariadic-macros"
280+
# pragma clang diagnostic ignored "-Wpedantic"
281+
# endif
282+
#endif
283+
284+
// Define the _lcl_logger macro which integrates LCLLogFile as a logging
285+
// back-end for LibComponentLogging and pass the header of a log component as
286+
// the identifier to LCLLogFile's log method.
287+
#define _lcl_logger(_component, _level, _format, ...) { \
288+
_lcl_logger_autoreleasepool_begin \
289+
[LCLLogFile logWithIdentifier:_lcl_component_header[_component] \
290+
level:_level \
291+
path:__FILE__ \
292+
line:__LINE__ \
293+
function:__PRETTY_FUNCTION__ \
294+
format:_format, \
295+
## __VA_ARGS__]; \
296+
_lcl_logger_autoreleasepool_end \
297+
}
298+
299+
#ifndef _LCL_NO_IGNORE_WARNINGS
300+
# ifdef __clang__
301+
# pragma clang diagnostic pop
302+
# endif
303+
#endif
304+

0 commit comments

Comments
 (0)