In Drupal 7 I use devel's drupal_debug() or its alias dd() to log a variable to a drupal_debug.txt in the site's temp directory.

In the Drupal 8 version of devel this function has disappeared. It seems to be replaced by DevelDumperManagerInterface But it is not clear to me how it used.

How can I log variables to a txt file in Drupal 8?

  • How about printing them in a message? drupal_set_message(var_dump($variable), 'warning');
    – No Sssweat
    Commented Oct 4, 2016 at 4:21
  • In the D8 devel module drupal_debug() as been replaced by the devel.dumper service, but the alias dd() is still there and now points to the service.
    – 4uk4
    Commented Oct 4, 2016 at 6:47
  • Also printing it to the logs is possible with \Drupal::logger('crimi')->notice($value); but dd() can be nice in some cases. Actually I managed to get it working when I figured out I was disabling the devel module constantly
    – batigolix
    Commented Oct 4, 2016 at 12:27

1 Answer 1


The DevelDumperManagerInterface interface is implemented by DevelDumperManager. This class is in turn used as a service, 'devel.dumper'.

One way to use this function would be the following:

$ddumper = \Drupal::service('devel.dumper');
$ddumper->debug($variable_name, NULL, 'default');

That would log the variable $variable_name to drupal_debug.txt located in the temp folder directory. See DevelDumperManager::debug() docs for more information.

Good luck!

  • What exactly does this code do? does it dump the variables somewhere on the page when the code runs?
    – No Sssweat
    Commented Oct 4, 2016 at 4:25
  • 1
    @NoSssweat : It logs a variable to a drupal_debug.txt in the temp folder directory. See api.drupal.org/api/devel/src%21DevelDumperManager.php/function/… Commented Oct 4, 2016 at 7:03
  • I think I am missing something here. I get the error exception 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' with message 'You have requested a non-existent service. I run this code from within a migrate plugin, so the devel functions may not be availabe at that point ...
    – batigolix
    Commented Oct 4, 2016 at 10:12
  • In that case, please update your OP to add this important information. I am gonna take a look at this and update my answer accordingly. Commented Oct 4, 2016 at 10:59
  • First question: Is the devel module installed and functioning in your Drupal instance? For example, what do you get for this command: drupal container:debug | grep debug.dumper ? Or for this one (using drush): drush ev "\Drupal::service('devel.dumper');" Commented Oct 4, 2016 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.