Snapdragon® Telematics Application Framework (TelAF) Interface Specification
le_log.h
Go to the documentation of this file.
1 
366 #ifndef LEGATO_LOG_INCLUDE_GUARD
367 #define LEGATO_LOG_INCLUDE_GUARD
368 
369 //--------------------------------------------------------------------------------------------------
373 //--------------------------------------------------------------------------------------------------
374 typedef enum _le_log_Level_t
375 {
380  LE_LOG_CRIT,
382  LE_LOG_EMERG,
385 }
387 
388 //--------------------------------------------------------------------------------------------------
395 //--------------------------------------------------------------------------------------------------
396 #if LE_CONFIG_LOG_STATIC_FILTER_NO_LOG
397 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_MAX
398 #elif LE_CONFIG_LOG_STATIC_FILTER_EMERG
399 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_EMERG
400 #elif LE_CONFIG_LOG_STATIC_FILTER_CRIT
401 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_CRIT
402 #elif LE_CONFIG_LOG_STATIC_FILTER_ERR
403 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_ERR
404 #elif LE_CONFIG_LOG_STATIC_FILTER_WARN
405 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_WARN
406 #elif LE_CONFIG_LOG_STATIC_FILTER_INFO
407 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_INFO
408 #else /* default to LE_DEBUG */
409 # define LE_LOG_LEVEL_STATIC_FILTER LE_LOG_DEBUG
410 #endif
411 
412 //--------------------------------------------------------------------------------------------------
414 
415 typedef struct le_log_Session* le_log_SessionRef_t;
416 
417 typedef struct le_log_Trace* le_log_TraceRef_t;
418 
419 #if !defined(LE_DEBUG) && \
420  !defined(LE_DUMP) && \
421  !defined(LE_LOG_DUMP) && \
422  !defined(LE_INFO) && \
423  !defined(LE_WARN) && \
424  !defined(LE_ERROR) && \
425  !defined(LE_CRIT) && \
426  !defined(LE_EMERG)
427 
429 # define LE_LOG_DEFAULT_IMPL 1
430 
431 //--------------------------------------------------------------------------------------------------
435 //--------------------------------------------------------------------------------------------------
436 void _le_log_Send
437 (
438  const le_log_Level_t level,
439  const le_log_TraceRef_t traceRef,
440  le_log_SessionRef_t logSession,
441  const char *filenamePtr,
442  const char *functionNamePtr,
443  const unsigned int lineNumber,
444  const char *formatPtr,
445  ...
446 ) __attribute__((format (printf, 7, 8)));
447 
448 //--------------------------------------------------------------------------------------------------
452 //--------------------------------------------------------------------------------------------------
453 void _le_LogData
454 (
455  le_log_Level_t level,
456  const uint8_t *dataPtr,
457  int dataLength,
458  const char *filenamePtr,
459  const char *functionNamePtr,
461  const unsigned int lineNumber
462 );
464 
465 //--------------------------------------------------------------------------------------------------
471 //--------------------------------------------------------------------------------------------------
472 le_log_TraceRef_t _le_log_GetTraceRef
473 (
474  le_log_SessionRef_t logSession,
475  const char *keyword
476 );
477 
478 //--------------------------------------------------------------------------------------------------
482 //--------------------------------------------------------------------------------------------------
483 void _le_log_SetFilterLevel
484 (
485  le_log_SessionRef_t logSession,
486  le_log_Level_t level
487 );
488 
489 //--------------------------------------------------------------------------------------------------
496 //--------------------------------------------------------------------------------------------------
497 extern LE_SHARED le_log_SessionRef_t LE_LOG_SESSION;
498 
499 //--------------------------------------------------------------------------------------------------
506 //--------------------------------------------------------------------------------------------------
507 extern LE_SHARED le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
508 
509 //--------------------------------------------------------------------------------------------------
513 //--------------------------------------------------------------------------------------------------
514 #if LE_CONFIG_LOG_FUNCTION_NAMES
515 # define _LE_LOG_FUNCTION_NAME __func__
516 #else
517 # define _LE_LOG_FUNCTION_NAME NULL
518 #endif
519 
521 //--------------------------------------------------------------------------------------------------
522 
523 //--------------------------------------------------------------------------------------------------
527 //--------------------------------------------------------------------------------------------------
528 #define _LE_LOG_MSG(level, formatString, ...) \
529  do { \
530  if ((level >= LE_LOG_LEVEL_STATIC_FILTER) && \
531  ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR))) \
532  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, _LE_LOG_FUNCTION_NAME, __LINE__, \
533  formatString, ##__VA_ARGS__); \
534  } while(0)
535 
536 
537 //--------------------------------------------------------------------------------------------------
544 //--------------------------------------------------------------------------------------------------
545 
547 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
548 
549 //--------------------------------------------------------------------------------------------------
556 //--------------------------------------------------------------------------------------------------
557 #define LE_DUMP(dataPtr, dataLength) \
558  _le_LogData(LE_LOG_DEBUG, dataPtr, dataLength, STRINGIZE(LE_FILENAME), _LE_LOG_FUNCTION_NAME, \
559  __LINE__)
560 
561 //--------------------------------------------------------------------------------------------------
569 //--------------------------------------------------------------------------------------------------
570 #define LE_LOG_DUMP(level, dataPtr, dataLength) \
571  _le_LogData(level, dataPtr, dataLength, STRINGIZE(LE_FILENAME), _LE_LOG_FUNCTION_NAME, __LINE__)
572 
573 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
574 
575 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
576 
577 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
578 
579 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
580 
581 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
582 
583 
584 //--------------------------------------------------------------------------------------------------
588 //--------------------------------------------------------------------------------------------------
589 #define LE_LOG_CAN_TRACE 1
590 
591 
592 //--------------------------------------------------------------------------------------------------
600 //--------------------------------------------------------------------------------------------------
601 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
602 
603 
604 //--------------------------------------------------------------------------------------------------
608 //--------------------------------------------------------------------------------------------------
609 #define LE_TRACE(traceRef, string, ...) \
610  if (le_log_IsTraceEnabled(traceRef)) \
611  { \
612  _le_log_Send((le_log_Level_t)-1, \
613  traceRef, \
614  LE_LOG_SESSION, \
615  STRINGIZE(LE_FILENAME), \
616  _LE_LOG_FUNCTION_NAME, \
617  __LINE__, \
618  string, \
619  ##__VA_ARGS__); \
620  }
621 
622 
623 //--------------------------------------------------------------------------------------------------
631 //--------------------------------------------------------------------------------------------------
632 #define le_log_GetTraceRef(keywordPtr) \
633  _le_log_GetTraceRef(LE_LOG_SESSION, (keywordPtr))
634 
635 
636 //--------------------------------------------------------------------------------------------------
644 //--------------------------------------------------------------------------------------------------
645 #define le_log_IsTraceEnabled(traceRef) ((traceRef) == NULL ? false : *((bool *) (traceRef)))
646 
647 
648 //--------------------------------------------------------------------------------------------------
658 //--------------------------------------------------------------------------------------------------
659 #define le_log_SetFilterLevel(level) \
660  _le_log_SetFilterLevel(LE_LOG_SESSION, (level))
661 
662 
663 //--------------------------------------------------------------------------------------------------
667 //--------------------------------------------------------------------------------------------------
668 #define le_log_GetFilterLevel() \
669  ((LE_LOG_LEVEL_FILTER_PTR != NULL)?(*LE_LOG_LEVEL_FILTER_PTR):(LE_LOG_INFO))
670 
671 
672 //--------------------------------------------------------------------------------------------------
682 //--------------------------------------------------------------------------------------------------
683 #define le_log_EnableTrace(traceRef) \
684  ((void)(*((bool*)(traceRef)) = true))
685 
686 
687 //--------------------------------------------------------------------------------------------------
697 //--------------------------------------------------------------------------------------------------
698 #define le_log_DisableTrace(traceRef) \
699  ((void)(*((bool*)(traceRef)) = false))
700 
701 #else
702 
703 // If any logging macro is overridden, all logging macros must be overridden.
704 #if !defined(LE_DEBUG)
705 # error "Logging are overridden, but LE_DEBUG not defined. Define LE_DEBUG."
706 #endif
707 
708 #if !defined(LE_DUMP)
709 # error "Logging are overridden, but LE_DUMP not defined. Define LE_DUMP."
710 #endif
711 
712 #if !defined(LE_LOG_DUMP)
713 # error "Logging are overridden, but LE_LOG_DUMP not defined. Define LE_LOG_DUMP."
714 #endif
715 
716 #if !defined(LE_INFO)
717 # error "Logging are overridden, but LE_INFO not defined. Define LE_INFO."
718 #endif
719 
720 #if !defined(LE_WARN)
721 # error "Logging are overridden, but LE_WARN not defined. Define LE_WARN."
722 #endif
723 
724 #if !defined(LE_ERROR)
725 # error "Logging are overridden, but LE_ERROR not defined. Define LE_ERROR."
726 #endif
727 
728 #if !defined(LE_CRIT)
729 # error "Logging are overridden, but LE_CRIT not defined. Define LE_CRIT."
730 #endif
731 
732 #if !defined(LE_EMERG)
733 # error "Logging are overridden, but LE_EMERG not defined. Define LE_EMERG."
734 #endif
735 
736 // If SetFilterLevel is not defined when logging is overridden,
737 // assume it cannot be set programatically
738 #ifndef le_log_SetFilterLevel
739 //--------------------------------------------------------------------------------------------------
749 //--------------------------------------------------------------------------------------------------
750 #define le_log_SetFilterLevel(level) ((void)(level))
751 #endif
752 
753 
754 // If le_log_GetFilterLevel is not defined when logging is overridden, assume it
755 // cannot be obtained programatically. In this case code should assume filter level
756 // is equal to static filter level
757 #ifndef le_log_GetFilterLevel
758 //--------------------------------------------------------------------------------------------------
762 //--------------------------------------------------------------------------------------------------
763 #define le_log_GetFilterLevel() (LE_LOG_LEVEL_STATIC_FILTER)
764 #endif
765 
766 //--------------------------------------------------------------------------------------------------
767 /*
768  * If logging is overridden, disable Legato tracing mechanism. Tracing is noisy and should
769  * not be put into general logs.
770  */
771 //--------------------------------------------------------------------------------------------------
772 
773 //--------------------------------------------------------------------------------------------------
781 //--------------------------------------------------------------------------------------------------
782 #define LE_IS_TRACE_ENABLED(traceRef) (false)
783 
784 
785 //--------------------------------------------------------------------------------------------------
789 //--------------------------------------------------------------------------------------------------
790 #define LE_TRACE(traceRef, string, ...) ((void)(traceRef))
791 
792 
793 //--------------------------------------------------------------------------------------------------
801 //--------------------------------------------------------------------------------------------------
802 #define le_log_GetTraceRef(keywordPtr) ((le_log_TraceRef_t)NULL)
803 
804 
805 //--------------------------------------------------------------------------------------------------
813 //--------------------------------------------------------------------------------------------------
814 #define le_log_IsTraceEnabled(traceRef) (false)
815 
816 
817 //--------------------------------------------------------------------------------------------------
827 //--------------------------------------------------------------------------------------------------
828 #define le_log_EnableTrace(traceRef) ((void)(0))
829 
830 
831 //--------------------------------------------------------------------------------------------------
841 //--------------------------------------------------------------------------------------------------
842 #define le_log_DisableTrace(traceRef) ((void)(0))
843 
844 #endif /* Logging macro override */
845 
847 const char* _le_log_GetResultCodeString
848 (
849  le_result_t resultCode
850 );
851 
853 const char* _le_log_GetErrnoCodeString
854 (
855  int errnoCode
856 );
857 
859 __attribute__((noreturn))
860 void _le_log_ExitFatal
861 (
862  void
863 );
864 
865 //--------------------------------------------------------------------------------------------------
874 //--------------------------------------------------------------------------------------------------
875 
877 #define LE_DEBUG_IF(condition, formatString, ...) \
878  if (condition) { LE_DEBUG(formatString, ##__VA_ARGS__); }
879 
880 #define LE_INFO_IF(condition, formatString, ...) \
881  if (condition) { LE_INFO(formatString, ##__VA_ARGS__); }
882 
883 #define LE_WARN_IF(condition, formatString, ...) \
884  if (condition) { LE_WARN(formatString, ##__VA_ARGS__); }
885 
886 #define LE_ERROR_IF(condition, formatString, ...) \
887  if (condition) { LE_ERROR(formatString, ##__VA_ARGS__); }
888 
889 #define LE_CRIT_IF(condition, formatString, ...) \
890  if (condition) { LE_CRIT(formatString, ##__VA_ARGS__); }
891 
892 #define LE_EMERG_IF(condition, formatString, ...) \
893  if (condition) { LE_EMERG(formatString, ##__VA_ARGS__); }
894 
895 
896 //--------------------------------------------------------------------------------------------------
904 //--------------------------------------------------------------------------------------------------
905 #ifndef LE_FATAL
906 # if !LE_CONFIG_DEBUG
907 # define LE_FATAL(formatString, ...) \
908  { LE_EMERG(formatString, ##__VA_ARGS__); _le_log_ExitFatal(); }
909 # else
910 # define LE_FATAL(formatString, ...) \
911  { LE_EMERG(formatString, ##__VA_ARGS__); abort(); }
912 # endif
913 #endif
914 
915 
916 //--------------------------------------------------------------------------------------------------
924 //--------------------------------------------------------------------------------------------------
925 #define LE_FATAL_IF(condition, formatString, ...) \
926  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
927 
928 
929 //--------------------------------------------------------------------------------------------------
934 //--------------------------------------------------------------------------------------------------
935 #define LE_ASSERT(condition) \
936  LE_FATAL_IF(!(condition), "Assert Failed: '%s'", #condition)
937 
938 
939 //--------------------------------------------------------------------------------------------------
944 //--------------------------------------------------------------------------------------------------
945 #define LE_ASSERT_OK(condition) \
946  LE_FATAL_IF((condition) != LE_OK, "Assert Failed: '%s' is not LE_OK (0)", #condition)
947 
948 
949 //--------------------------------------------------------------------------------------------------
960 //--------------------------------------------------------------------------------------------------
961 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
962 
963 //--------------------------------------------------------------------------------------------------
972 //--------------------------------------------------------------------------------------------------
973 #ifndef LE_ERRNO_TXT
974 # define LE_ERRNO_TXT(v) _le_log_GetErrnoCodeString(v)
975 # define LE_LOG_NEED_GET_ERRNO_STRING 1
976 
977 const char *_le_log_GetErrnoCodeString(int error);
978 #endif
979 
980 
981 //--------------------------------------------------------------------------------------------------
988 //--------------------------------------------------------------------------------------------------
990 (
991  void
992 );
993 
994 //--------------------------------------------------------------------------------------------------
1002 //--------------------------------------------------------------------------------------------------
1003 LE_FULL_API le_log_SessionRef_t le_log_RegComponent
1004 (
1005  const char *componentNamePtr,
1006  le_log_Level_t **levelFilterPtrPtr
1007 );
1008 
1009 #endif // LEGATO_LOG_INCLUDE_GUARD
le_log_Level_t
Definition: le_log.h:374
const char * _le_log_GetErrnoCodeString(int errnoCode)
Function that does the real work of translating result codes. See LE_RESULT_TXT.
Definition: le_log.h:379
Definition: le_log.h:381
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:383
One beyond maximum log level.
Definition: le_log.h:384
LE_FULL_API le_log_SessionRef_t le_log_RegComponent(const char *componentNamePtr, le_log_Level_t **levelFilterPtrPtr)
LE_FULL_API void le_log_ConnectToControlDaemon(void)
const char * _le_log_GetResultCodeString(le_result_t resultCode)
Function that does the real work of translating result codes. See LE_RESULT_TXT.
__attribute__((noreturn)) void _le_log_ExitFatal(void)
Function that exits in a race-free manner – work around glibc BZ#14333.
le_result_t
Definition: le_basics.h:45
Informational message. Normally expected.
Definition: le_log.h:377
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:378
#define LE_FULL_API
Definition: le_apiFeatures.h:42
Debug message.
Definition: le_log.h:376
#define LE_SHARED
Definition: le_basics.h:297