kint dumping javascript into log

Created on 18 August 2025, 15 days ago

Problem/Motivation

kint() is working fine on a page, however I also write to the debug log with ddm() this is coming out as HTML in the log (temporary://drupal_debug.txt).

Steps to reproduce

eg ddm('myrecvalue', date('Ymd His ') . __FUNCTION__ . " recrecrec");
in funtion doTable() is seen as:

</style><div class="kint-rich"><dl><dt><dfn>20250818 143034 doTable recrecrec</dfn> <var>string</var> (10) "myrecvalue"</dt></dl><footer><span class="kint-folder-trigger" title="Move to folder">&mapstodown;</span><nav></nav>Called from &lt;drupal&gt;/modules/contrib/devel/src/DevelDumperManager.php:138 [Drupal\kint\Plugin\Devel\Dumper\DevelDumper->export()] [2025-08-18T14:30:34+01:00]<ol><li>&lt;drupal&gt;/modules/contrib/devel/devel.module:398 [Drupal\devel\DevelDumperManager->debug()]<li>&lt;drupal&gt;/modules/custom/j2sutil/src/Form/FileList.php:212 .......  (also lots of other HTML and javascript)

Proposed resolution

It should be like '20250730 181843 doTable recrecrec => myrecvalue'

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇬🇧United Kingdom Jons

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Jons
  • 🇳🇱Netherlands J V

    While Kint can create plain text dumps, Devel doesn't pass any information about the format of the dump to the dumper plugin. I could make a hacky workaround to see if specific functions like ddm are in the stack trace but I'd rather not. Other dumpers like symfony/var-dumper also leave JS/CSS in the log file.

    You could make the log file an html file so it opens in a browser rather than a text editor if you want to see the output correctly.

    If devel had an option to choose a separate dumper for log files and normal dumps you could just configure it at will but that's a feature request for devel, not kint.

    I plan to start work on the next kint release in a week. If I have time afterwards I might add a hack for ddm but I will probably just close this issue

  • 🇬🇧United Kingdom Jons

    It is quite important, esp for non-UI modules.
    Something like this was seen before and the following patch fixed it

    ---- a/src/Plugin/Devel/Dumper/VarDumper.php
    -+++ b/src/Plugin/Devel/Dumper/VarDumper.php
    @@ -24,7 +24,7 @@
        */
       public function export(mixed $input, ?string $name = NULL): MarkupInterface|string {
         $cloner = new VarCloner();
    -    $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
    +    $dumper = new CliDumper();
     
         $output = fopen('php://memory', 'r+b');
         $dumper->dump($cloner->cloneVar($input), $output);
    @@ -34,7 +34,7 @@
           $output = $name . ' => ' . $output;
         }
     
    -    return $this->setSafeMarkup($output);
    +    return $output;
       }
     
       /**
    --- a/src/DevelDumperManager.php
    +++ b/src/DevelDumperManager.php
    @@ -135,7 +135,7 @@
        * {@inheritdoc}
        */
       public function debug($input, $name = NULL, $plugin_id = NULL) {
    -    $output = $this->createInstance($plugin_id)->export($input, $name) . "\n";
    +    $output = $this->createInstance($plugin_id)->export($input, $name);
         // The temp directory does vary across multiple simpletest instances.
         $file = $this->config->get('debug_logfile');
         if (empty($file)) {
    

    Not sure how to reapply to export()

  • 🇬🇧United Kingdom Jons

    As an initial hack - this seems to work for log and does not break UI.

    --- a/DevelDumperManager_1
    +++ b/DevelDumperManager
    @@ -135,7 +135,7 @@
        * {@inheritdoc}
        */
       public function debug($input, ?string $name = NULL, ?string $plugin_id = NULL) {
    +    $output = $name . ': ' . print_r($input, TRUE) . "\n";
    -    $output = $this->createInstance($plugin_id)->export($input, $name) . "\n";
     
         // The temp directory does vary across multiple simpletest instances.
         $file = $this->config->get('debug_logfile');
  • 🇳🇱Netherlands J V

    As an initial hack - this seems to work for log and does not break UI.

    Looking at DevelDumperManagerInterface your hack might actually be close to correct. While you can set the dump file to whatever extension you want it was clearly intended to be text based on the docblock:

    Logs a variable to a drupal_debug.txt in the site's temp directory.

    Anyway, regardless of whether it needs to be text or have a separate dumper configured that's not a change to kint, that's a change to devel. Your hack doesn't even touch a file in kint. Either decorate devel's dumper manager or ask them for the feature.

    Closing this since it's out of scope

Production build 0.71.5 2024