Add logging support for linux.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
@@ -140,6 +140,11 @@ project (JerryCore CXX C ASM)
|
||||
set(INCLUDE_CORE ${INCLUDE_CORE} ${INCLUDE_THIRD_PARTY_VALGRIND})
|
||||
endif()
|
||||
|
||||
# Log
|
||||
if("${ENABLE_LOG}" STREQUAL "ON")
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_LOG)
|
||||
endif()
|
||||
|
||||
# Platform-specific configuration
|
||||
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_JERRY_${PLATFORM_EXT}})
|
||||
|
||||
|
||||
+15
-2
@@ -71,6 +71,11 @@ static bool jerry_api_available;
|
||||
*/
|
||||
char jerry_extension_characters_buffer[CONFIG_EXTENSION_CHAR_BUFFER_SIZE];
|
||||
|
||||
#ifdef JERRY_ENABLE_LOG
|
||||
int jerry_debug_level = 0;
|
||||
FILE *jerry_log_file = nullptr;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Assert that it is correct to call API in current state.
|
||||
*
|
||||
@@ -1119,6 +1124,13 @@ jerry_api_eval (const char *source_p, /**< source code */
|
||||
void
|
||||
jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */
|
||||
{
|
||||
if (flags & (JERRY_FLAG_ENABLE_LOG))
|
||||
{
|
||||
#ifndef JERRY_ENABLE_LOG
|
||||
JERRY_WARNING_MSG ("Ignoring log options because of '!JERRY_ENABLE_LOG' build configuration.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (flags & (JERRY_FLAG_MEM_STATS))
|
||||
{
|
||||
#ifndef MEM_STATS
|
||||
@@ -1126,14 +1138,15 @@ jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */
|
||||
| JERRY_FLAG_MEM_STATS_PER_OPCODE
|
||||
| JERRY_FLAG_MEM_STATS_SEPARATE);
|
||||
|
||||
printf ("Ignoring memory statistics option because of '!MEM_STATS' build configuration.\n");
|
||||
JERRY_WARNING_MSG ("Ignoring memory statistics option because of '!MEM_STATS' build configuration.\n");
|
||||
#endif /* !MEM_STATS */
|
||||
}
|
||||
else if (flags & (JERRY_FLAG_MEM_STATS_PER_OPCODE | JERRY_FLAG_MEM_STATS_SEPARATE))
|
||||
{
|
||||
flags &= ~(JERRY_FLAG_MEM_STATS_PER_OPCODE | JERRY_FLAG_MEM_STATS_SEPARATE);
|
||||
|
||||
printf ("Ignoring detailed memory statistics options because memory statistics dump mode is not enabled.\n");
|
||||
JERRY_WARNING_MSG (
|
||||
"Ignoring detailed memory statistics options because memory statistics dump mode is not enabled.\n");
|
||||
}
|
||||
|
||||
jerry_flags = flags;
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef uint32_t jerry_flag_t;
|
||||
#define JERRY_FLAG_MEM_STATS_SEPARATE (1u << 3) /**< dump memory statistics and reset peak values after parse */
|
||||
#define JERRY_FLAG_PARSE_ONLY (1u << 4) /**< parse only, prevents script execution (only for testing)
|
||||
* FIXME: Remove. */
|
||||
#define JERRY_FLAG_ENABLE_LOG (1u << 5) /**< enable logging */
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
@@ -67,6 +68,11 @@ extern const char *jerry_commit_hash;
|
||||
*/
|
||||
extern const char *jerry_branch_name;
|
||||
|
||||
#ifdef JERRY_ENABLE_LOG
|
||||
extern int jerry_debug_level;
|
||||
extern FILE *jerry_log_file;
|
||||
#endif /* JERRY_ENABLE_LOG */
|
||||
|
||||
/**
|
||||
* Jerry error callback type
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef JERRY_GLOBALS_H
|
||||
#define JERRY_GLOBALS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "jerry.h"
|
||||
#include "jrt-types.h"
|
||||
|
||||
@@ -92,6 +93,36 @@ extern void __noreturn jerry_unimplemented (const char *comment, const char *fil
|
||||
#define JERRY_ASSERT(x) do { if (false) { (void)(x); } } while (0)
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
#ifdef JERRY_ENABLE_LOG
|
||||
#define JERRY_LOG(lvl, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (lvl <= jerry_debug_level && jerry_log_file) \
|
||||
{ \
|
||||
fprintf (jerry_log_file, __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define JERRY_DLOG(...) JERRY_LOG (1, __VA_ARGS__)
|
||||
#define JERRY_DDLOG(...) JERRY_LOG (2, __VA_ARGS__)
|
||||
#define JERRY_DDDLOG(...) JERRY_LOG (3, __VA_ARGS__)
|
||||
#else /* !JERRY_ENABLE_LOG */
|
||||
#define JERRY_DLOG(...) \
|
||||
do \
|
||||
{ \
|
||||
if (false) \
|
||||
{ \
|
||||
jerry_ref_unused_variables (0, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define JERRY_DDLOG(...) JERRY_DLOG (__VA_ARGS__)
|
||||
#define JERRY_DDDLOG(...) JERRY_DLOG (__VA_ARGS__)
|
||||
#endif /* !JERRY_ENABLE_LOG */
|
||||
|
||||
#define JERRY_ERROR_MSG(...) fprintf (stderr, __VA_ARGS__)
|
||||
#define JERRY_WARNING_MSG(...) JERRY_ERROR_MSG (__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Mark for unreachable points and unimplemented cases
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user