Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_log.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework afw_log interface helpers header
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_LOG_H__
10 #define __AFW_LOG_H__
11 
12 #include "afw_interface.h"
13 
56 #define afw_log_release afw_log_destroy
57 
59 
62  const afw_utf8_t *priority_id;
63  afw_log_priority_t priority;
64  const afw_utf8_z_t *description;
66 
67 
71 
72 
80  const afw_utf8_t *priority_id);
81 
82 
88 AFW_DECLARE(const afw_utf8_t *)
90  afw_log_priority_t priority);
91 
92 
98 AFW_DEFINE_STATIC_INLINE(afw_log_priority_mask_t)
100  afw_log_priority_t priority)
101 {
102  return 1 << priority;
103 }
104 
110 AFW_DEFINE_STATIC_INLINE(afw_log_priority_mask_t)
112  afw_log_priority_t priority)
113 {
114  return (1 << (priority + 1) ) - 1;
115 }
116 
123 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
126 {
127  return ((1 << priority) & mask) != 0;
128 }
129 
137 AFW_DEFINE_STATIC_INLINE(void)
140  afw_log_priority_t priority,
141  afw_boolean_t value)
142 {
143  if (value) {
144  *mask |= (1 << priority);
145  }
146 
147  else {
148  *mask &= ~(1 << priority);
149  }
150 }
151 
158 #define AFW_LOG(priority, message, xctx) \
159  afw_log_write(xctx->env->log, afw_log_priority_ ## priority, \
160  AFW__FILE_LINE__, message, xctx)
161 
168 #define AFW_LOG_Z(priority, message_z, xctx) \
169  afw_log_write_z(xctx->env->log, afw_log_priority_ ## priority, \
170  AFW__FILE_LINE__, message_z, xctx)
171 
180 #define AFW_LOG_VZ(priority, format_z, ap, xctx) \
181  afw_log_write_vz(xctx->env->log, afw_log_priority_ ## priority, \
182  AFW__FILE_LINE__, format_z, ap, xctx)
183 
192 #define AFW_LOG_FZ(priority, xctx, format_z, ...) \
193  afw_log_write_fz(xctx->env->log, afw_log_priority_ ## priority, \
194  AFW__FILE_LINE__, xctx, format_z, __VA_ARGS__)
195 
196 
205 AFW_DEFINE_STATIC_INLINE(void)
207  const afw_log_t * instance,
208  afw_log_priority_t priority,
209  const afw_utf8_z_t * source_z,
210  const afw_utf8_z_t * message_z,
211  afw_xctx_t *xctx)
212 {
213  afw_utf8_t message;
214 
215  message.s = message_z;
216  message.len = strlen(message_z);
217  afw_log_write(instance, priority, source_z, &message,
218  xctx);
219 }
220 
230 AFW_DECLARE(void)
232  const afw_log_t * instance,
233  afw_log_priority_t priority,
234  const afw_utf8_z_t * source_z,
235  const afw_utf8_z_t * format_z,
236  va_list ap,
237  afw_xctx_t *xctx);
238 
248 AFW_DEFINE_STATIC_INLINE(void)
250  const afw_log_t * instance,
251  afw_log_priority_t priority,
252  const afw_utf8_z_t * source_z,
253  afw_xctx_t *xctx,
254  const afw_utf8_z_t * format_z,
255  ...)
256 {
257  va_list ap;
258 
259  va_start(ap, format_z);
260  afw_log_write_vz(instance, priority, source_z, format_z,
261  ap, xctx);
262  va_end(ap);
263 }
264 
265 
272 
273 
274 
281 
282 
283 
289 AFW_DECLARE(void)
291  const afw_log_t * instance,
292  afw_xctx_t *xctx);
293 
294 
295 /*
296  * @brief Set a log's mask and insure env->mask is correct.
297  * @param instance
298  * @param mask
299  * @param xctx of caller.
300  */
301 AFW_DECLARE(void)
302 afw_log_set_mask(
303  const afw_log_t * instance,
305  afw_xctx_t *xctx);
306 
307 
308 AFW_END_DECLARES
309 
312 #endif /* __AFW_LOG_H__ */
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
_Bool afw_boolean_t
Definition: afw_common.h:373
int afw_log_priority_mask_t
Definition: afw_common.h:659
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
enum afw_log_priority_e afw_log_priority_t
Log levels. See afw_log.h for more information.
#define afw_log_write(instance, priority, source_z, message, xctx)
Call method write of interface afw_log.
void afw_log_write_fz(const afw_log_t *instance, afw_log_priority_t priority, const afw_utf8_z_t *source_z, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...)
Log an message using a printf style format and parameters.
Definition: afw_log.h:249
void afw_log_add_to_environment(const afw_log_t *instance, afw_xctx_t *xctx)
Add a log to the list of logs called by environment log.
Definition: afw_log.c:290
void afw_log_write_z(const afw_log_t *instance, afw_log_priority_t priority, const afw_utf8_z_t *source_z, const afw_utf8_z_t *message_z, afw_xctx_t *xctx)
Log an afw_utf8_z_t message.
Definition: afw_log.h:206
void afw_log_write_vz(const afw_log_t *instance, afw_log_priority_t priority, const afw_utf8_z_t *source_z, const afw_utf8_z_t *format_z, va_list ap, afw_xctx_t *xctx)
Log an message using a printf style format and va_list.
Definition: afw_log.c:374
const afw_utf8_t * afw_log_priority_to_priority_id(afw_log_priority_t priority)
Convert a log priority to priority id.
Definition: afw_log.c:273
afw_log_priority_t afw_log_priority_id_to_priority(const afw_utf8_t *priority_id)
Convert a log priority id to priority.
Definition: afw_log.c:258
void afw_log_set_priority_in_mask(afw_log_priority_mask_t *mask, afw_log_priority_t priority, afw_boolean_t value)
Set the corresponding bit for a priority in a mask.
Definition: afw_log.h:138
const afw_log_factory_t * afw_log_standard_factory_get()
Get the factory for log type standard.
const afw_log_priority_id_map_entry_t * afw_log_get_priority_id_map()
Definition: afw_log.c:250
afw_boolean_t afw_log_priority_in_mask(afw_log_priority_mask_t mask, afw_log_priority_t priority)
Determined if log priority corresponding bit is on in mask.
Definition: afw_log.h:124
const afw_log_factory_t * afw_log_file_factory_get()
Get the factory for log type file.
Definition: afw_log_file.c:45
afw_log_priority_mask_t afw_log_up_to_priority_mask(afw_log_priority_t priority)
Get the priority mask for all equal or higher log priorities.
Definition: afw_log.h:111
struct afw_log_priority_id_map_entry_s afw_log_priority_id_map_entry_t
afw_log_priority_mask_t afw_log_priority_mask(afw_log_priority_t priority)
Get the priority mask for a log priority.
Definition: afw_log.h:99
Interface afw_log_factory public struct.
Definition: afw_log.h:61
Interface afw_log public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.