From: DongHyun Song Date: Mon, 30 Aug 2021 01:44:10 +0000 (+0900) Subject: [Service] Change console.debug() to distinguish from console.log() X-Git-Tag: submit/tizen/20210831.160020~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=961666a491e8fbaaa6adcd6fbd6f6b2b877a9d1a;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service] Change console.debug() to distinguish from console.log() Occasionally, it is confused that a certain console.log is from application or wrtjs. Thus, it needs to distinguish application's console.log and wrtjs's log. Change-Id: I027b37f1d969932244a5dbf4b208264fe85dbe26 Signed-off-by: DongHyun Song --- diff --git a/wrt_app/browser/wrt.ts b/wrt_app/browser/wrt.ts index 180dcfe7..ed89c2b0 100755 --- a/wrt_app/browser/wrt.ts +++ b/wrt_app/browser/wrt.ts @@ -19,9 +19,14 @@ import * as util from 'util'; export const { wrt }: NativeWRTjs.WRTBinding = process.wrtBinding('wrt'); Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype); -console.log = console.info = console.error = console.warn = function(format: any, ...param: any[]) { +console.log = console.info = console.error = console.warn = (format: any, ...param: any[]) => { wrt.log(util.format(format, ...param)); }; + +console.debug = (format: any, ...param: any[]) => { + wrt.log(`[debug] ${util.format(format, ...param)}`); +}; + console.logd = console.logv = console.loge = console.log; function write(chunk: Uint8Array | string, encoding?: any, callback?: (err?: Error) => void): boolean { diff --git a/wrt_app/common/wrt_xwalk_extension.ts b/wrt_app/common/wrt_xwalk_extension.ts index 187082aa..94903459 100644 --- a/wrt_app/common/wrt_xwalk_extension.ts +++ b/wrt_app/common/wrt_xwalk_extension.ts @@ -31,7 +31,7 @@ class XWalkExtension { var extensions: NativeXWalkExtension[] = binding.getExtensions(); for (var i = 0; i < extensions.length; i++) { extensions[i].loaded = false; - console.log("Load extension : " + extensions[i].name); + console.debug("Load extension : " + extensions[i].name); extensions_[extensions[i].name] = extensions[i]; } for (var name in extensions_) { @@ -100,7 +100,7 @@ class XWalkExtension { } static runtimeMessageHandler(type: string, data?: string, callback?: (message: string) => void): void { - console.log('This is prototype of runtimeMessageHandler'); + console.debug('This is prototype of runtimeMessageHandler'); } /** @@ -119,7 +119,7 @@ class XWalkExtension { var api = (ext.use_trampoline) ? api_ : global; var extension_api = ext.jsapi; if (global.serviceType === 'GLOBAL' && ext.name === 'xwalk') { - console.log(`Delete freeze exports.utils for override method`); + console.debug(`Delete freeze exports.utils for override method`); extension_api = extension_api.replace('Object.freeze(exports.utils);', ''); extension_api = extension_api.replace('Object.freeze(Utils.prototype);', ''); } @@ -160,7 +160,7 @@ class XWalkExtension { this.exposeApi(ext); } } catch (err) { - console.log('Error loading extension "' + ext.name + '": ' + err.message); + console.debug('Error loading extension "' + ext.name + '": ' + err.message); } } @@ -188,7 +188,7 @@ class XWalkExtension { this.load(ext); return api_[parent_name][base_name]; } catch (e) { - console.log(e.stack); + console.debug(e.stack); } }.bind(this); }.call(this, parent_name, base_name), diff --git a/wrt_app/service/builtins/appmanifest_loader.ts b/wrt_app/service/builtins/appmanifest_loader.ts index e074d455..40bd03b4 100644 --- a/wrt_app/service/builtins/appmanifest_loader.ts +++ b/wrt_app/service/builtins/appmanifest_loader.ts @@ -7,7 +7,7 @@ import * as https from 'https'; import * as XWalkExtension from '../../common/wrt_xwalk_extension'; function getManifestFile(manifestUrl: string) { - console.log('manifestUrl : '+manifestUrl); + console.debug('manifestUrl : '+manifestUrl); return new Promise((resolve, reject) => { const req = https.request(manifestUrl, (res) => { res.setEncoding('utf8'); @@ -19,7 +19,7 @@ function getManifestFile(manifestUrl: string) { resolve(JSON.parse(responseBody)); }); }).on('error', (err) => { - console.log(`error : ${err}`); + console.debug(`error : ${err}`); reject(err); }); req.end(); @@ -27,7 +27,7 @@ function getManifestFile(manifestUrl: string) { } async function downloadIcon(iconSrc: string, iconFile: string) { - console.log('iconSrc : ' + iconSrc); + console.debug('iconSrc : ' + iconSrc); return new Promise((resolve, reject) => { const req = https.request(iconSrc, (res) => { const Stream = require('stream').Transform; @@ -40,7 +40,7 @@ async function downloadIcon(iconSrc: string, iconFile: string) { resolve('done'); }); }).on('error', (err) => { - console.log(`error : ${err}`); + console.debug(`error : ${err}`); reject(err); }); req.end(); @@ -71,7 +71,7 @@ let refCount: number = 0; function getAppName(appName: string) { appName = appName.replace(/ /g, ''); - console.log('appName : ' + appName); + console.debug('appName : ' + appName); return appName; } @@ -80,7 +80,7 @@ function makeWorkingFolder(appName: string) { fs.rmdirSync(workingDir, { recursive: true }); fs.mkdir(workingDir, { recursive: true }, (err) => { if (err) - console.log(`mkdir error : ${err}`) + console.debug(`mkdir error : ${err}`) }); } @@ -105,7 +105,7 @@ function makeManifestFile(appName: string, manifest: any) { function makePkgId(startUrl: string) { let id = Buffer.from(startUrl).toString('base64'); id = id.replace(/=/gi, ''); - console.log(`id : ${id}`); + console.debug(`id : ${id}`); return id.substr(-10); } @@ -134,7 +134,7 @@ function cleanUpAndQuit(appName: string) { function installWgt(appName: string) { let wgtPath = `${baseWorkingDir}/${appName}/${appName}.wgt`; let installinfo = "{\"app_id\":\"" + appName + "\",\"pkg_path\":\"" + wgtPath + "\"}"; - console.log(`installWgt info: ${installinfo}`); + console.debug(`installWgt info: ${installinfo}`); (wrt.tv as any).notifyInstall(installinfo); process.exit(); } @@ -143,18 +143,18 @@ function makeWgt(appName: string) { let wgtPath = `${downloadVirtualDir}/${appName}/${appName}.wgt`; let onArchive = (archive: any) => { function progressCallback(opId: string, val: number, name: any) { - console.log('opId: ' + opId + ' with progress val: ' + (val * 100).toFixed(0) + '%'); + console.debug('opId: ' + opId + ' with progress val: ' + (val * 100).toFixed(0) + '%'); } function successCallback() { - console.log(`File added : ${refCount}`); + console.debug(`File added : ${refCount}`); refCount--; if (!refCount) { installWgt(appName); } } - console.log(`convertedConfigXml : ${convertedConfigXml}`); - console.log(`manifestFile : ${manifestFile}`); - console.log(`iconFile : ${iconFile}`); + console.debug(`convertedConfigXml : ${convertedConfigXml}`); + console.debug(`manifestFile : ${manifestFile}`); + console.debug(`iconFile : ${iconFile}`); let defaultArchiveFileEntryOption = { destination:'', stripSourceDirectory: true}; archive.add(convertedConfigXml, successCallback, null, progressCallback, defaultArchiveFileEntryOption); archive.add(manifestFile, successCallback, null, progressCallback, defaultArchiveFileEntryOption); @@ -181,13 +181,13 @@ async function parseAndHandleManifest(manifestUrl: string) { } makeWgt(appName); } catch (e) { - console.log(`Exception: ${e}`); + console.debug(`Exception: ${e}`); cleanUpAndQuit(appName); } } export function run(manifestUrl: string) { - console.log(`Appmanifest parser starts for ${manifestUrl}`); + console.debug(`Appmanifest parser starts for ${manifestUrl}`); setInterval(() => { }, 500); wrt.tv?.delayShutdown(); XWalkExtension.initialize(); diff --git a/wrt_app/service/builtins/wasm_builder.ts b/wrt_app/service/builtins/wasm_builder.ts index e23ac17b..b9ceca9a 100644 --- a/wrt_app/service/builtins/wasm_builder.ts +++ b/wrt_app/service/builtins/wasm_builder.ts @@ -6,7 +6,7 @@ import * as fs from 'fs'; function compileWasmForCaching(files: string[]) { try { files.forEach(async filePath => { - console.log(`Requesting WASM compilation for building a cache, file_path:(${filePath})`); + console.debug(`Requesting WASM compilation for building a cache, file_path:(${filePath})`); let source = fs.readFileSync(filePath); let file = new Uint8Array(source); await WebAssembly.compile(file); @@ -17,12 +17,12 @@ function compileWasmForCaching(files: string[]) { } export function run(appId: string) { - console.log(`wasm_builder.js starts, app_id:(${appId})`); + console.debug(`wasm_builder.js starts, app_id:(${appId})`); let tv = wrt.tv as NativeWRTjs.TVExtension; tv.setWasmFlags(); tv.setDiskCache(appId); let files = tv.getWasmFiles(appId); - console.log(files); + console.debug(files); tv.delayShutdown(); compileWasmForCaching(files); process.exit(); diff --git a/wrt_app/service/device_api_router.ts b/wrt_app/service/device_api_router.ts index 2c601d05..1c4f610a 100644 --- a/wrt_app/service/device_api_router.ts +++ b/wrt_app/service/device_api_router.ts @@ -200,7 +200,7 @@ export class DeviceAPIRouter { // tizen.application.getCurrentApplication() this.funcCurrentApplication = global.tizen.application.getCurrentApplication; global.tizen.application.getCurrentApplication = () => { - console.log(`Routing - getCurrentApplication() : ${this.getServiceId()}`); + console.debug(`Routing - getCurrentApplication() : ${this.getServiceId()}`); if (this.currentApplication) return this.currentApplication; this.currentApplication = {}; @@ -234,7 +234,7 @@ export class DeviceAPIRouter { // tizen.application.getCurrentApplication().getRequestedAppControl() this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl; this.currentApplication.getRequestedAppControl = () => { - console.log(`Routing - getRequestedAppControl() : ${this.getServiceId()}`); + console.debug(`Routing - getRequestedAppControl() : ${this.getServiceId()}`); return this.funcRequestedAppcontrol(); } return this.currentApplication; @@ -245,7 +245,7 @@ export class DeviceAPIRouter { let app_id = args[0]; if (this.hasNoneOrNull(args)) app_id = this.getServiceId(); - console.log(`Routing - getAppInfo(${app_id})`); + console.debug(`Routing - getAppInfo(${app_id})`); return this.funcGetAppInfo(app_id); } // tizen.application.getAppCerts() @@ -254,13 +254,13 @@ export class DeviceAPIRouter { let app_id = args[0]; if (this.hasNoneOrNull(args)) app_id = this.getServiceId(); - console.log(`Routing - getAppCerts() ` + app_id); + console.debug(`Routing - getAppCerts() ` + app_id); return this.funcGetAppcerts(app_id); } // tizen.application.getAppContext() this.funcGetContext = global.tizen.application.getAppContext; global.tizen.application.getAppContext = (...args: any[]) => { - console.log(`Routing - getAppContext()`); + console.debug(`Routing - getAppContext()`); if (this.hasNoneOrNull(args)) { const context = {"id": this.funcGetContext().id, "appId": this.getServiceId()}; Object.defineProperties(context, { @@ -277,7 +277,7 @@ export class DeviceAPIRouter { let app_id = args[0]; if (this.hasNoneOrNull(args)) app_id = this.getServiceId(); - console.log(`Routing - getAppSharedURI()`); + console.debug(`Routing - getAppSharedURI()`); return this.funcGetSharedUri(app_id); } // tizen.application.getAppMetaData() @@ -286,7 +286,7 @@ export class DeviceAPIRouter { let app_id = args[0]; if (this.hasNoneOrNull(args)) app_id = this.getServiceId(); - console.log(`Routing - getAppMetaData()`); + console.debug(`Routing - getAppMetaData()`); return this.funcGetMetadata(app_id); } } @@ -298,7 +298,7 @@ export class DeviceAPIRouter { let package_id = args[0]; if (this.hasNoneOrNull(args)) package_id = this.getPackageId(); - console.log(`Routing - getPackageInfo() : ${package_id}`); + console.debug(`Routing - getPackageInfo() : ${package_id}`); return this.funcGetPackageInfo(package_id); } } @@ -311,7 +311,7 @@ export class DeviceAPIRouter { global.tizen.filesystem.setVirtualPath(name, realPath, 'INTERVAL', 'MOUNTED'); }); } catch (e) { - console.log(`refineFilesystemApis has an error ${e}`); + console.debug(`refineFilesystemApis has an error ${e}`); } } @@ -341,7 +341,7 @@ export class DeviceAPIRouter { "http://tizen.org/appcontrol/operation/default", null, null, null, data_payload, null); global.tizen.application.launchAppControl(appControl, this.serviceId, - () => console.log(`'${this.serviceId}::${name}' is requsted`)); + () => console.debug(`'${this.serviceId}::${name}' is requsted`)); } global.tizen.messageport.requestLocalMessagePort = (portName: string) => { diff --git a/wrt_app/service/main.ts b/wrt_app/service/main.ts index b0292ae8..7552ea91 100755 --- a/wrt_app/service/main.ts +++ b/wrt_app/service/main.ts @@ -21,17 +21,17 @@ import { wrt } from '../browser/wrt'; import * as ServiceManager from './service_manager'; wrt.on('start-service', (event: any, internal_id: string) => { - console.log(`start service app : ${internal_id}`); + console.debug(`start service app : ${internal_id}`); ServiceManager.startService(internal_id, ''); }); wrt.on('stop-service', (event: any, internal_id: string) => { - console.log(`stop service app : ${internal_id}`); + console.debug(`stop service app : ${internal_id}`); ServiceManager.stopService(internal_id); }); wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => { - console.log(`id: ${internal_id}, service_name: ${service_name}`); + console.debug(`id: ${internal_id}, service_name: ${service_name}`); ServiceManager.handleBuiltinService(internal_id, service_name); }); @@ -40,5 +40,5 @@ wrt.on('quit', (event: any) => { }); process.on('exit', (code) => { - console.log('Exit with code : ' + code); + console.debug('Exit with code : ' + code); }); diff --git a/wrt_app/service/service_manager.ts b/wrt_app/service/service_manager.ts index 66213f6b..9f8d3e5a 100644 --- a/wrt_app/service/service_manager.ts +++ b/wrt_app/service/service_manager.ts @@ -32,21 +32,21 @@ function createWorker(id: string, startService: string, filename: string) { workers[id].on('exit', (code: number) => { delete workers[id]; let runningServices = Object.keys(workers).length; - console.log(`exit code(${code}), remain services(${runningServices})`); + console.debug(`exit code(${code}), remain services(${runningServices})`); }); } function terminateWorker(id: string, delay: number) { if (!workers[id]) { - console.log(`This worker is already terminated. ${id}`); + console.debug(`This worker is already terminated. ${id}`); return; } - console.log(`${id} will shutdown after ${delay}ms`); + console.debug(`${id} will shutdown after ${delay}ms`); workers[id].postMessage({ type: 'stop', delay }); } export function startService(id: string, filename: string) { - console.log(`startService - ${id}`); + console.debug(`startService - ${id}`); if (global['serviceType'] === 'STANDALONE') { let ids = id.split(':'); let serviceId = ids[0]; @@ -58,7 +58,7 @@ export function startService(id: string, filename: string) { } export function stopService(id: string) { - console.log(`stopService - ${id}`); + console.debug(`stopService - ${id}`); terminateWorker(id, 500); } @@ -68,10 +68,10 @@ export function handleBuiltinService(serviceId: string, serviceName: string) { } let need_stop = (serviceName.substr(0, 5) === 'stop_'); if (need_stop) { - console.log(`${serviceName} will be terminated.`); + console.debug(`${serviceName} will be terminated.`); workers[serviceId].terminate(); } else { - console.log(`Builtin service is ${serviceName}`); + console.debug(`Builtin service is ${serviceName}`); let startService = `${__dirname}/../service/builtins/${serviceName}.js`; createWorker(serviceId, startService, ''); } diff --git a/wrt_app/service/service_runner.ts b/wrt_app/service/service_runner.ts index 0dc0ae68..2b382357 100644 --- a/wrt_app/service/service_runner.ts +++ b/wrt_app/service/service_runner.ts @@ -19,11 +19,11 @@ function isGlobalService() { function printAppControlData(id: string) { let reqAppControl = global.tizen.application.getCurrentApplication().getRequestedAppControl(); if (reqAppControl) { - console.log(`id: ${id}, appControlData operation: ${reqAppControl.appControl.operation}`); + console.debug(`id: ${id}, appControlData operation: ${reqAppControl.appControl.operation}`); let appControlData = reqAppControl.appControl.data; for (let dataIndex in appControlData) { for (let valueIndex in appControlData[dataIndex].value) - console.log(`data[${dataIndex}][${valueIndex}]: ${appControlData[dataIndex].value[valueIndex]}`); + console.debug(`data[${dataIndex}][${valueIndex}]: ${appControlData[dataIndex].value[valueIndex]}`); } } } @@ -31,7 +31,7 @@ function printAppControlData(id: string) { function registerExtensionResolver(id: string) { if (wrt.tv) { let extensionResolver = (module: any, file_path: string) => { - console.log(`resolved path: ${file_path}`); + console.debug(`resolved path: ${file_path}`); let content = (wrt.tv as NativeWRTjs.TVExtension).decryptFile(id, file_path); if (content) { // Remove BOM @@ -59,7 +59,7 @@ let checkLauncherAlive = (id: string) => { if (!periodLauncherAlive) { periodLauncherAlive = 20; if (!wrt.checkLauncherAlive(id)) { - console.log(`${id} launcher was killed.`) + console.debug(`${id} launcher was killed.`) requestStopService(id); checkLauncherAlive = () => {}; } @@ -71,12 +71,12 @@ export function start(id: string, filename: string) { XWalkExtension.initialize(); XWalkExtension.setRuntimeMessageHandler((type, data) => { if (type === 'tizen://exit') { - console.log(`${id} will be closed by ${type}`); + console.debug(`${id} will be closed by ${type}`); requestStopService(id); } }); - console.log(`serviceType : ${global['serviceType']}`) + console.debug(`serviceType : ${global['serviceType']}`) new DeviceAPIRouter(id, isGlobalService()); // this is workaround solution to make webapis singleton worker @@ -93,7 +93,7 @@ export function start(id: string, filename: string) { if (isServiceApplication()) { registerExtensionResolver(id); filename = wrt.getStartServiceFile(id); - console.log(`start global service file: ${filename}`); + console.debug(`start global service file: ${filename}`); } try { @@ -114,7 +114,7 @@ export function start(id: string, filename: string) { wrt.finishStartingService(id); } } catch (e) { - console.log(`exception on start: ${e}`); + console.debug(`exception on start: ${e}`); requestStopService(id); } } @@ -129,7 +129,7 @@ export function stop(id: string) { app.onExit(); } } catch (e) { - console.log(`exception on stop: ${e}`); + console.debug(`exception on stop: ${e}`); } } @@ -144,7 +144,7 @@ function run() { if (!parentPort) return; parentPort.on('message', (message) => { - console.log(`Received message type : ${message.type}`); + console.debug(`Received message type : ${message.type}`); if (message.type === 'wake') { app?.onRequest(); } else if (message.type === 'stop') { diff --git a/wrt_app/service/timer_manager.ts b/wrt_app/service/timer_manager.ts deleted file mode 100644 index deace6e1..00000000 --- a/wrt_app/service/timer_manager.ts +++ /dev/null @@ -1,62 +0,0 @@ -interface TimerAPI { - clearInterval(id: NodeJS.Timeout): void; - clearTimeout(id: NodeJS.Timeout): void; - setInterval(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout; - setTimeout(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout; - setServiceInterval(callback: (...args: any[]) => void, after:number, repeat:number): void; -} - -export class TimerManager { - interval_handlers: NodeJS.Timeout[] = []; - timeout_handlers: NodeJS.Timeout[] = []; - timer_api: TimerAPI; - constructor() { - this.timer_api = { - clearInterval: (handler) => { - const index = this.interval_handlers.indexOf(handler); - clearInterval(this.interval_handlers.splice(index, 1)[0]); - }, - clearTimeout: (handler) => { - const index = this.timeout_handlers.indexOf(handler); - clearTimeout(this.timeout_handlers.splice(index, 1)[0]); - }, - setInterval: (func, delay) => { - let id = setInterval(func, delay); - this.interval_handlers.push(id); - return id; - }, - setTimeout: (func, delay) => { - let id = setTimeout(func, delay); - this.timeout_handlers.push(id); - return id; - }, - setServiceInterval: (func, after = 1000, repeat = 0) => { - if (typeof func !== "function") { - console.log("Use function as the first parameter."); - return; - } - let count = 1; - let handler = this.timer_api.setInterval(() => { - func(); - count++; - if (count > repeat && repeat !== 0) { - this.timer_api.clearInterval(handler); - } - }, after); - } - } - } - getTimerAPI() { - return this.timer_api; - } - releaseRemainingTimers() { - console.log('Remaining interval(s) : ' + this.interval_handlers.length); - for (let id of this.interval_handlers) - clearInterval(id); - this.interval_handlers = []; - console.log('Remaining timer(s) : ' + this.timeout_handlers.length); - for (let id of this.timeout_handlers) - clearTimeout(id); - this.timeout_handlers = []; - } -}