00001
00332 #ifndef LEGATO_LOG_INCLUDE_GUARD
00333 #define LEGATO_LOG_INCLUDE_GUARD
00334
00335
00339
00340 typedef enum
00341 {
00342 LE_LOG_DEBUG,
00343 LE_LOG_INFO,
00344 LE_LOG_WARN,
00345 LE_LOG_ERR,
00346
00347 LE_LOG_CRIT,
00348
00349 LE_LOG_EMERG
00350 }
00351 le_log_Level_t;
00352
00353
00354
00355 typedef struct le_log_Session* le_log_SessionRef_t;
00356
00357 typedef struct le_log_Trace* le_log_TraceRef_t;
00358
00359 void _le_log_Send
00360 (
00361 const le_log_Level_t level,
00362 const le_log_TraceRef_t traceRef,
00363 le_log_SessionRef_t logSession,
00364 const char* filenamePtr,
00365 const char* functionNamePtr,
00366 const unsigned int lineNumber,
00367 const char* formatPtr,
00368 ...
00369 ) __attribute__ ((format (printf, 7, 8)));
00370
00371 le_log_TraceRef_t _le_log_GetTraceRef
00372 (
00373 le_log_SessionRef_t logSession,
00374 const char* keyword
00375 );
00376
00377 void _le_log_SetFilterLevel
00378 (
00379 le_log_SessionRef_t logSession,
00380 le_log_Level_t level
00381 );
00382
00383
00384
00391
00392 le_log_SessionRef_t LE_LOG_SESSION;
00393
00394
00401
00402 le_log_Level_t* LE_LOG_LEVEL_FILTER_PTR;
00403
00404
00405
00406
00410
00411 #define _LE_LOG_MSG(level, formatString, ...) \
00412 if ((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR)) \
00413 { \
00414 _le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
00415 formatString, ##__VA_ARGS__); \
00416 }
00417
00418
00419
00426
00427
00429 #define LE_DEBUG(formatString, ...) _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
00430
00431 #define LE_INFO(formatString, ...) _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
00432
00433 #define LE_WARN(formatString, ...) _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
00434
00435 #define LE_ERROR(formatString, ...) _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
00436
00437 #define LE_CRIT(formatString, ...) _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
00438
00439 #define LE_EMERG(formatString, ...) _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
00440
00441
00442
00451
00452
00454 #define LE_DEBUG_IF(condition, formatString, ...) \
00455 if (condition) { _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__) }
00456
00457 #define LE_INFO_IF(condition, formatString, ...) \
00458 if (condition) { _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__) }
00459
00460 #define LE_WARN_IF(condition, formatString, ...) \
00461 if (condition) { _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__) }
00462
00463 #define LE_ERROR_IF(condition, formatString, ...) \
00464 if (condition) { _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__) }
00465
00466 #define LE_CRIT_IF(condition, formatString, ...) \
00467 if (condition) { _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__) }
00468
00469 #define LE_EMERG_IF(condition, formatString, ...) \
00470 if (condition) { _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__) }
00471
00472
00473
00481
00482 #define LE_FATAL(formatString, ...) \
00483 { LE_EMERG(formatString, ##__VA_ARGS__); exit(EXIT_FAILURE); }
00484
00485
00486
00494
00495 #define LE_FATAL_IF(condition, formatString, ...) \
00496 if (condition) { LE_FATAL(formatString, ##__VA_ARGS__) }
00497
00498
00499
00504
00505 #define LE_ASSERT(condition) \
00506 if (!(condition)) { LE_FATAL("Assert Failed: '%s'", #condition) }
00507
00508
00509
00520
00521 #define LE_RESULT_TXT(v) _le_log_GetResultCodeString(v)
00522
00524 const char* _le_log_GetResultCodeString
00525 (
00526 le_result_t resultCode
00527 );
00528
00529
00530
00538
00539 #define LE_IS_TRACE_ENABLED(traceRef) (le_log_IsTraceEnabled(traceRef))
00540
00541
00542
00546
00547 #define LE_TRACE(traceRef, string, ...) \
00548 if (le_log_IsTraceEnabled(traceRef)) \
00549 { \
00550 _le_log_Send(-1, traceRef, LE_LOG_SESSION, __FILE__, __func__, __LINE__, \
00551 string, ##__VA_ARGS__); \
00552 }
00553
00554
00555
00561
00562 static inline le_log_TraceRef_t le_log_GetTraceRef
00563 (
00564 const char* keywordPtr
00565 )
00566 {
00567 return _le_log_GetTraceRef(LE_LOG_SESSION, keywordPtr);
00568 }
00569
00570
00571
00577
00578 static inline bool le_log_IsTraceEnabled
00579 (
00580 const le_log_TraceRef_t traceRef
00581 )
00582 {
00583 return *((bool*)traceRef);
00584 }
00585
00586
00587
00595
00596 static inline void le_log_SetFilterLevel
00597 (
00598 le_log_Level_t level
00599 )
00600 {
00601 _le_log_SetFilterLevel(LE_LOG_SESSION, level);
00602 }
00603
00604
00605
00612
00613 static inline void le_log_EnableTrace
00614 (
00615 const le_log_TraceRef_t traceRef
00616 )
00617 {
00618 *((bool*)traceRef) = true;
00619 }
00620
00621
00622
00629
00630 static inline void le_log_DisableTrace
00631 (
00632 const le_log_TraceRef_t traceRef
00633 )
00634 {
00635 *((bool*)traceRef) = false;
00636 }
00637
00638
00639
00640 #endif // LEGATO_LOG_INCLUDE_GUARD