le_log.h
Go to the documentation of this file.
1 
369 #ifndef LEGATO_LOG_INCLUDE_GUARD
370 #define LEGATO_LOG_INCLUDE_GUARD
371 
372 //--------------------------------------------------------------------------------------------------
376 //--------------------------------------------------------------------------------------------------
377 typedef enum
378 {
383  LE_LOG_CRIT,
385  LE_LOG_EMERG
387 }
389 
390 
391 //--------------------------------------------------------------------------------------------------
393 
394 typedef struct le_log_Session* le_log_SessionRef_t;
395 
396 typedef struct le_log_Trace* le_log_TraceRef_t;
397 
398 void _le_log_Send
399 (
400  const le_log_Level_t level,
401  const le_log_TraceRef_t traceRef,
402  le_log_SessionRef_t logSession,
403  const char* filenamePtr,
404  const char* functionNamePtr,
405  const unsigned int lineNumber,
406  const char* formatPtr,
407  ...
408 ) __attribute__ ((format (printf, 7, 8)));
409 
410 le_log_TraceRef_t _le_log_GetTraceRef
411 (
412  le_log_SessionRef_t logSession,
413  const char* keyword
414 );
415 
416 void _le_log_SetFilterLevel
417 (
418  le_log_SessionRef_t logSession,
419  le_log_Level_t level
420 );
421 
422 
423 //--------------------------------------------------------------------------------------------------
430 //--------------------------------------------------------------------------------------------------
431 #ifdef __cplusplus
432 extern
433 #endif
434 LE_SHARED le_log_SessionRef_t LE_LOG_SESSION;
435 
436 //--------------------------------------------------------------------------------------------------
443 //--------------------------------------------------------------------------------------------------
444 #ifdef __cplusplus
445 extern
446 #endif
447 LE_SHARED le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
448 
449 
451 //--------------------------------------------------------------------------------------------------
452 
453 //--------------------------------------------------------------------------------------------------
457 //--------------------------------------------------------------------------------------------------
458 #define _LE_LOG_MSG(level, formatString, ...) \
459  do { \
460  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
461  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
462  formatString, ##__VA_ARGS__); \
463  } while(0)
464 
465 
466 //--------------------------------------------------------------------------------------------------
473 //--------------------------------------------------------------------------------------------------
474 
476 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
477 
478 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
479 
480 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
481 
482 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
483 
484 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
485 
486 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
487 
488 
489 //--------------------------------------------------------------------------------------------------
498 //--------------------------------------------------------------------------------------------------
499 
501 #define LE_DEBUG_IF(condition, formatString, ...) \
502  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__); }
503 
504 #define LE_INFO_IF(condition, formatString, ...) \
505  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__); }
506 
507 #define LE_WARN_IF(condition, formatString, ...) \
508  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__); }
509 
510 #define LE_ERROR_IF(condition, formatString, ...) \
511  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__); }
512 
513 #define LE_CRIT_IF(condition, formatString, ...) \
514  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__); }
515 
516 #define LE_EMERG_IF(condition, formatString, ...) \
517  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__); }
518 
519 
520 //--------------------------------------------------------------------------------------------------
528 //--------------------------------------------------------------------------------------------------
529 #define LE_FATAL(formatString, ...) \
530  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
531 
532 
533 //--------------------------------------------------------------------------------------------------
541 //--------------------------------------------------------------------------------------------------
542 #define LE_FATAL_IF(condition, formatString, ...) \
543  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
544 
545 
546 //--------------------------------------------------------------------------------------------------
551 //--------------------------------------------------------------------------------------------------
552 #define LE_ASSERT(condition) \
553  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
554 
555 
556 //--------------------------------------------------------------------------------------------------
567 //--------------------------------------------------------------------------------------------------
568 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
569 
571 const char* _le_log_GetResultCodeString
572 (
573  le_result_t resultCode
574 );
575 
576 
577 //--------------------------------------------------------------------------------------------------
585 //--------------------------------------------------------------------------------------------------
586 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
587 
588 
589 //--------------------------------------------------------------------------------------------------
593 //--------------------------------------------------------------------------------------------------
594 #define LE_TRACE(traceRef, string, ...) \
595  if (le_log_IsTraceEnabled(traceRef)) \
596  { \
597  _le_log_Send((le_log_Level_t)-1, \
598  traceRef, \
599  LE_LOG_SESSION, \
600  __FILE__, \
601  __func__, \
602  __LINE__, \
603  string, \
604  ##__VA_ARGS__); \
605  }
606 
607 
608 //--------------------------------------------------------------------------------------------------
614 //--------------------------------------------------------------------------------------------------
615 static inline le_log_TraceRef_t le_log_GetTraceRef
616 (
617  const char* keywordPtr
618 )
619 {
620  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
621 }
622 
623 
624 //--------------------------------------------------------------------------------------------------
630 //--------------------------------------------------------------------------------------------------
631 static inline bool le_log_IsTraceEnabled
632 (
633  const le_log_TraceRef_t traceRef
634 )
635 {
636  return *((bool*)traceRef);
637 }
638 
639 
640 //--------------------------------------------------------------------------------------------------
648 //--------------------------------------------------------------------------------------------------
649 static inline void le_log_SetFilterLevel
650 (
651  le_log_Level_t level
652 )
653 {
654  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
655 }
656 
657 
658 //--------------------------------------------------------------------------------------------------
662 //--------------------------------------------------------------------------------------------------
664 (
665  void
666 )
667 {
668  if (LE_LOG_LEVEL_FILTER_PTR != NULL)
669  {
670  return *LE_LOG_LEVEL_FILTER_PTR;
671  }
672  else
673  {
674  return LE_LOG_INFO; // Default.
675  }
676 }
677 
678 
679 //--------------------------------------------------------------------------------------------------
686 //--------------------------------------------------------------------------------------------------
687 static inline void le_log_EnableTrace
688 (
689  const le_log_TraceRef_t traceRef
690 )
691 {
692  *((bool*)traceRef) = true;
693 }
694 
695 
696 //--------------------------------------------------------------------------------------------------
703 //--------------------------------------------------------------------------------------------------
704 static inline void le_log_DisableTrace
705 (
706  const le_log_TraceRef_t traceRef
707 )
708 {
709  *((bool*)traceRef) = false;
710 }
711 
712 
713 
714 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:616
#define LE_SHARED
Definition: le_basics.h:239
le_result_t
Definition: le_basics.h:35
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:688
static le_log_Level_t le_log_GetFilterLevel(void)
Definition: le_log.h:664
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:381
le_log_Level_t
Definition: le_log.h:377
Debug message.
Definition: le_log.h:379
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:650
Definition: le_log.h:382
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:384
Informational message. Normally expected.
Definition: le_log.h:380
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:386
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:632
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:705