All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
le_log.h
Go to the documentation of this file.
1 
344 #ifndef LEGATO_LOG_INCLUDE_GUARD
345 #define LEGATO_LOG_INCLUDE_GUARD
346 
347 //--------------------------------------------------------------------------------------------------
351 //--------------------------------------------------------------------------------------------------
352 typedef enum
353 {
358  LE_LOG_CRIT,
360  LE_LOG_EMERG
362 }
364 
365 /* @cond PrivateFunctions */
366 
367 typedef struct le_log_Session* le_log_SessionRef_t;
368 
369 typedef struct le_log_Trace* le_log_TraceRef_t;
370 
371 void _le_log_Send
372 (
373  const le_log_Level_t level,
374  const le_log_TraceRef_t traceRef,
375  le_log_SessionRef_t logSession,
376  const char* filenamePtr,
377  const char* functionNamePtr,
378  const unsigned int lineNumber,
379  const char* formatPtr,
380  ...
381 ) __attribute__ ((format (printf, 7, 8)));
382 
383 le_log_TraceRef_t _le_log_GetTraceRef
384 (
385  le_log_SessionRef_t logSession,
386  const char* keyword
387 );
388 
389 void _le_log_SetFilterLevel
390 (
391  le_log_SessionRef_t logSession,
392  le_log_Level_t level
393 );
394 
395 
396 //--------------------------------------------------------------------------------------------------
403 //--------------------------------------------------------------------------------------------------
404 #ifdef __cplusplus
405 extern
406 #endif
407 le_log_SessionRef_t LE_LOG_SESSION;
408 
409 //--------------------------------------------------------------------------------------------------
416 //--------------------------------------------------------------------------------------------------
417 #ifdef __cplusplus
418 extern
419 #endif
420 le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
421 
422 /* @endcond */
423 
424 //--------------------------------------------------------------------------------------------------
428 //--------------------------------------------------------------------------------------------------
429 #define _LE_LOG_MSG(level, formatString, ...) \
430  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
431  { \
432  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
433  formatString, ##__VA_ARGS__); \
434  }
435 
436 
437 //--------------------------------------------------------------------------------------------------
444 //--------------------------------------------------------------------------------------------------
445 
447 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
448 
449 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
450 
451 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
452 
453 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
454 
455 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
456 
457 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
458 
459 
460 //--------------------------------------------------------------------------------------------------
469 //--------------------------------------------------------------------------------------------------
470 
472 #define LE_DEBUG_IF(condition, formatString, ...) \
473  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__) }
474 
475 #define LE_INFO_IF(condition, formatString, ...) \
476  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__) }
477 
478 #define LE_WARN_IF(condition, formatString, ...) \
479  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__) }
480 
481 #define LE_ERROR_IF(condition, formatString, ...) \
482  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__) }
483 
484 #define LE_CRIT_IF(condition, formatString, ...) \
485  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__) }
486 
487 #define LE_EMERG_IF(condition, formatString, ...) \
488  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__) }
489 
490 
491 //--------------------------------------------------------------------------------------------------
499 //--------------------------------------------------------------------------------------------------
500 #define LE_FATAL(formatString, ...) \
501  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
502 
503 
504 //--------------------------------------------------------------------------------------------------
512 //--------------------------------------------------------------------------------------------------
513 #define LE_FATAL_IF(condition, formatString, ...) \
514  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
515 
516 
517 //--------------------------------------------------------------------------------------------------
522 //--------------------------------------------------------------------------------------------------
523 #define LE_ASSERT(condition) \
524  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
525 
526 
527 //--------------------------------------------------------------------------------------------------
538 //--------------------------------------------------------------------------------------------------
539 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
540 
542 const char* _le_log_GetResultCodeString
543 (
544  le_result_t resultCode
545 );
546 
547 
548 //--------------------------------------------------------------------------------------------------
556 //--------------------------------------------------------------------------------------------------
557 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
558 
559 
560 //--------------------------------------------------------------------------------------------------
564 //--------------------------------------------------------------------------------------------------
565 #define LE_TRACE(traceRef, string, ...) \
566  if (le_log_IsTraceEnabled(traceRef)) \
567  { \
568  _le_log_Send(-1, traceRef, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
569  string, ##__VA_ARGS__); \
570  }
571 
572 
573 //--------------------------------------------------------------------------------------------------
579 //--------------------------------------------------------------------------------------------------
580 static inline le_log_TraceRef_t le_log_GetTraceRef
581 (
582  const char* keywordPtr
583 )
584 {
585  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
586 }
587 
588 
589 //--------------------------------------------------------------------------------------------------
595 //--------------------------------------------------------------------------------------------------
596 static inline bool le_log_IsTraceEnabled
597 (
598  const le_log_TraceRef_t traceRef
599 )
600 {
601  return *((bool*)traceRef);
602 }
603 
604 
605 //--------------------------------------------------------------------------------------------------
613 //--------------------------------------------------------------------------------------------------
614 static inline void le_log_SetFilterLevel
615 (
616  le_log_Level_t level
617 )
618 {
619  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
620 }
621 
622 
623 //--------------------------------------------------------------------------------------------------
630 //--------------------------------------------------------------------------------------------------
631 static inline void le_log_EnableTrace
632 (
633  const le_log_TraceRef_t traceRef
634 )
635 {
636  *((bool*)traceRef) = true;
637 }
638 
639 
640 //--------------------------------------------------------------------------------------------------
647 //--------------------------------------------------------------------------------------------------
648 static inline void le_log_DisableTrace
649 (
650  const le_log_TraceRef_t traceRef
651 )
652 {
653  *((bool*)traceRef) = false;
654 }
655 
656 
657 
658 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:581
le_result_t
Definition: le_basics.h:35
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:632
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:356
le_log_Level_t
Definition: le_log.h:352
Debug message.
Definition: le_log.h:354
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:615
Definition: le_log.h:357
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:359
Informational message. Normally expected.
Definition: le_log.h:355
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:361
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:597
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:649