print_r()
accepts a second parameter which will return its output as a string. As such, your first example can be modified to the following:
error_log('this is information about the variable: ' . print_r($variable, true));
Note: While var_dump()
does not have such a parameter, you could use output buffering to store its output as described in the docs.