-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
RKLog.h
127 lines (96 loc) · 4.24 KB
/
RKLog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
//
// RKLog.h
// RestKit
//
// Created by Blake Watters on 5/3/11.
// Copyright 2011 Two Toasters. All rights reserved.
//
/**
RestKit Logging is based on the LibComponentLogging framework
@see lcl_config_components.h
@see lcl_config_logger.h
*/
#import "lcl.h"
/**
RKLogComponent defines the active component within any given portion of RestKit
By default, messages will log to the base 'RestKit' log component. All other components
used by RestKit are nested under this parent, so this effectively sets the default log
level for the entire library.
The component can be undef'd and redefined to change the active logging component.
*/
#define RKLogComponent lcl_cRestKit
/**
The logging macros. These macros will log to the currently active logging component
at the log level identified in the name of the macro.
For example, in the RKObjectMappingOperation class we would redefine the RKLogComponent:
#undef RKLogComponent
#define RKLogComponent lcl_cRestKitObjectMapping
The lcl_c prefix is the LibComponentLogging data structure identifying the logging component
we want to target within this portion of the codebase. See lcl_config_component.h for reference.
Having defined the logging component, invoking the logger via:
RKLogInfo(@"This is my log message!");
Would result in a log message similar to:
I RestKit.ObjectMapping:RKLog.h:42 This is my log message!
The message will only be logged if the log level for the active component is equal to or higher
than the level the message was logged at (in this case, Info).
*/
#define RKLogCritical(...) \
lcl_log(RKLogComponent, lcl_vCritical, @"" __VA_ARGS__);
#define RKLogError(...) \
lcl_log(RKLogComponent, lcl_vError, @"" __VA_ARGS__);
#define RKLogWarning(...) \
lcl_log(RKLogComponent, lcl_vWarning, @"" __VA_ARGS__);
#define RKLogInfo(...) \
lcl_log(RKLogComponent, lcl_vInfo, @"" __VA_ARGS__);
#define RKLogDebug(...) \
lcl_log(RKLogComponent, lcl_vDebug, @"" __VA_ARGS__);
#define RKLogTrace(...) \
lcl_log(RKLogComponent, lcl_vTrace, @"" __VA_ARGS__);
/**
Log Level Aliases
These aliases simply map the log levels defined within LibComponentLogger to something more friendly
*/
#define RKLogLevelCritical lcl_vCritical
#define RKLogLevelError lcl_vError
#define RKLogLevelWarning lcl_vWarning
#define RKLogLevelInfo lcl_vInfo
#define RKLogLevelDebug lcl_vDebug
#define RKLogLevelTrace lcl_vTrace
/**
Alias the LibComponentLogger logging configuration method. Also ensures logging
is initialized for the framework.
Expects the name of the component and a log level.
Examples:
// Log debugging messages from the Network component
RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
// Log only critical messages from the Object Mapping component
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelCritical);
*/
#define RKLogConfigureByName(name, level) \
RKLogInitialize(); \
lcl_configure_by_name(name, level);
/**
Alias for configuring the LibComponentLogger logging component for the App. This
enables the end-user of RestKit to leverage RKLog() to log messages inside of
their apps.
*/
#define RKLogSetAppLoggingLevel(level) \
RKLogInitialize(); \
lcl_configure_by_name("App", level);
/**
Set the Default Log Level
Based on the presence of the DEBUG flag, we default the logging for the RestKit parent component
to Info or Warning.
You can override this setting by defining RKLogLevelDefault as a pre-processor macro.
*/
#ifndef RKLogLevelDefault
#ifdef DEBUG
#define RKLogLevelDefault RKLogLevelInfo
#else
#define RKLogLevelDefault RKLogLevelWarning
#endif
#endif
/**
Initialize the logging environment
*/
void RKLogInitialize(void);