All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
le_log.h
Go to the documentation of this file.
1 
332 #ifndef LEGATO_LOG_INCLUDE_GUARD
333 #define LEGATO_LOG_INCLUDE_GUARD
334 
335 //--------------------------------------------------------------------------------------------------
339 //--------------------------------------------------------------------------------------------------
340 typedef enum
341 {
346  LE_LOG_CRIT,
348  LE_LOG_EMERG
350 }
352 
353 /* @cond PrivateFunctions */
354 
355 typedef struct le_log_Session* le_log_SessionRef_t;
356 
357 typedef struct le_log_Trace* le_log_TraceRef_t;
358 
359 void _le_log_Send
360 (
361  const le_log_Level_t level,
362  const le_log_TraceRef_t traceRef,
363  le_log_SessionRef_t logSession,
364  const char* filenamePtr,
365  const char* functionNamePtr,
366  const unsigned int lineNumber,
367  const char* formatPtr,
368  ...
369 ) __attribute__ ((format (printf, 7, 8)));
370 
371 le_log_TraceRef_t _le_log_GetTraceRef
372 (
373  le_log_SessionRef_t logSession,
374  const char* keyword
375 );
376 
377 void _le_log_SetFilterLevel
378 (
379  le_log_SessionRef_t logSession,
380  le_log_Level_t level
381 );
382 
383 
384 //--------------------------------------------------------------------------------------------------
391 //--------------------------------------------------------------------------------------------------
392 #ifdef __cplusplus
393 extern
394 #endif
395 le_log_SessionRef_t LE_LOG_SESSION;
396 
397 //--------------------------------------------------------------------------------------------------
404 //--------------------------------------------------------------------------------------------------
405 #ifdef __cplusplus
406 extern
407 #endif
408 le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
409 
410 /* @endcond */
411 
412 //--------------------------------------------------------------------------------------------------
416 //--------------------------------------------------------------------------------------------------
417 #define _LE_LOG_MSG(level, formatString, ...) \
418  if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
419  { \
420  _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
421  formatString, ##__VA_ARGS__); \
422  }
423 
424 
425 //--------------------------------------------------------------------------------------------------
432 //--------------------------------------------------------------------------------------------------
433 
435 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
436 
437 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
438 
439 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
440 
441 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
442 
443 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
444 
445 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
446 
447 
448 //--------------------------------------------------------------------------------------------------
457 //--------------------------------------------------------------------------------------------------
458 
460 #define LE_DEBUG_IF(condition, formatString, ...) \
461  if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__) }
462 
463 #define LE_INFO_IF(condition, formatString, ...) \
464  if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__) }
465 
466 #define LE_WARN_IF(condition, formatString, ...) \
467  if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__) }
468 
469 #define LE_ERROR_IF(condition, formatString, ...) \
470  if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__) }
471 
472 #define LE_CRIT_IF(condition, formatString, ...) \
473  if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__) }
474 
475 #define LE_EMERG_IF(condition, formatString, ...) \
476  if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__) }
477 
478 
479 //--------------------------------------------------------------------------------------------------
487 //--------------------------------------------------------------------------------------------------
488 #define LE_FATAL(formatString, ...) \
489  { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
490 
491 
492 //--------------------------------------------------------------------------------------------------
500 //--------------------------------------------------------------------------------------------------
501 #define LE_FATAL_IF(condition, formatString, ...) \
502  if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
503 
504 
505 //--------------------------------------------------------------------------------------------------
510 //--------------------------------------------------------------------------------------------------
511 #define LE_ASSERT(condition) \
512  if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
513 
514 
515 //--------------------------------------------------------------------------------------------------
526 //--------------------------------------------------------------------------------------------------
527 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
528 
530 const char* _le_log_GetResultCodeString
531 (
532  le_result_t resultCode
533 );
534 
535 
536 //--------------------------------------------------------------------------------------------------
544 //--------------------------------------------------------------------------------------------------
545 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
546 
547 
548 //--------------------------------------------------------------------------------------------------
552 //--------------------------------------------------------------------------------------------------
553 #define LE_TRACE(traceRef, string, ...) \
554  if (le_log_IsTraceEnabled(traceRef)) \
555  { \
556  _le_log_Send(-1, traceRef, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
557  string, ##__VA_ARGS__); \
558  }
559 
560 
561 //--------------------------------------------------------------------------------------------------
567 //--------------------------------------------------------------------------------------------------
568 static inline le_log_TraceRef_t le_log_GetTraceRef
569 (
570  const char* keywordPtr
571 )
572 {
573  return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
574 }
575 
576 
577 //--------------------------------------------------------------------------------------------------
583 //--------------------------------------------------------------------------------------------------
584 static inline bool le_log_IsTraceEnabled
585 (
586  const le_log_TraceRef_t traceRef
587 )
588 {
589  return *((bool*)traceRef);
590 }
591 
592 
593 //--------------------------------------------------------------------------------------------------
601 //--------------------------------------------------------------------------------------------------
602 static inline void le_log_SetFilterLevel
603 (
604  le_log_Level_t level
605 )
606 {
607  _le_log_SetFilterLevel(LE_LOG_SESSION, level);
608 }
609 
610 
611 //--------------------------------------------------------------------------------------------------
618 //--------------------------------------------------------------------------------------------------
619 static inline void le_log_EnableTrace
620 (
621  const le_log_TraceRef_t traceRef
622 )
623 {
624  *((bool*)traceRef) = true;
625 }
626 
627 
628 //--------------------------------------------------------------------------------------------------
635 //--------------------------------------------------------------------------------------------------
636 static inline void le_log_DisableTrace
637 (
638  const le_log_TraceRef_t traceRef
639 )
640 {
641  *((bool*)traceRef) = false;
642 }
643 
644 
645 
646 #endif // LEGATO_LOG_INCLUDE_GUARD
static le_log_TraceRef_t le_log_GetTraceRef(const char *keywordPtr)
Definition: le_log.h:569
le_result_t
Definition: le_basics.h:34
static void le_log_EnableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:620
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:344
le_log_Level_t
Definition: le_log.h:340
Debug message.
Definition: le_log.h:342
static void le_log_SetFilterLevel(le_log_Level_t level)
Definition: le_log.h:603
Definition: le_log.h:345
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:347
Informational message. Normally expected.
Definition: le_log.h:343
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:349
static bool le_log_IsTraceEnabled(const le_log_TraceRef_t traceRef)
Definition: le_log.h:585
static void le_log_DisableTrace(const le_log_TraceRef_t traceRef)
Definition: le_log.h:637