|
22 | 22 |
|
23 | 23 | #define LOG_POLICY_FORMAT_TEXT_STR_DEBUG "[%.19s] #%" PRIuS " [ %" PRIuS " | %s | %s ] @%s : " |
24 | 24 | #define LOG_POLICY_FORMAT_TEXT_STR_RELEASE "[%.19s] #%" PRIuS " @%s : " |
| 25 | +#define LOG_POLICY_FORMAT_TEXT_STR_PRETTY "\x1b[32m%s\x1b[0m: " |
25 | 26 |
|
26 | 27 | /* -- Macros -- */ |
27 | 28 |
|
@@ -130,36 +131,57 @@ static size_t log_policy_format_text_size(log_policy policy, const log_record re |
130 | 131 |
|
131 | 132 | static const char * log_policy_format_text_serialize_impl_format(enum log_level_id log_level, unsigned int flags) |
132 | 133 | { |
133 | | - if (log_level == LOG_LEVEL_DEBUG) |
| 134 | + #if (LOG_POLICY_FORMAT_PRETTY == 1) |
134 | 135 | { |
| 136 | + (void)log_level; |
| 137 | + |
135 | 138 | if (flags & LOG_POLICY_FORMAT_TEXT_NEWLINE) |
136 | 139 | { |
137 | | - static const char format_debug_newline[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG "%s\n"; |
| 140 | + static const char format_debug_newline[] = LOG_POLICY_FORMAT_TEXT_STR_PRETTY "%s\n"; |
138 | 141 |
|
139 | 142 | return format_debug_newline; |
140 | 143 | } |
141 | 144 | else |
142 | 145 | { |
143 | | - static const char format_debug[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG "%s"; |
| 146 | + static const char format_debug[] = LOG_POLICY_FORMAT_TEXT_STR_PRETTY "%s"; |
144 | 147 |
|
145 | 148 | return format_debug; |
146 | 149 | } |
147 | 150 | } |
148 | | - else |
| 151 | + #else |
149 | 152 | { |
150 | | - if (flags & LOG_POLICY_FORMAT_TEXT_NEWLINE) |
| 153 | + if (log_level == LOG_LEVEL_DEBUG) |
151 | 154 | { |
152 | | - static const char format_release_newline[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE "%s\n"; |
153 | | - |
154 | | - return format_release_newline; |
| 155 | + if (flags & LOG_POLICY_FORMAT_TEXT_NEWLINE) |
| 156 | + { |
| 157 | + static const char format_debug_newline[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG "%s\n"; |
| 158 | + |
| 159 | + return format_debug_newline; |
| 160 | + } |
| 161 | + else |
| 162 | + { |
| 163 | + static const char format_debug[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG "%s"; |
| 164 | + |
| 165 | + return format_debug; |
| 166 | + } |
155 | 167 | } |
156 | 168 | else |
157 | 169 | { |
158 | | - static const char format_release[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE "%s"; |
159 | | - |
160 | | - return format_release; |
| 170 | + if (flags & LOG_POLICY_FORMAT_TEXT_NEWLINE) |
| 171 | + { |
| 172 | + static const char format_release_newline[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE "%s\n"; |
| 173 | + |
| 174 | + return format_release_newline; |
| 175 | + } |
| 176 | + else |
| 177 | + { |
| 178 | + static const char format_release[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE "%s"; |
| 179 | + |
| 180 | + return format_release; |
| 181 | + } |
161 | 182 | } |
162 | 183 | } |
| 184 | + #endif |
163 | 185 | } |
164 | 186 |
|
165 | 187 | static size_t log_policy_format_text_serialize_impl(log_policy policy, const log_record record, void * buffer, const size_t size) |
@@ -206,37 +228,48 @@ static size_t log_policy_format_text_serialize_impl_va(log_policy policy, const |
206 | 228 | { |
207 | 229 | log_policy_format_text_data text_data = log_policy_instance(policy); |
208 | 230 |
|
209 | | - log_aspect aspect = log_policy_aspect(policy); |
210 | | - |
211 | | - log_impl impl = log_aspect_parent(aspect); |
212 | | - |
213 | 231 | int header_length = 0, body_length = 0; |
214 | 232 |
|
215 | 233 | void * buffer_body = NULL; |
216 | 234 |
|
217 | 235 | struct log_record_va_list_type * variable_args; |
218 | 236 |
|
219 | | - if (log_impl_level(impl) == LOG_LEVEL_DEBUG) |
| 237 | + #if (LOG_POLICY_FORMAT_PRETTY == 1) |
220 | 238 | { |
221 | | - static const char header_format[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG; |
| 239 | + static const char header_format[] = LOG_POLICY_FORMAT_TEXT_STR_PRETTY; |
222 | 240 |
|
223 | 241 | header_length = snprintf(buffer, size, header_format, |
224 | | - ctime(log_record_time(record)), |
225 | | - log_record_thread_id(record), |
226 | | - log_record_line(record), |
227 | | - log_record_func(record), |
228 | | - log_record_file(record), |
229 | 242 | log_level_to_string(log_record_level(record))); |
230 | 243 | } |
231 | | - else |
| 244 | + #else |
232 | 245 | { |
233 | | - static const char header_format[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE; |
| 246 | + log_aspect aspect = log_policy_aspect(policy); |
234 | 247 |
|
235 | | - header_length = snprintf(buffer, size, header_format, |
236 | | - ctime(log_record_time(record)), |
237 | | - log_record_thread_id(record), |
238 | | - log_level_to_string(log_record_level(record))); |
| 248 | + log_impl impl = log_aspect_parent(aspect); |
| 249 | + |
| 250 | + if (log_impl_level(impl) == LOG_LEVEL_DEBUG) |
| 251 | + { |
| 252 | + static const char header_format[] = LOG_POLICY_FORMAT_TEXT_STR_DEBUG; |
| 253 | + |
| 254 | + header_length = snprintf(buffer, size, header_format, |
| 255 | + ctime(log_record_time(record)), |
| 256 | + log_record_thread_id(record), |
| 257 | + log_record_line(record), |
| 258 | + log_record_func(record), |
| 259 | + log_record_file(record), |
| 260 | + log_level_to_string(log_record_level(record))); |
| 261 | + } |
| 262 | + else |
| 263 | + { |
| 264 | + static const char header_format[] = LOG_POLICY_FORMAT_TEXT_STR_RELEASE; |
| 265 | + |
| 266 | + header_length = snprintf(buffer, size, header_format, |
| 267 | + ctime(log_record_time(record)), |
| 268 | + log_record_thread_id(record), |
| 269 | + log_level_to_string(log_record_level(record))); |
| 270 | + } |
239 | 271 | } |
| 272 | + #endif |
240 | 273 |
|
241 | 274 | if (header_length <= 0) |
242 | 275 | { |
|
0 commit comments