le_log.h
Go to the documentation of this file.
1 
373 #ifndef LEGATO_LOG_INCLUDE_GUARD
374 #define LEGATO_LOG_INCLUDE_GUARD
375 
376 //--------------------------------------------------------------------------------------------------
380 //--------------------------------------------------------------------------------------------------
381 typedef enum
382 {
387  LE_LOG_CRIT,
389  LE_LOG_EMERG
391 }
393 
394 
395 //--------------------------------------------------------------------------------------------------
397 
398 typedef struct le_log_Session* le_log_SessionRef_t;
399 
400 typedef struct le_log_Trace* le_log_TraceRef_t;
401 
402 void _le_log_Send
403 (
404  const le_log_Level_t level,
405  const le_log_TraceRef_t traceRef,
406  le_log_SessionRef_t logSession,
407  const char* filenamePtr,
408  const char* functionNamePtr,
409  const unsigned int lineNumber,
410  const char* formatPtr,
411  ...
412 ) __attribute__ ((format (printf, 7, 8)));
413 
414 le_log_TraceRef_t _le_log_GetTraceRef
415 (
416  le_log_SessionRef_t logSession,
417  const char* keyword
418 );
419 
420 void _le_log_SetFilterLevel
421 (
422  le_log_SessionRef_t logSession,
423  le_log_Level_t level
424 );
425 
426 
427 //--------------------------------------------------------------------------------------------------
434 //--------------------------------------------------------------------------------------------------
435 #ifdef __cplusplus
436 extern
437 #endif
438 LE_SHARED le_log_SessionRef_t LE_LOG_SESSION;
439 
440 //--------------------------------------------------------------------------------------------------
447 //--------------------------------------------------------------------------------------------------
448 #ifdef __cplusplus
449 extern
450 #endif
451 LE_SHARED le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
452 
453 
455 //--------------------------------------------------------------------------------------------------
456 
457 //--------------------------------------------------------------------------------------------------
461 //--------------------------------------------------------------------------------------------------
462 #define _LE_LOG_MSG(level, formatString, ...) \
463  do { \
464  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
465  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
466  formatString, ##__VA_ARGS__); \
467  } while(0)
468 
469 
470 //--------------------------------------------------------------------------------------------------
477 //--------------------------------------------------------------------------------------------------
478 
480 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
481 
482 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
483 
484 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
485 
486 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
487 
488 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
489 
490 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
491 
492 
493 //--------------------------------------------------------------------------------------------------
502 //--------------------------------------------------------------------------------------------------
503 
505 #define LE_DEBUG_IF(condition, formatString, ...) \
506  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__); }
507 
508 #define LE_INFO_IF(condition, formatString, ...) \
509  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__); }
510 
511 #define LE_WARN_IF(condition, formatString, ...) \
512  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__); }
513 
514 #define LE_ERROR_IF(condition, formatString, ...) \
515  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__); }
516 
517 #define LE_CRIT_IF(condition, formatString, ...) \
518  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__); }
519 
520 #define LE_EMERG_IF(condition, formatString, ...) \
521  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__); }
522 
523 
524 //--------------------------------------------------------------------------------------------------
532 //--------------------------------------------------------------------------------------------------
533 #define LE_FATAL(formatString, ...) \
534  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
535 
536 
537 //--------------------------------------------------------------------------------------------------
545 //--------------------------------------------------------------------------------------------------
546 #define LE_FATAL_IF(condition, formatString, ...) \
547  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
548 
549 
550 //--------------------------------------------------------------------------------------------------
555 //--------------------------------------------------------------------------------------------------
556 #define LE_ASSERT(condition) \
557  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
558 
559 
560 //--------------------------------------------------------------------------------------------------
565 //--------------------------------------------------------------------------------------------------
566 #define LE_ASSERT_OK(condition) \
567  if ((condition) != LE_OK) { LE_FATAL("Assert Failed: '%s' is not LE_OK (0)", #condition) }
568 
569 
570 //--------------------------------------------------------------------------------------------------
581 //--------------------------------------------------------------------------------------------------
582 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
583 
585 const char* _le_log_GetResultCodeString
586 (
587  le_result_t resultCode
588 );
589 
590 
591 //--------------------------------------------------------------------------------------------------
599 //--------------------------------------------------------------------------------------------------
600 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
601 
602 
603 //--------------------------------------------------------------------------------------------------
607 //--------------------------------------------------------------------------------------------------
608 #define LE_TRACE(traceRef, string, ...) \
609  if (le_log_IsTraceEnabled(traceRef)) \
610  { \
611  _le_log_Send((le_log_Level_t)-1, \
612  traceRef, \
613  LE_LOG_SESSION, \
614  __FILE__, \
615  __func__, \
616  __LINE__, \
617  string, \
618  ##__VA_ARGS__); \
619  }
620 
621 
622 //--------------------------------------------------------------------------------------------------
628 //--------------------------------------------------------------------------------------------------
629 static inline le_log_TraceRef_t le_log_GetTraceRef
630 (
631  const char* keywordPtr
632 )
633 {
634  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
635 }
636 
637 
638 //--------------------------------------------------------------------------------------------------
644 //--------------------------------------------------------------------------------------------------
645 static inline bool le_log_IsTraceEnabled
646 (
647  const le_log_TraceRef_t traceRef
648 )
649 {
650  return *((bool*)traceRef);
651 }
652 
653 
654 //--------------------------------------------------------------------------------------------------
662 //--------------------------------------------------------------------------------------------------
663 static inline void le_log_SetFilterLevel
664 (
665  le_log_Level_t level
666 )
667 {
668  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
669 }
670 
671 
672 //--------------------------------------------------------------------------------------------------
676 //--------------------------------------------------------------------------------------------------
678 (
679  void
680 )
681 {
682  if (LE_LOG_LEVEL_FILTER_PTR != NULL)
683  {
684  return *LE_LOG_LEVEL_FILTER_PTR;
685  }
686  else
687  {
688  return LE_LOG_INFO; // Default.
689  }
690 }
691 
692 
693 //--------------------------------------------------------------------------------------------------
700 //--------------------------------------------------------------------------------------------------
701 static inline void le_log_EnableTrace
702 (
703  const le_log_TraceRef_t traceRef
704 )
705 {
706  *((bool*)traceRef) = true;
707 }
708 
709 
710 //--------------------------------------------------------------------------------------------------
717 //--------------------------------------------------------------------------------------------------
718 static inline void le_log_DisableTrace
719 (
720  const le_log_TraceRef_t traceRef
721 )
722 {
723  *((bool*)traceRef) = false;
724 }
725 
726 
727 
728 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:630
#define LE_SHARED
Definition: le_basics.h:240
le_result_t
Definition: le_basics.h:35
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:702
static le_log_Level_t le_log_GetFilterLevel(void)
Definition: le_log.h:678
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:385
le_log_Level_t
Definition: le_log.h:381
Debug message.
Definition: le_log.h:383
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:664
Definition: le_log.h:386
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:388
Informational message. Normally expected.
Definition: le_log.h:384
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:390
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:646
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:719