Update customized logging

* enabled by ESCARGOT_USE_CUSTOM_LOGGING flag
* user can registers customized logging through Platform's inherited functions

Signed-off-by: HyukWoo Park <hyukwoo.park@samsung.com>
This commit is contained in:
HyukWoo Park 2021-10-21 20:02:14 +09:00 committed by Boram Bae
commit 4366a01196
9 changed files with 64 additions and 6 deletions

View file

@ -100,7 +100,7 @@ jobs:
strategy:
matrix:
tc: ['octane', 'v8 chakracore spidermonkey']
build_opt: ['', '-DESCARGOT_THREADING=ON', '-DESCARGOT_SMALL_CONFIG=ON']
build_opt: ['', '-DESCARGOT_THREADING=ON', '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON']
exclude:
# exclude spidermonkey on threading-enabled build (TODO)
- tc: 'v8 chakracore spidermonkey'

View file

@ -135,7 +135,9 @@ IF (ESCARGOT_LIBICU_SUPPORT)
ENDIF()
ENDIF()
IF (${ESCARGOT_HOST} STREQUAL "tizen_obs")
IF (ESCARGOT_USE_CUSTOM_LOGGING)
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DESCARGOT_USE_CUSTOM_LOGGING)
ELSEIF (${ESCARGOT_HOST} STREQUAL "tizen_obs")
PKG_CHECK_MODULES (DLOG REQUIRED dlog)
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} ${DLOG_LIBRARIES})
SET (ESCARGOT_INCDIRS ${ESCARGOT_INCDIRS} ${DLOG_INCLUDE_DIRS})

View file

@ -317,6 +317,17 @@ typedef int32_t UChar32;
#define FALSE 0
#endif
#ifdef ESCARGOT_USE_CUSTOM_LOGGING
// use customized logging
#include <stdarg.h>
namespace Escargot {
void customEscargotInfoLogger(const char* format, ...);
void customEscargotErrorLogger(const char* format, ...);
} // namespace Escargot
#define ESCARGOT_LOG_INFO(...) ::Escargot::customEscargotInfoLogger(__VA_ARGS__);
#define ESCARGOT_LOG_ERROR(...) ::Escargot::customEscargotErrorLogger(__VA_ARGS__);
#else
// use default logging
#define ESCARGOT_LOG_INFO(...) fprintf(stdout, __VA_ARGS__);
#define ESCARGOT_LOG_ERROR(...) fprintf(stderr, __VA_ARGS__);
@ -333,6 +344,7 @@ typedef int32_t UChar32;
#define ESCARGOT_LOG_INFO(...) dlog_print(DLOG_INFO, "Escargot", __VA_ARGS__);
#define ESCARGOT_LOG_ERROR(...) dlog_print(DLOG_ERROR, "Escargot", __VA_ARGS__);
#endif
#endif
#ifndef CRASH
#define CRASH ASSERT_NOT_REACHED

View file

@ -183,6 +183,18 @@ public:
m_platform->deallocateThreadLocalCustomData();
}
#ifdef ESCARGOT_USE_CUSTOM_LOGGING
virtual void customInfoLogger(const char* format, va_list arg) override
{
m_platform->customInfoLogger(format, arg);
}
virtual void customErrorLogger(const char* format, va_list arg) override
{
m_platform->customErrorLogger(format, arg);
}
#endif
private:
PlatformRef* m_platform;
};

View file

@ -1945,6 +1945,19 @@ public:
// do nothing
}
#ifdef ESCARGOT_USE_CUSTOM_LOGGING
// default custom logger
virtual void customInfoLogger(const char* format, va_list arg)
{
vfprintf(stdout, format, arg);
}
virtual void customErrorLogger(const char* format, va_list arg)
{
vfprintf(stderr, format, arg);
}
#endif
void* threadLocalCustomData();
};

View file

@ -24,7 +24,6 @@
#include "runtime/GlobalObject.h"
#include "runtime/RegExpObject.h"
#include "runtime/StaticStrings.h"
#include "runtime/String.h"
namespace Escargot {

View file

@ -100,4 +100,21 @@ Global::Waiter* Global::waiter(void* blockAddress)
}
#endif
#ifdef ESCARGOT_USE_CUSTOM_LOGGING
void customEscargotInfoLogger(const char* format, ...)
{
va_list arg;
va_start(arg, format);
Global::platform()->customInfoLogger(format, arg);
va_end(arg);
}
void customEscargotErrorLogger(const char* format, ...)
{
va_list arg;
va_start(arg, format);
Global::platform()->customErrorLogger(format, arg);
va_end(arg);
}
#endif
} // namespace Escargot

View file

@ -53,6 +53,12 @@ public:
// ThreadLocal custom data (g_customData)
virtual void* allocateThreadLocalCustomData() = 0;
virtual void deallocateThreadLocalCustomData() = 0;
#ifdef ESCARGOT_USE_CUSTOM_LOGGING
// customized logging
virtual void customInfoLogger(const char* format, va_list arg) = 0;
virtual void customErrorLogger(const char* format, va_list arg) = 0;
#endif
};
} // namespace Escargot

View file

@ -115,9 +115,6 @@ private:
uint64_t m_start;
const char* m_msg;
};
} // namespace Escargot
namespace Escargot {
namespace detail {