All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
le_log.h
Go to the documentation of this file.
1 
348 #ifndef LEGATO_LOG_INCLUDE_GUARD
349 #define LEGATO_LOG_INCLUDE_GUARD
350 
351 //--------------------------------------------------------------------------------------------------
355 //--------------------------------------------------------------------------------------------------
356 typedef enum
357 {
362  LE_LOG_CRIT,
364  LE_LOG_EMERG
366 }
368 
369 
370 //--------------------------------------------------------------------------------------------------
372 
373 typedef struct le_log_Session* le_log_SessionRef_t;
374 
375 typedef struct le_log_Trace* le_log_TraceRef_t;
376 
377 void _le_log_Send
378 (
379  const le_log_Level_t level,
380  const le_log_TraceRef_t traceRef,
381  le_log_SessionRef_t logSession,
382  const char* filenamePtr,
383  const char* functionNamePtr,
384  const unsigned int lineNumber,
385  const char* formatPtr,
386  ...
387 ) __attribute__ ((format (printf, 7, 8)));
388 
389 le_log_TraceRef_t _le_log_GetTraceRef
390 (
391  le_log_SessionRef_t logSession,
392  const char* keyword
393 );
394 
395 void _le_log_SetFilterLevel
396 (
397  le_log_SessionRef_t logSession,
398  le_log_Level_t level
399 );
400 
401 
402 //--------------------------------------------------------------------------------------------------
409 //--------------------------------------------------------------------------------------------------
410 #ifdef __cplusplus
411 extern
412 #endif
413 le_log_SessionRef_t LE_LOG_SESSION;
414 
415 //--------------------------------------------------------------------------------------------------
422 //--------------------------------------------------------------------------------------------------
423 #ifdef __cplusplus
424 extern
425 #endif
426 le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
427 
428 
430 //--------------------------------------------------------------------------------------------------
431 
432 //--------------------------------------------------------------------------------------------------
436 //--------------------------------------------------------------------------------------------------
437 #define _LE_LOG_MSG(level, formatString, ...) \
438  do { \
439  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
440  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
441  formatString, ##__VA_ARGS__); \
442  } while(0)
443 
444 
445 //--------------------------------------------------------------------------------------------------
452 //--------------------------------------------------------------------------------------------------
453 
455 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
456 
457 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
458 
459 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
460 
461 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
462 
463 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
464 
465 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
466 
467 
468 //--------------------------------------------------------------------------------------------------
477 //--------------------------------------------------------------------------------------------------
478 
480 #define LE_DEBUG_IF(condition, formatString, ...) \
481  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__); }
482 
483 #define LE_INFO_IF(condition, formatString, ...) \
484  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__); }
485 
486 #define LE_WARN_IF(condition, formatString, ...) \
487  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__); }
488 
489 #define LE_ERROR_IF(condition, formatString, ...) \
490  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__); }
491 
492 #define LE_CRIT_IF(condition, formatString, ...) \
493  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__); }
494 
495 #define LE_EMERG_IF(condition, formatString, ...) \
496  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__); }
497 
498 
499 //--------------------------------------------------------------------------------------------------
507 //--------------------------------------------------------------------------------------------------
508 #define LE_FATAL(formatString, ...) \
509  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
510 
511 
512 //--------------------------------------------------------------------------------------------------
520 //--------------------------------------------------------------------------------------------------
521 #define LE_FATAL_IF(condition, formatString, ...) \
522  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
523 
524 
525 //--------------------------------------------------------------------------------------------------
530 //--------------------------------------------------------------------------------------------------
531 #define LE_ASSERT(condition) \
532  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
533 
534 
535 //--------------------------------------------------------------------------------------------------
546 //--------------------------------------------------------------------------------------------------
547 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
548 
550 const char* _le_log_GetResultCodeString
551 (
552  le_result_t resultCode
553 );
554 
555 
556 //--------------------------------------------------------------------------------------------------
564 //--------------------------------------------------------------------------------------------------
565 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
566 
567 
568 //--------------------------------------------------------------------------------------------------
572 //--------------------------------------------------------------------------------------------------
573 #define LE_TRACE(traceRef, string, ...) \
574  if (le_log_IsTraceEnabled(traceRef)) \
575  { \
576  _le_log_Send(-1, traceRef, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
577  string, ##__VA_ARGS__); \
578  }
579 
580 
581 //--------------------------------------------------------------------------------------------------
587 //--------------------------------------------------------------------------------------------------
588 static inline le_log_TraceRef_t le_log_GetTraceRef
589 (
590  const char* keywordPtr
591 )
592 {
593  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
594 }
595 
596 
597 //--------------------------------------------------------------------------------------------------
603 //--------------------------------------------------------------------------------------------------
604 static inline bool le_log_IsTraceEnabled
605 (
606  const le_log_TraceRef_t traceRef
607 )
608 {
609  return *((bool*)traceRef);
610 }
611 
612 
613 //--------------------------------------------------------------------------------------------------
621 //--------------------------------------------------------------------------------------------------
622 static inline void le_log_SetFilterLevel
623 (
624  le_log_Level_t level
625 )
626 {
627  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
628 }
629 
630 
631 //--------------------------------------------------------------------------------------------------
635 //--------------------------------------------------------------------------------------------------
637 (
638  void
639 )
640 {
641  if (LE_LOG_LEVEL_FILTER_PTR != NULL)
642  {
643  return *LE_LOG_LEVEL_FILTER_PTR;
644  }
645  else
646  {
647  return LE_LOG_INFO; // Default.
648  }
649 }
650 
651 
652 //--------------------------------------------------------------------------------------------------
659 //--------------------------------------------------------------------------------------------------
660 static inline void le_log_EnableTrace
661 (
662  const le_log_TraceRef_t traceRef
663 )
664 {
665  *((bool*)traceRef) = true;
666 }
667 
668 
669 //--------------------------------------------------------------------------------------------------
676 //--------------------------------------------------------------------------------------------------
677 static inline void le_log_DisableTrace
678 (
679  const le_log_TraceRef_t traceRef
680 )
681 {
682  *((bool*)traceRef) = false;
683 }
684 
685 
686 
687 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:589
le_result_t
Definition: le_basics.h:35
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:661
static le_log_Level_t le_log_GetFilterLevel(void)
Definition: le_log.h:637
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:360
le_log_Level_t
Definition: le_log.h:356
Debug message.
Definition: le_log.h:358
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:623
Definition: le_log.h:361
const char * _le_log_GetResultCodeString(le_result_t resultCode)
Function that does the real work of translating result codes. See LE_RESULT_TXT.
Definition: le_log.h:363
Informational message. Normally expected.
Definition: le_log.h:359
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:365
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:605
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:678