2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %Log macros.
22 * This header file defines the %Log macros.
25 #ifndef _FBASE_SYS_LOG_H_
26 #define _FBASE_SYS_LOG_H_
29 #include <FOspConfig.h>
30 #include <FBaseDataType.h>
31 #include <FIoRegistry.h>
38 #define likely(x) __builtin_expect(!!(x), 1)
41 #define unlikely(x) __builtin_expect(!!(x), 0)
45 * @mainpage Tizen Platform API Reference
47 * The Tizen platform API Reference provides descriptions of APIs for the platform developers.
51 * @defgroup GroupMacros Debugging Macros
53 * This page describes Tizen debugging macros used by the Tizen modules.
54 * These debugging macros should use specific NID ( Namespace ID ) to distinguish each Tizen modules.
61 * @addtogroup GroupMacros
67 * This macro allows display of informative log messages.
68 * This system log macro is for the platform modules.
72 * @param[in] NID The Tizen namespace
73 * @param[in] ... The message to display
75 * The following example demonstrates how to use the SysLog macro.
79 * MyEngine::Init(int value)
81 * SysLog(NID, "Initialization successful.");
88 #define SysLog(NID, ...) SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
91 * This macro allows display of exception log messages with a tag and sets the last result.
92 * This system log macro is for the platform modules.
96 * @param[in] NID The Tizen namespace
97 * @param[in] r The last result to set
98 * @param[in] ... The message to display
100 * The following example demonstrates how to use the SysLogException macro.
104 * MyEngine::Init(int value)
107 * if (something_wrong) // The Try family macros can be used instead.
109 * SysLogException(NID, E_INVALID_ARG, "An unexpected error has occurred.");
120 #define SysLogException(NID, r, ...) SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
123 * This macro allows display of informative log messages with a tag.
124 * This system log macro is for the platform modules.
128 * @param[in] NID The Tizen namespace
129 * @param[in] tag The user defined tag
130 * @param[in] ... The message to display
132 * The following example demonstrates how to use the SysLogTag macro.
136 * MyEngine::Init(int value)
138 * SysLogTag(NID, "MyTag", "Initialization successful.");
145 #define SysLogTag(NID, tag, ...) SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
148 * This macro allows display of exception log messages with a tag and sets the last result.
149 * This system log macro is for the platform modules.
153 * @param[in] NID The Tizen namespace
154 * @param[in] tag The user defined tag
155 * @param[in] r The last result to set
156 * @param[in] ... The message to display
158 * The following example demonstrates how to use the SysLogTagException macro.
162 * MyEngine::Init(int value)
164 * SysLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "Initialization successful.");
171 #define SysLogExceptionTag(NID, tag, r, ...) SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
176 * This macro allows display of informative log message with a tag, when the condition is @c false.
177 * This system log macro is for the platform modules.
181 * @param[in] NID The Tizen namespace
182 * @param[in] condition The condition that is expected to be true
183 * @param[in] ... The message to display
185 * The following example demonstrates how to use the SysTryLog macro.
189 * MyEngine::Init(int value)
193 * SysTryLog(NID, condition, "An unexpected error has occurred.");
200 #define SysTryLog(NID, condition, ...) \
203 if (unlikely(!(condition))) { \
204 SysLog(NID, __VA_ARGS__); \
209 * This macro allows display of informative log message, when the condition is @c false.
210 * Executes statements and goes to label.
211 * This system log macro is for the platform modules.
215 * @param[in] NID The Tizen namespace
216 * @param[in] condition The condition that is expected to be true
217 * @param[in] expr Expressions that are evaluated before going to CATCH label
218 * @param[in] ... The message to display
220 * The following example demonstrates how to use the SysTryLogCatch macro.
224 * MyEngine::Init(int value)
228 * SysTryLogCatch(NID, condition, r=E_INVALID_ARG, "An unexpected error has occurred.");
237 #define SysTryLogCatch(NID, condition, expr, ...) \
240 if (unlikely(!(condition))) { \
241 SysLog(NID, __VA_ARGS__); \
248 * This macro allows display of informative log message and returns returnValue, when the condition is @c false.
249 * This system log macro is for the platform modules.
253 * @param[in] NID The Tizen namespace
254 * @param[in] condition The condition that is expected to be true
255 * @param[in] returnValue The value to return when the condition is @c false
256 * @param[in] ... The message to display
258 * The following example demonstrates how to use the SysTryLogReturn macro.
262 * MyEngine::Init(int value)
266 * SysTryLogReturn(NID, condition, false, "An unexpected error has occurred.");
274 #define SysTryLogReturn(NID, condition, returnValue, ...) \
277 if (unlikely(!(condition))) { \
278 SysLog(NID, __VA_ARGS__); \
279 return returnValue; \
285 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
286 * This system log macro is for the platform modules.
290 * @param[in] NID The Tizen namespace
291 * @param[in] condition The condition that is expected to be true
292 * @param[in] returnValue The value to return when the condition is @c false
293 * @param[in] r The last result to set
294 * @param[in] ... The message to display
296 * The following example demonstrates how to use the SysTryReturn macro.
300 * MyEngine::Init(int value)
304 * SysTryReturn(NID, condition, false, E_INVALID_ARG, "An unexpected error has occurred.");
312 #define SysTryReturn(NID, condition, returnValue, r, ...) \
315 if (unlikely(!(condition))) { \
316 SysLogException(NID, r, __VA_ARGS__); \
317 return returnValue; \
322 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
323 * This is a shorthand macro for SysTryReturn(NID, condition, r, r, "[" # r "] " ...).
324 * This system log macro is for the platform modules.
328 * @param[in] NID The Tizen namespace
329 * @param[in] condition The condition that is expected to be true
330 * @param[in] r The last result to set
331 * @param[in] ... The message to display
333 * The following example demonstrates how to use the SysTryReturnResult macro.
336 * #define E_UNKNOWN_ERROR 1
338 * MyEngine::Init(int value)
342 * SysTryReturnResult(NID, condition, E_UNKNOWN_ERROR, "An unexpected error has occurred.");
350 #define SysTryReturnResult(NID, condition, r, ...) \
353 if (unlikely(!(condition))) { \
354 SysTryReturnResultInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
360 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
361 * This system log macro is for the platform modules.
365 * @param[in] NID The Tizen namespace
366 * @param[in] condition The condition that is expected to be true
367 * @param[in] r The last result to set
368 * @param[in] ... The message to display
370 * The following example demonstrates how to use the SysTryReturnVoidResult macro.
374 * MyEngine::Init(int value)
378 * SysTryReturnVoidResult(NID, condition, E_INVALID_ARG, "An unexpected error has occurred.");
386 #define SysTryReturnVoidResult(NID, condition, r, ...) \
389 if (unlikely(!(condition))) { \
390 SysLogException(NID, r, __VA_ARGS__); \
396 * This macro allows display of exception log message with a tag, when the condition is @c false.
397 * Executes statements, sets the last result and goes to label.
398 * This system log macro is for the platform modules.
402 * @param[in] NID The Tizen namespace
403 * @param[in] condition The condition that is expected to be true
404 * @param[in] expr Expressions that are evaluated before going to CATCH label
405 * @param[in] r The last result to set
406 * @param[in] ... The message to display
408 * The following example demonstrates how to use the SysTryCatch macro.
412 * MyEngine::Init(int value)
416 * SysTryCatch(NID, condition, r=E_INVALID_ARG, E_INVALID_ARG, "An unexpected error has occurred.");
425 #define SysTryCatch(NID, condition, expr, r, ...) \
428 if (unlikely(!(condition))) { \
429 SysLogException(NID, r, __VA_ARGS__); \
436 * This macro allows display of exception log message with a tag, when the condition is @c false.
437 * Executes statements, sets the last result and goes to label.
438 * This system log macro is for the platform modules.
442 * @param[in] NID The Tizen namespace
443 * @param[in] condition The condition that is expected to be true
444 * @param[in] expr Expressions that are evaluated before going to catchLabel label
445 * @param[in] catchLabel The label for goto operation
446 * @param[in] r The last result to set
447 * @param[in] ... The message to display
449 * The following example demonstrates how to use the SysTryCatchLabel macro.
453 * MyEngine::Init(int value)
457 * SysTryCatchLabel(NID, condition, r=E_INVALID_ARG, LABEL, E_INVALID_ARG, "An unexpected error has occurred.");
466 #define SysTryCatchLabel(NID, condition, expr, catchLabel, r, ...) \
469 if (unlikely(!(condition))) { \
470 SysLogException(NID, r, __VA_ARGS__); \
478 * This macro allows display of exception log message and the program will expire, when the condition is @c false.
479 * This system log macro is for the platform modules.
483 * @param[in] condition The condition that is expected to be true
485 * The following example demonstrates how to use the SysAssert macro.
489 * MyEngine::Init(int value)
493 * SysAssert(condition);
500 #define SysAssert(condition) \
503 if (unlikely(!(condition))) { \
504 SysAssertInternal(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
509 * This macro allows display of exception log message with a tag and the program will expire, when the condition is @c false.
510 * This system log macro is for the platform modules.
514 * @param[in] condition The condition that is expected to be true
515 * @param[in] ... The message to display
517 * The following example demonstrates how to use the SysAssertf macro.
521 * MyEngine::Init(int value)
525 * SysAssertf(condition, "");
532 #define SysAssertf(condition, ...) \
535 if (unlikely(!(condition))) { \
536 SysAssertfInternal(# condition, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
542 * This macro generates an error message during compile time, when the condition is @c false.
543 * This system log macro is for the platform modules.
547 * @param[in] condition The condition that is expected to be true
549 * The following example demonstrates how to use the SysStaticAssert macro.
553 * MyEngine::Init(int value)
557 * SysStaticAssert(condition);
564 #define SysStaticAssert(condition) switch (0) { \
572 * This macro allows display of exception log messages.
573 * This system log macro is for the platform modules.
577 * @param[in] NID The Tizen namespace
578 * @param[in] r The last result to set
580 * The following example demonstrates how to use the SysPropagate macro.
584 * MyEngine::Init(int value)
588 * SysPropagate(NID, E_INVALID_ARG);
595 #define SysPropagate(NID, r) SysPropagateInternal(__PRETTY_FUNCTION__, __LINE__, NID, r)
598 #if defined(_SECURE_LOG)
600 #define SysSecureLog(NID, ...) SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
601 #define SysSecureLogException(NID, r,...) SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
603 #define SysSecureLogTag(NID, tag, ...) SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
604 #define SysSecureLogExceptionTag(NID, tag, r, ...) SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
609 * This macro is to protect informative log messages which needs to keep security.
610 * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
611 * Otherwise, it will be removed in the compile time.
612 * This system log macro is for the platform modules.
616 * @param[in] NID The Tizen namespace ID
617 * @param[in] ... The message to display
619 * The following example demonstrates how to use the SysSecureLog macro.
623 * MyEngine::Init(int value)
625 * SysSecureLog(NID, "User ID : 'JoneDoe'");
632 #define SysSecureLog(NID, ...)
635 * This macro is to protect exception log messages which needs to keep security, and sets the last result.
636 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
637 * Otherwise, it will be removed in the compile time.
638 * This system log macro is for the platform modules.
642 * @param[in] NID The Tizen namespace ID
643 * @param[in] r The last result to set
644 * @param[in] ... The message to display
646 * The following example demonstrates how to use the SysSecureLogException macro.
650 * MyEngine::Init(int value)
653 * if (something_wrong)
655 * SysSecureLogException(NID, E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
666 #define SysSecureLogException(NID, r,...)
669 * This macro is to protect informative log messages which needs to keep security, with a tag.
670 * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
671 * Otherwise, it will be removed in the compile time.
672 * This system log macro is for the platform modules.
676 * @param[in] NID The Tizen namespace ID
677 * @param[in] tag The user defined tag
678 * @param[in] ... The message to display
680 * The following example demonstrates how to use the SysSecureLogTag macro.
684 * MyEngine::Init(int value)
686 * SysSecureLogTag(NID, "MyTag", "User ID : 'JoneDoe'");
693 #define SysSecureLogTag(NID, tag, ...)
696 * This macro is to protect exception log messages which needs to keep security, with a tag and sets the last result.
697 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
698 * Otherwise, it will be removed in the compile time.
699 * This system log macro is for the platform modules.
703 * @param[in] NID The Tizen namespace ID
704 * @param[in] tag The user defined tag
705 * @param[in] r The last result to set
706 * @param[in] ... The message to display
708 * The following example demonstrates how to use the SysSecureLogExceptionTag macro.
712 * MyEngine::Init(int value)
714 * SysSecureLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
721 #define SysSecureLogExceptionTag(NID, tag, r, ...)
726 * Defines the log ID.
730 //Tizen Namespace ID ===============================================================
765 NID_SEC_CRYPTO = 112,
783 NID_UIX_SPEECH = 171,
796 _OSP_EXPORT_ void SysLogInternal(unsigned long id, const char* pFunction, int lineNumber, const char* pFormat, ...);
797 _OSP_EXPORT_ void SysLogExceptionInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
799 _OSP_EXPORT_ void SysLogTagInternal(unsigned long id, const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
800 _OSP_EXPORT_ void SysLogExceptionTagInternal(unsigned long id, const char* pTag, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
802 _OSP_EXPORT_ void SysAssertInternal(const char* pFileName, int lineNumber, const char* pFunction);
803 _OSP_EXPORT_ void SysAssertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
805 _OSP_EXPORT_ void SysPropagateInternal(const char* pFunction, int lineNumber, unsigned long nid, result r);
807 _OSP_EXPORT_ void SysTryReturnResultInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
811 #endif // __cplusplus
814 #endif // _FBASE_SYS_LOG_H_