MCPcopy
hub / github.com/ionic-team/capacitor / initLogger

Function initLogger

android/capacitor/src/main/assets/native-bridge.js:316–825  ·  view source on GitHub ↗
(win, cap)

Source from the content-addressed store, hash-verified

314 win.Ionic.WebView = IonicWebView;
315 };
316 const initLogger = (win, cap) => {
317 const BRIDGED_CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn'];
318 const createLogFromNative = (c) => (result) => {
319 if (isFullConsole(c)) {
320 const success = result.success === true;
321 const tagStyles = success
322 ? 'font-style: italic; font-weight: lighter; color: gray'
323 : 'font-style: italic; font-weight: lighter; color: red';
324 c.groupCollapsed('%cresult %c' + result.pluginId + '.' + result.methodName + ' (#' + result.callbackId + ')', tagStyles, 'font-style: italic; font-weight: bold; color: #444');
325 if (result.success === false) {
326 c.error(result.error);
327 }
328 else {
329 c.dir(JSON.stringify(result.data));
330 }
331 c.groupEnd();
332 }
333 else {
334 if (result.success === false) {
335 c.error('LOG FROM NATIVE', result.error);
336 }
337 else {
338 c.log('LOG FROM NATIVE', result.data);
339 }
340 }
341 };
342 const createLogToNative = (c) => (call) => {
343 if (isFullConsole(c)) {
344 c.groupCollapsed('%cnative %c' + call.pluginId + '.' + call.methodName + ' (#' + call.callbackId + ')', 'font-weight: lighter; color: gray', 'font-weight: bold; color: #000');
345 c.dir(call);
346 c.groupEnd();
347 }
348 else {
349 c.log('LOG TO NATIVE: ', call);
350 }
351 };
352 const isFullConsole = (c) => {
353 if (!c) {
354 return false;
355 }
356 return typeof c.groupCollapsed === 'function' || typeof c.groupEnd === 'function' || typeof c.dir === 'function';
357 };
358 const serializeConsoleMessage = (msg) => {
359 try {
360 if (typeof msg === 'object') {
361 msg = JSON.stringify(msg);
362 }
363 return String(msg);
364 }
365 catch (e) {
366 return '';
367 }
368 };
369 const platform = getPlatformId(win);
370 if (platform == 'android' && typeof win.CapacitorSystemBarsAndroidInterface !== 'undefined') {
371 // add DOM ready listener for System Bars
372 document.addEventListener('DOMContentLoaded', function () {
373 win.CapacitorSystemBarsAndroidInterface.onDOMReady();

Callers 1

initNativeBridgeFunction · 0.70

Calls 15

addEventListenerMethod · 0.80
onDOMReadyMethod · 0.80
rejectMethod · 0.80
thenMethod · 0.80
catchMethod · 0.80
errorMethod · 0.80
warnMethod · 0.80
infoMethod · 0.80
getPlatformIdFunction · 0.70
createProxyUrlFunction · 0.70
convertBodyFunction · 0.70
isRelativeOrProxyUrlFunction · 0.70

Tested by

no test coverage detected