@@ -73,6 +73,8 @@ typedef struct {
7373 ulog_level_names names ; // level names
7474} ulog_level_descriptor ;
7575
76+ #if ULOG_BUILD_DISABLED != 1
77+
7678/// @brief Returns the string representation of the log level
7779/// @param level Log level to convert
7880/// @return String representation of the level, or "?" for invalid levels
@@ -87,6 +89,8 @@ ulog_status ulog_level_set_new_levels(const ulog_level_descriptor *new_levels);
8789/// @return ulog_status
8890ulog_status ulog_level_reset_levels (void );
8991
92+ #endif // ULOG_BUILD_DISABLED != 1
93+
9094/* ============================================================================
9195 Feature: Topics (1/2)
9296============================================================================ */
@@ -104,6 +108,8 @@ enum {
104108/// @brief Event structure (opaque)
105109typedef struct ulog_event ulog_event ;
106110
111+ #if ULOG_BUILD_DISABLED != 1
112+
107113/// @brief Write event content to a buffer as a log message
108114/// @param ev Event to convert
109115/// @param out Output buffer to write to
@@ -147,6 +153,8 @@ ulog_level ulog_event_get_level(ulog_event *ev);
147153/// or time feature disabled
148154struct tm * ulog_event_get_time (ulog_event * ev );
149155
156+ #endif // ULOG_BUILD_DISABLED != 1
157+
150158/* ============================================================================
151159 Core: Thread Safety
152160============================================================================ */
@@ -156,6 +164,8 @@ struct tm *ulog_event_get_time(ulog_event *ev);
156164/// @param lock_arg User-provided argument passed during registration
157165typedef ulog_status (* ulog_lock_fn )(bool lock , void * lock_arg );
158166
167+ #if ULOG_BUILD_DISABLED != 1
168+
159169/// @brief Sets the thread synchronization lock function
160170/// @param function Lock function to use, or NULL to disable locking
161171/// @param lock_arg User argument passed to the lock function
@@ -195,12 +205,16 @@ ulog_status ulog_source_location_config(bool enabled);
195205/// acquired
196206ulog_status ulog_time_config (bool enabled );
197207
208+ #endif // ULOG_BUILD_DISABLED != 1
209+
198210/// @brief Log level configuration styles
199211typedef enum {
200212 ULOG_LEVEL_CONFIG_STYLE_DEFAULT = 0 , /// Use default style (e.g. `DEBUG`)
201213 ULOG_LEVEL_CONFIG_STYLE_SHORT , /// Use short style (e.g. `D`)
202214} ulog_level_config_style ;
203215
216+ #if ULOG_BUILD_DISABLED != 1
217+
204218/// @brief Configure level string format (requires ULOG_BUILD_DYNAMIC_CONFIG=1)
205219/// @param style Level configuration style
206220/// @return ULOG_STATUS_OK on success, ULOG_STATUS_BUSY if lock cannot be
@@ -214,6 +228,8 @@ ulog_status ulog_level_config(ulog_level_config_style style);
214228/// acquired
215229ulog_status ulog_topic_config (bool enabled );
216230
231+ #endif // ULOG_BUILD_DISABLED != 1
232+
217233/* ============================================================================
218234 Feature: Prefix
219235============================================================================ */
@@ -226,13 +242,17 @@ ulog_status ulog_topic_config(bool enabled);
226242typedef void (* ulog_prefix_fn )(ulog_event * ev , char * prefix ,
227243 size_t prefix_size );
228244
245+ #if ULOG_BUILD_DISABLED != 1
246+
229247/// @brief Sets the custom prefix generation function (requires
230248/// ULOG_BUILD_PREFIX_SIZE>0 or ULOG_BUILD_DYNAMIC_CONFIG=1)
231249/// @param function Handler function to generate prefix, or NULL to disable
232250/// @return ULOG_STATUS_OK on success, ULOG_STATUS_BUSY if lock cannot be
233251/// acquired, ULOG_STATUS_INVALID_ARGUMENT if function is NULL
234252ulog_status ulog_prefix_set_fn (ulog_prefix_fn function );
235253
254+ #endif // ULOG_BUILD_DISABLED != 1
255+
236256/* ============================================================================
237257 Feature: Output
238258============================================================================ */
@@ -250,6 +270,8 @@ enum {
250270/// @param arg User-provided argument passed during handler registration
251271typedef void (* ulog_output_handler_fn )(ulog_event * ev , void * arg );
252272
273+ #if ULOG_BUILD_DISABLED != 1
274+
253275/// @brief Sets the minimum log level for a specific output
254276/// @param output Output handle to configure
255277/// @param level Minimum log level for this output
@@ -286,6 +308,8 @@ ulog_output_id ulog_output_add_file(FILE *file, ulog_level level);
286308/// handle, ULOG_STATUS_NOT_FOUND if output not found
287309ulog_status ulog_output_remove (ulog_output_id output );
288310
311+ #endif // ULOG_BUILD_DISABLED != 1
312+
289313/* ============================================================================
290314 Feature: Topics (2/2)
291315============================================================================ */
@@ -297,6 +321,8 @@ ulog_status ulog_output_remove(ulog_output_id output);
297321#define ULOG_BUILD_TOPICS_MODE_STATIC 1
298322#define ULOG_BUILD_TOPICS_MODE_DYNAMIC 2
299323
324+ #if ULOG_BUILD_DISABLED != 1
325+
300326/// @brief Alias: `ulog_t`. Log a message with topic (requires ULOG_BUILD_TOPICS!=0 or
301327/// ULOG_BUILD_DYNAMIC_CONFIG=1)
302328/// @param LEVEL Log level
@@ -428,6 +454,8 @@ void ulog_log(ulog_level level, const char *file,
428454/// @brief Clean up all topic, outputs and other dynamic resources
429455ulog_status ulog_cleanup (void );
430456
457+ #endif // ULOG_BUILD_DISABLED != 1
458+
431459/* ============================================================================
432460 Optional Feature: Disable
433461============================================================================ */
@@ -436,125 +464,103 @@ ulog_status ulog_cleanup(void);
436464
437465// If logging is disabled, replace all functions with zero-overhead inline functions
438466#if defined(__GNUC__ ) || defined(__clang__ ) || defined(__TI_COMPILER_VERSION__ )
439- #define ULOG_INLINE inline __attribute__((always_inline))
467+ #define ULOG_STATIC_INLINE static inline __attribute__((always_inline))
440468#elif defined(_MSC_VER )
441- #define ULOG_INLINE __forceinline
469+ #define ULOG_STATIC_INLINE static __forceinline
442470#elif defined(__IAR_SYSTEMS_ICC__ )
443- #define ULOG_INLINE _Pragma("inline=forced") inline
471+ #define ULOG_STATIC_INLINE static inline _Pragma("inline=forced")
444472#else
445- #define ULOG_INLINE inline
473+ #define ULOG_STATIC_INLINE static inline
446474#endif
447475
448476// clang-format off
449- ULOG_INLINE ulog_status ulog_cleanup (void )
477+ ULOG_STATIC_INLINE ulog_status ulog_cleanup (void )
450478 { return ULOG_STATUS_DISABLED ; }
451479
452- ULOG_INLINE ulog_status ulog_color_config (bool enabled )
480+ ULOG_STATIC_INLINE ulog_status ulog_color_config (bool enabled )
453481 { (void )enabled ; return ULOG_STATUS_DISABLED ; }
454482
455- ULOG_INLINE const char * ulog_event_get_file (ulog_event * ev )
483+ ULOG_STATIC_INLINE const char * ulog_event_get_file (ulog_event * ev )
456484 { (void )ev ; return "" ; }
457485
458- ULOG_INLINE ulog_level ulog_event_get_level (ulog_event * ev )
486+ ULOG_STATIC_INLINE ulog_level ulog_event_get_level (ulog_event * ev )
459487 { (void )ev ; return ULOG_LEVEL_0 ; }
460488
461- ULOG_INLINE int ulog_event_get_line (ulog_event * ev )
489+ ULOG_STATIC_INLINE int ulog_event_get_line (ulog_event * ev )
462490 { (void )ev ; return -1 ; }
463491
464- ULOG_INLINE ulog_status ulog_event_get_message (ulog_event * ev , char * buffer , size_t buffer_size )
492+ ULOG_STATIC_INLINE ulog_status ulog_event_get_message (ulog_event * ev , char * buffer , size_t buffer_size )
465493 { (void )ev ; (void )buffer ; (void )buffer_size ; return ULOG_STATUS_DISABLED ; }
466494
467- ULOG_INLINE struct tm * ulog_event_get_time (ulog_event * ev )
495+ ULOG_STATIC_INLINE struct tm * ulog_event_get_time (ulog_event * ev )
468496 { (void )ev ; return NULL ; }
469497
470- ULOG_INLINE ulog_topic_id ulog_event_get_topic (ulog_event * ev )
498+ ULOG_STATIC_INLINE ulog_topic_id ulog_event_get_topic (ulog_event * ev )
471499 { (void )ev ; return ULOG_TOPIC_ID_INVALID ; }
472500
473- ULOG_INLINE ulog_status ulog_event_to_cstr (ulog_event * ev , char * out , size_t out_size )
501+ ULOG_STATIC_INLINE ulog_status ulog_event_to_cstr (ulog_event * ev , char * out , size_t out_size )
474502 { (void )ev ; (void )out ; (void )out_size ; return ULOG_STATUS_DISABLED ; }
475503
476- ULOG_INLINE ulog_status ulog_level_config (ulog_level_config_style style )
504+ ULOG_STATIC_INLINE ulog_status ulog_level_config (ulog_level_config_style style )
477505 { (void )style ; return ULOG_STATUS_DISABLED ; }
478506
479- ULOG_INLINE ulog_status ulog_level_reset_levels (void )
507+ ULOG_STATIC_INLINE ulog_status ulog_level_reset_levels (void )
480508 { return ULOG_STATUS_DISABLED ; }
481509
482- ULOG_INLINE ulog_status ulog_level_set_new_levels (const ulog_level_descriptor * new_levels )
510+ ULOG_STATIC_INLINE ulog_status ulog_level_set_new_levels (const ulog_level_descriptor * new_levels )
483511 { (void )new_levels ; return ULOG_STATUS_DISABLED ; }
484512
485- ULOG_INLINE const char * ulog_level_to_string (ulog_level level )
513+ ULOG_STATIC_INLINE const char * ulog_level_to_string (ulog_level level )
486514 { (void )level ; return "?" ; }
487515
488- ULOG_INLINE ulog_status ulog_lock_set_fn (ulog_lock_fn function , void * lock_arg )
516+ ULOG_STATIC_INLINE ulog_status ulog_lock_set_fn (ulog_lock_fn function , void * lock_arg )
489517 { (void )function ; (void )lock_arg ; return ULOG_STATUS_DISABLED ; }
490518
491- ULOG_INLINE void ulog_log (ulog_level level , const char * file , int line , const char * topic , const char * message , ...)
519+ ULOG_STATIC_INLINE void ulog_log (ulog_level level , const char * file , int line , const char * topic , const char * message , ...)
492520 { (void )level ; (void )file ; (void )line ; (void )topic ; (void )message ; }
493521
494- ULOG_INLINE ulog_output_id ulog_output_add (ulog_output_handler_fn handler , void * arg , ulog_level level )
522+ ULOG_STATIC_INLINE ulog_output_id ulog_output_add (ulog_output_handler_fn handler , void * arg , ulog_level level )
495523 { (void )handler ; (void )arg ; (void )level ; return ULOG_OUTPUT_INVALID ; }
496524
497- ULOG_INLINE ulog_output_id ulog_output_add_file (FILE * file , ulog_level level )
525+ ULOG_STATIC_INLINE ulog_output_id ulog_output_add_file (FILE * file , ulog_level level )
498526 { (void )file ; (void )level ; return ULOG_OUTPUT_INVALID ; }
499527
500- ULOG_INLINE ulog_status ulog_output_level_set (ulog_output_id output , ulog_level level )
528+ ULOG_STATIC_INLINE ulog_status ulog_output_level_set (ulog_output_id output , ulog_level level )
501529 { (void )output ; (void )level ; return ULOG_STATUS_DISABLED ; }
502530
503- ULOG_INLINE ulog_status ulog_output_level_set_all (ulog_level level )
531+ ULOG_STATIC_INLINE ulog_status ulog_output_level_set_all (ulog_level level )
504532 { (void )level ; return ULOG_STATUS_DISABLED ; }
505533
506- ULOG_INLINE ulog_status ulog_output_remove (ulog_output_id output )
534+ ULOG_STATIC_INLINE ulog_status ulog_output_remove (ulog_output_id output )
507535 { (void )output ; return ULOG_STATUS_DISABLED ; }
508536
509- ULOG_INLINE ulog_status ulog_prefix_config (bool enabled )
537+ ULOG_STATIC_INLINE ulog_status ulog_prefix_config (bool enabled )
510538 { (void )enabled ; return ULOG_STATUS_DISABLED ; }
511539
512- ULOG_INLINE ulog_status ulog_prefix_set_fn (ulog_prefix_fn function )
540+ ULOG_STATIC_INLINE ulog_status ulog_prefix_set_fn (ulog_prefix_fn function )
513541 { (void )function ; return ULOG_STATUS_DISABLED ; }
514542
515- ULOG_INLINE ulog_status ulog_source_location_config (bool enabled )
543+ ULOG_STATIC_INLINE ulog_status ulog_source_location_config (bool enabled )
516544 { (void )enabled ; return ULOG_STATUS_DISABLED ; }
517545
518- ULOG_INLINE ulog_status ulog_time_config (bool enabled )
546+ ULOG_STATIC_INLINE ulog_status ulog_time_config (bool enabled )
519547 { (void )enabled ; return ULOG_STATUS_DISABLED ; }
520548
521- ULOG_INLINE ulog_topic_id ulog_topic_add (const char * topic_name , ulog_output_id output , ulog_level level )
549+ ULOG_STATIC_INLINE ulog_topic_id ulog_topic_add (const char * topic_name , ulog_output_id output , ulog_level level )
522550 { (void )topic_name ; (void )output ; (void )level ; return ULOG_TOPIC_ID_INVALID ; }
523551
524- ULOG_INLINE ulog_status ulog_topic_config (bool enabled )
552+ ULOG_STATIC_INLINE ulog_status ulog_topic_config (bool enabled )
525553 { (void )enabled ; return ULOG_STATUS_DISABLED ; }
526554
527- ULOG_INLINE ulog_topic_id ulog_topic_get_id (const char * topic_name )
555+ ULOG_STATIC_INLINE ulog_topic_id ulog_topic_get_id (const char * topic_name )
528556 { (void )topic_name ; return ULOG_TOPIC_ID_INVALID ; }
529557
530- ULOG_INLINE ulog_status ulog_topic_level_set (const char * topic_name , ulog_level level )
558+ ULOG_STATIC_INLINE ulog_status ulog_topic_level_set (const char * topic_name , ulog_level level )
531559 { (void )topic_name ; (void )level ; return ULOG_STATUS_DISABLED ; }
532560
533- ULOG_INLINE ulog_status ulog_topic_remove (const char * topic_name )
561+ ULOG_STATIC_INLINE ulog_status ulog_topic_remove (const char * topic_name )
534562 { (void )topic_name ; return ULOG_STATUS_DISABLED ; }
535563
536- // Redefine logging macros to be no-ops when disabled
537- #undef ulog_trace
538- #undef ulog_debug
539- #undef ulog_info
540- #undef ulog_warn
541- #undef ulog_error
542- #undef ulog_fatal
543- #undef ulog
544- #undef ulog_topic_trace
545- #undef ulog_topic_debug
546- #undef ulog_topic_info
547- #undef ulog_topic_warn
548- #undef ulog_topic_error
549- #undef ulog_topic_fatal
550- #undef ulog_topic_log
551- #undef ulog_t_trace
552- #undef ulog_t_debug
553- #undef ulog_t_info
554- #undef ulog_t_warn
555- #undef ulog_t_error
556- #undef ulog_t_fatal
557- #undef ulog_t
558564#define ulog_trace (...) ((void)0)
559565#define ulog_debug (...) ((void)0)
560566#define ulog_info (...) ((void)0)
@@ -577,7 +583,7 @@ ULOG_INLINE ulog_status ulog_topic_remove(const char *topic_name)
577583#define ulog_t_fatal (...) ((void)0)
578584#define ulog_t (...) ((void)0)
579585
580- #undef ULOG_INLINE // not to expose it
586+ #undef ULOG_STATIC_INLINE // not to expose it
581587// clang-format on
582588#endif // ULOG_BUILD_DISABLED
583589
0 commit comments