2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * @author Sang-tai Kim(sangtai.kim@samsung.com)
24 #include <CommonsJavaScript/Converter.h>
25 #include <CommonsJavaScript/Validator.h>
26 #include <CommonsJavaScript/JSCallbackManager.h>
27 #include <CommonsJavaScript/JSUtils.h>
28 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
29 #include <CommonsJavaScript/Utils.h>
31 #include "JSTizenLog.h"
39 #define LOG_TAG "TIZEN"
41 #define EXCEPTION_COLOR "\033[1;31;40m" //bold and red
42 #define ASSERT_COLOR "\033[1;31;40m" //bold and red
44 #define GREEN_COLOR "\033[0;32;40m" //normal and green
45 #define NORMAL_COLOR "\033[0m" //system default
46 #define RED_COLOR "\033[0;31;40m" //normal and red
47 #define YELLOW_COLOR "\033[0;33m" //normal and yellow
48 #define BLUE_COLOR "\033[0;34m" //normal and blue
49 #define MAGENTA_COLOR "\033[0;35;40m" //normal and magenta
50 #define CYAN_COLOR "\033[0;36;40m" //normal and cyan
52 #define TIZEN_DEBUG(FM,ARG...) {LOGD("%s[%s]%s" FM, GREEN_COLOR, __FUNCTION__, NORMAL_COLOR, ##ARG);}
53 #define TIZEN_INFO(FM,ARG...) {LOGI("%s[%s]%s" FM, CYAN_COLOR, __FUNCTION__, NORMAL_COLOR, ##ARG);}
54 #define TIZEN_WANING(FM,ARG...) {LOGW("%s[%s]%s" FM, YELLOW_COLOR, __FUNCTION__, NORMAL_COLOR, ##ARG);}
55 #define TIZEN_ERROR(FM,ARG...) {LOGE("%s[%s]%s" FM, RED_COLOR, __FUNCTION__, NORMAL_COLOR, ##ARG);}
60 using namespace WrtDeviceApis::Commons;
61 using namespace WrtDeviceApis;
63 JSClassDefinition JSTizenLog::m_classInfo =
66 kJSClassAttributeNone,
76 NULL, //DeleteProperty,
77 NULL, //GetPropertyNames,
78 NULL, //CallAsFunction,
79 NULL, //CallAsConstructor,
84 const JSClassRef JSTizenLog::getClassRef() {
86 m_jsClassRef = JSClassCreate(&m_classInfo);
91 const JSClassDefinition* JSTizenLog::getClassInfo() {
95 JSStaticFunction JSTizenLog::m_function[] = {
96 { "debug", JSTizenLog::logDebug, kJSPropertyAttributeNone},
97 { "info", JSTizenLog::logInfo, kJSPropertyAttributeNone},
98 { "warning", JSTizenLog::logWarning, kJSPropertyAttributeNone},
99 { "error", JSTizenLog::logError, kJSPropertyAttributeNone},
103 JSClassRef JSTizenLog::m_jsClassRef =
104 JSClassCreate(JSTizenLog::getClassInfo());
107 void JSTizenLog::initialize(JSContextRef context, JSObjectRef object) {
108 // TIZEN_DEBUG("<<<");
111 void JSTizenLog::finalize(JSObjectRef object) {
112 // TIZEN_DEBUG("<<<");
115 JSValueRef JSTizenLog::logDebug(JSContextRef context, JSObjectRef object,
116 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
117 JSValueRef* exception) {
119 CommonsJavaScript::Converter converter(context);
120 std::string pattern = converter.toString(argv[0]);
122 TIZEN_DEBUG("[%s]", pattern.c_str());
124 return JSValueMakeUndefined(context);
127 JSValueRef JSTizenLog::logInfo(JSContextRef context, JSObjectRef object,
128 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
129 JSValueRef* exception) {
131 CommonsJavaScript::Converter converter(context);
132 std::string pattern = converter.toString(argv[0]);
134 TIZEN_INFO("[%s]", pattern.c_str());
136 return JSValueMakeUndefined(context);
139 JSValueRef JSTizenLog::logWarning(JSContextRef context, JSObjectRef object,
140 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
141 JSValueRef* exception) {
143 CommonsJavaScript::Converter converter(context);
144 std::string pattern = converter.toString(argv[0]);
146 TIZEN_WANING("[%s]", pattern.c_str());
148 return JSValueMakeUndefined(context);
151 JSValueRef JSTizenLog::logError(JSContextRef context, JSObjectRef object,
152 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
153 JSValueRef* exception) {
155 CommonsJavaScript::Converter converter(context);
156 std::string pattern = converter.toString(argv[0]);
158 TIZEN_ERROR("[%s]", pattern.c_str());
160 return JSValueMakeUndefined(context);