Skip to content

Reduce async console logger #33850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: 2.4-develop
Choose a base branch
from
29 changes: 14 additions & 15 deletions app/code/Magento/PageCache/view/frontend/web/js/page-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
define([
'jquery',
'domReady',
'consoleLogger',
'Magento_PageCache/js/form-key-provider',
'jquery-ui-modules/widget',
'mage/cookies'
], function ($, domReady, consoleLogger, formKeyInit) {
], function ($, domReady, formKeyInit) {
'use strict';

/**
Expand Down Expand Up @@ -45,31 +44,31 @@ define([
* @param {jQuery} element - Comment holder
*/
(function lookup(element) {
var iframeHostName;

// prevent cross origin iframe content reading
if ($(element).prop('tagName') === 'IFRAME') {
iframeHostName = $('<a>').prop('href', $(element).prop('src'))
.prop('hostname');

if (window.location.hostname !== iframeHostName) {
return [];
}
}

/**
* Rewrite jQuery contents().
*
* @param {jQuery} elem
*/
contents = function (elem) {
return $.map(elem, function (el) {
var iframeHostName;

// prevent cross origin iframe content reading
if ($(element).prop('tagName') === 'IFRAME') {
iframeHostName = $('<a>').prop('href', $(element).prop('src'))
.prop('hostname');

if (window.location.hostname !== iframeHostName) {
return [];
}
}

try {
return el.nodeName.toLowerCase() === 'iframe' ?
el.contentDocument || (el.contentWindow ? el.contentWindow.document : []) :
$.merge([], el.childNodes);
} catch (e) {
consoleLogger.error(e);
console.error(e);

return [];
}
Expand Down
36 changes: 9 additions & 27 deletions app/code/Magento/Ui/view/base/web/js/core/renderer/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ define([
'jquery',
'mageUtils',
'uiRegistry',
'./types',
'../../lib/logger/console-logger'
], function (_, $, utils, registry, types, consoleLogger) {
'./types'
], function (_, $, utils, registry, types) {
'use strict';

var templates = registry.create(),
Expand Down Expand Up @@ -71,25 +70,7 @@ define([
* @returns {jQueryPromise}
*/
function loadDeps(node) {
var loaded = $.Deferred(),
loggerUtils = consoleLogger.utils;

if (node.deps) {
consoleLogger.utils.asyncLog(
loaded,
{
data: {
component: node.name,
deps: node.deps
},
messages: loggerUtils.createMessages(
'depsStartRequesting',
'depsFinishRequesting',
'depsLoadingFail'
)
}
);
}
var loaded = $.Deferred();

registry.get(node.deps, function (deps) {
node.provider = node.extendProvider ? deps && deps.name : node.provider;
Expand All @@ -109,17 +90,18 @@ define([
var loaded = $.Deferred(),
source = node.component;

consoleLogger.info('componentStartLoading', {
console.info('componentStartLoading', {
component: node.component
});

require([source], function (constr) {
consoleLogger.info('componentFinishLoading', {
console.info('componentFinishLoading', {
component: node.component
});
loaded.resolve(node, constr);
}, function () {
consoleLogger.error('componentLoadingFail', {
}, function (e) {
console.log(e);
console.error('componentLoadingFail', {
component: node.component
});
});
Expand All @@ -136,7 +118,7 @@ define([
function initComponent(node, Constr) {
var component = new Constr(_.omit(node, 'children'));

consoleLogger.info('componentStartInitialization', {
console.info('componentStartInitialization', {
component: node.component,
componentName: node.name
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ define([
'uiRegistry',
'mage/translate',
'../template/renderer',
'jquery',
'../../logger/console-logger'
], function (ko, registry, $t, renderer, $, consoleLogger) {
'jquery'
], function (ko, registry, $t, renderer, $) {
'use strict';

/**
Expand Down Expand Up @@ -58,24 +57,9 @@ define([
update: function (el, valueAccessor, allBindings, viewModel, bindingContext) {
var component = valueAccessor(),
promise = $.Deferred(),
apply = applyComponents.bind(this, el, bindingContext, promise),
loggerUtils = consoleLogger.utils;
apply = applyComponents.bind(this, el, bindingContext, promise);

if (typeof component === 'string') {
loggerUtils.asyncLog(
promise,
{
data: {
component: component
},
messages: loggerUtils.createMessages(
'requestingComponent',
'requestingComponentIsLoaded',
'requestingComponentIsFailed'
)
}
);

registry.get(component, apply);
} else if (typeof component === 'function') {
component(apply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ define([
'ko',
'underscore',
'./observable_source',
'./renderer',
'../../logger/console-logger'
], function ($, ko, _, Source, renderer, consoleLogger) {
'./renderer'
], function ($, ko, _, Source, renderer) {
'use strict';

var RemoteTemplateEngine,
Expand Down Expand Up @@ -70,13 +69,14 @@ define([
}

if (!options.name) {
consoleLogger.error('Could not find template name', options);
console.error('Could not find template name', options);
}

templateName = options.name;
} else if (typeof options === 'string') {
templateName = options;
} else {
consoleLogger.error('Could not build a template binding', options);
console.error('Could not build a template binding', options);
}
engine._trackRender(templateName);
isSync = engine._hasTemplateLoaded(templateName);
Expand Down Expand Up @@ -184,28 +184,29 @@ define([
source.requestedBy = bindingContext.$data.name;
sources[templateId] = source;

consoleLogger.info('templateStartLoading', {
console.info('templateStartLoading', {
template: templateId,
component: bindingContext.$data.name
});

renderer.render(template).then(function (rendered) {
consoleLogger.info('templateLoadedFromServer', {
console.info('templateLoadedFromServer', {
template: templateId,
component: bindingContext.$data.name
});

source.nodes(rendered);
engine._releaseRender(templateId, 'async');
}).fail(function () {
consoleLogger.error('templateLoadingFail', {
console.error('templateLoadingFail', {
template: templateId,
component: bindingContext.$data.name
});
});
}

if (source.requestedBy !== bindingContext.$data.name) {
consoleLogger.info('templateLoadedFromCache', {
console.info('templateLoadedFromCache', {
template: templateId,
component: bindingContext.$data.name
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ define([

it('on empty node comments() returns empty Array', function () {
expect($(element).comments()).toEqual([]);
expect($(iframe).insertAfter('body').comments()).toEqual([]);
expect($(iframe).comments()).toEqual([]);
});

it('on non-empty node comments() returns empty Array with nodes', function () {
Expand Down