Sonataadminbundle: Disable console.log() messages

Created on 25 Oct 2018  路  9Comments  路  Source: sonata-project/SonataAdminBundle

I see many console log messages in the browser generated by Sonata admin bundle.

7kwb0

These messages are generated from /vendor/sonata-project/admin-bundle/src/Resources/public/Admin.js by the code,

/**
 * render log message
 * @param mixed
 */
log: function() {
    var msg = '[Sonata.Admin] ' + Array.prototype.join.call(arguments,', ');
    if (window.console && window.console.log) {
        window.console.log(msg);
    } else if (window.opera && window.opera.postError) {
        window.opera.postError(msg);
    }
},

I don't need these logs to be generated in the browser. Is there a way to control these from configuration file or something?

Easy Pick hacktoberfest

Most helpful comment

IMHO we should switch the actual behaviour. So that we have a logger function that does nothing, but you can override/enable it if you want

All 9 comments

Does these logs occur on prod?

Yes. Both dev and prod environment.

You can customize the layout and override that function:

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

{% block javascripts %}
  {{ parent() }}
  <script>
    if ('undefined' !== typeof window.Admin) {
      window.Admin.log = function() {}
    }
  </script>
{% endblock %}

@bgaleotti Thanks, it works.

But logging console messages even in production environment is the actual implementation or is it a bug?

IMHO we should switch the actual behaviour. So that we have a logger function that does nothing, but you can override/enable it if you want

Yes, I have overrided the standard_layout to disable it. Thanks for the support. Can I close this issue now?

No please keep it to open until we have a better solution

Sure

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peter-gribanov picture peter-gribanov  路  3Comments

vazgen picture vazgen  路  4Comments

jenyak picture jenyak  路  3Comments

Max93 picture Max93  路  3Comments

SlimenTN picture SlimenTN  路  3Comments