All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
le_log.h
Go to the documentation of this file.
1 
364 #ifndef LEGATO_LOG_INCLUDE_GUARD
365 #define LEGATO_LOG_INCLUDE_GUARD
366 
367 //--------------------------------------------------------------------------------------------------
371 //--------------------------------------------------------------------------------------------------
372 typedef enum
373 {
378  LE_LOG_CRIT,
380  LE_LOG_EMERG
382 }
384 
385 /* @cond PrivateFunctions */
386 
387 typedef struct le_log_Session* le_log_SessionRef_t;
388 
389 typedef struct le_log_Trace* le_log_TraceRef_t;
390 
391 void _le_log_Send
392 (
393  const le_log_Level_t level,
394  const le_log_TraceRef_t traceRef,
395  le_log_SessionRef_t logSession,
396  const char* filenamePtr,
397  const char* functionNamePtr,
398  const unsigned int lineNumber,
399  const char* formatPtr,
400  ...
401 ) __attribute__ ((format (printf, 7, 8)));
402 
403 le_log_TraceRef_t _le_log_GetTraceRef
404 (
405  le_log_SessionRef_t logSession,
406  const char* keyword
407 );
408 
409 void _le_log_SetFilterLevel
410 (
411  le_log_SessionRef_t logSession,
412  le_log_Level_t level
413 );
414 
415 
416 //--------------------------------------------------------------------------------------------------
423 //--------------------------------------------------------------------------------------------------
424 #ifdef __cplusplus
425 extern
426 #endif
427 le_log_SessionRef_t LE_LOG_SESSION;
428 
429 //--------------------------------------------------------------------------------------------------
436 //--------------------------------------------------------------------------------------------------
437 #ifdef __cplusplus
438 extern
439 #endif
440 le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
441 
442 /* @endcond */
443 
444 //--------------------------------------------------------------------------------------------------
448 //--------------------------------------------------------------------------------------------------
449 #define _LE_LOG_MSG(level, formatString, ...) \
450  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
451  { \
452  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
453  formatString, ##__VA_ARGS__); \
454  }
455 
456 
457 //--------------------------------------------------------------------------------------------------
464 //--------------------------------------------------------------------------------------------------
465 
467 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
468 
469 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
470 
471 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
472 
473 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
474 
475 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
476 
477 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
478 
479 
480 //--------------------------------------------------------------------------------------------------
489 //--------------------------------------------------------------------------------------------------
490 
492 #define LE_DEBUG_IF(condition, formatString, ...) \
493  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__) }
494 
495 #define LE_INFO_IF(condition, formatString, ...) \
496  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__) }
497 
498 #define LE_WARN_IF(condition, formatString, ...) \
499  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__) }
500 
501 #define LE_ERROR_IF(condition, formatString, ...) \
502  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__) }
503 
504 #define LE_CRIT_IF(condition, formatString, ...) \
505  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__) }
506 
507 #define LE_EMERG_IF(condition, formatString, ...) \
508  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__) }
509 
510 
511 //--------------------------------------------------------------------------------------------------
519 //--------------------------------------------------------------------------------------------------
520 #define LE_FATAL(formatString, ...) \
521  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
522 
523 
524 //--------------------------------------------------------------------------------------------------
532 //--------------------------------------------------------------------------------------------------
533 #define LE_FATAL_IF(condition, formatString, ...) \
534  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
535 
536 
537 //--------------------------------------------------------------------------------------------------
542 //--------------------------------------------------------------------------------------------------
543 #define LE_ASSERT(condition) \
544  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
545 
546 
547 //--------------------------------------------------------------------------------------------------
558 //--------------------------------------------------------------------------------------------------
559 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
560 
562 const char* _le_log_GetResultCodeString
563 (
564  le_result_t resultCode
565 );
566 
567 
568 //--------------------------------------------------------------------------------------------------
576 //--------------------------------------------------------------------------------------------------
577 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
578 
579 
580 //--------------------------------------------------------------------------------------------------
584 //--------------------------------------------------------------------------------------------------
585 #define LE_TRACE(traceRef, string, ...) \
586  if (le_log_IsTraceEnabled(traceRef)) \
587  { \
588  _le_log_Send(-1, traceRef, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
589  string, ##__VA_ARGS__); \
590  }
591 
592 
593 //--------------------------------------------------------------------------------------------------
599 //--------------------------------------------------------------------------------------------------
600 static inline le_log_TraceRef_t le_log_GetTraceRef
601 (
602  const char* keywordPtr
603 )
604 {
605  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
606 }
607 
608 
609 //--------------------------------------------------------------------------------------------------
615 //--------------------------------------------------------------------------------------------------
616 static inline bool le_log_IsTraceEnabled
617 (
618  const le_log_TraceRef_t traceRef
619 )
620 {
621  return *((bool*)traceRef);
622 }
623 
624 
625 //--------------------------------------------------------------------------------------------------
633 //--------------------------------------------------------------------------------------------------
634 static inline void le_log_SetFilterLevel
635 (
636  le_log_Level_t level
637 )
638 {
639  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
640 }
641 
642 
643 //--------------------------------------------------------------------------------------------------
650 //--------------------------------------------------------------------------------------------------
651 static inline void le_log_EnableTrace
652 (
653  const le_log_TraceRef_t traceRef
654 )
655 {
656  *((bool*)traceRef) = true;
657 }
658 
659 
660 //--------------------------------------------------------------------------------------------------
667 //--------------------------------------------------------------------------------------------------
668 static inline void le_log_DisableTrace
669 (
670  const le_log_TraceRef_t traceRef
671 )
672 {
673  *((bool*)traceRef) = false;
674 }
675 
676 
677 
678 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:601
le_result_t
Definition: le_basics.h:35
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:652
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:376
le_log_Level_t
Definition: le_log.h:372
Debug message.
Definition: le_log.h:374
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:635
Definition: le_log.h:377
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:379
Informational message. Normally expected.
Definition: le_log.h:375
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:381
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:617
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:669