2
votes

I'm using Sonata Admin bundle in my Symfony project. I see many console log messages in the browser generated by Sonata admin bundle.

enter image description here

These messages are generated by Sonata Admin 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);
    }
},

Does anyone know how to disable these log messages? I don't even get any kind of result from Google search. Is there a way to control these from configuration file or something?

Thanks in advance!!

2
Hi, do you also get these logs in prod environment ? Or just in dev ? Do you need any console logs ? (ie Would you mind disable all console ?)S. Bureau
I'm getting these logs both in dev & prod environment. I don't need logs from Sonata admin.Vinoth Kumar
Well, if you don't need logs AT ALL (not just Sonata Admin) ! You could use this : stackoverflow.com/questions/1215392/… I don't use Sonata, you could create an issue on the official repo to get some help from the users.S. Bureau
I'll need logs generated by my code. I just need to disable logs from Sonata Admin. As you said, I think I need to create issue in official repo. I'll post my answer if got solution. Thanks!!Vinoth Kumar

2 Answers

1
votes

I have opened a issue in Sonata Admin GitHub repo https://github.com/sonata-project/SonataAdminBundle/issues/5278 and found the solution.

You have to override the sonata admin's standard_layout like,

/config/packages/sonata_admin.yaml

sonata_admin
    templates:
        layout: 'sonata_admin/layout.html.twig'

Now create layout.html.twig inside /templates/sonata_admin/ and use the following code.

{% extends '@SonataAdmin/standard_layout.html.twig' %}

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

If you don't need any Sonata comments at all, I suggest you to comment that code and you should be done. If some error appears (for example, if the function "log()" is called anywhere in the code), you can just comment these two lines:

window.console.log(msg);
window.opera.postError(msg);