Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Log / JSTizenLog.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
17
18 /**
19  * @file        JSTizenLog
20  * @author      Sang-tai Kim(sangtai.kim@samsung.com)
21  * @version     0.1
22  */
23
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>
30
31 #include "JSTizenLog.h"
32
33 #include <dlog.h>
34
35 #ifdef LOG_TAG
36 #undef LOG_TAG
37 #endif
38
39 #define LOG_TAG "TIZEN"
40
41 #define EXCEPTION_COLOR    "\033[1;31;40m"  //bold and red
42 #define ASSERT_COLOR       "\033[1;31;40m"  //bold and red
43
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
51
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);}
56
57 namespace TizenApis {
58 namespace Tizen1_0 {
59
60 using namespace WrtDeviceApis::Commons;
61 using namespace WrtDeviceApis;
62
63 JSClassDefinition JSTizenLog::m_classInfo =
64 {
65     0,
66     kJSClassAttributeNone,
67     "log",
68     0,
69     NULL,
70     m_function,
71     initialize,
72     finalize,
73     NULL, //hasProperty,
74     NULL, //getProperty,
75     NULL, //setProperty,
76     NULL, //DeleteProperty,
77     NULL, //GetPropertyNames,
78     NULL, //CallAsFunction,
79     NULL, //CallAsConstructor,
80     NULL, //HasInstance,
81     NULL, //ConvertToType
82 };
83
84 const JSClassRef JSTizenLog::getClassRef() {
85     if (!m_jsClassRef) {
86         m_jsClassRef = JSClassCreate(&m_classInfo);
87     }
88     return m_jsClassRef;
89 }
90
91 const JSClassDefinition* JSTizenLog::getClassInfo() {
92     return &m_classInfo;
93 }
94
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},
100     { 0, 0, 0 }
101 };
102
103 JSClassRef JSTizenLog::m_jsClassRef =
104   JSClassCreate(JSTizenLog::getClassInfo());
105
106
107 void JSTizenLog::initialize(JSContextRef context, JSObjectRef object) {
108 //    TIZEN_DEBUG("<<<");
109 }
110
111 void JSTizenLog::finalize(JSObjectRef object) {
112 //    TIZEN_DEBUG("<<<");
113 }
114
115 JSValueRef JSTizenLog::logDebug(JSContextRef context, JSObjectRef object,
116                 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
117                 JSValueRef* exception) {
118
119         CommonsJavaScript::Converter converter(context);
120         std::string pattern = converter.toString(argv[0]);
121
122         TIZEN_DEBUG("[%s]", pattern.c_str());
123
124         return JSValueMakeUndefined(context);
125 }
126
127 JSValueRef JSTizenLog::logInfo(JSContextRef context, JSObjectRef object,
128                 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
129                 JSValueRef* exception) {
130
131         CommonsJavaScript::Converter converter(context);
132         std::string pattern = converter.toString(argv[0]);
133
134         TIZEN_INFO("[%s]", pattern.c_str());
135
136         return JSValueMakeUndefined(context);
137 }
138
139 JSValueRef JSTizenLog::logWarning(JSContextRef context, JSObjectRef object,
140                 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
141                 JSValueRef* exception) {
142
143         CommonsJavaScript::Converter converter(context);
144         std::string pattern = converter.toString(argv[0]);
145
146         TIZEN_WANING("[%s]", pattern.c_str());
147
148         return JSValueMakeUndefined(context);
149 }
150
151 JSValueRef JSTizenLog::logError(JSContextRef context, JSObjectRef object,
152                 JSObjectRef thisObject, size_t argc, const JSValueRef argv[],
153                 JSValueRef* exception) {
154
155         CommonsJavaScript::Converter converter(context);
156         std::string pattern = converter.toString(argv[0]);
157
158         TIZEN_ERROR("[%s]", pattern.c_str());
159
160         return JSValueMakeUndefined(context);
161 }
162
163 } // Tizen1_0
164 } // TizenApis