<p>Something like this should work for you:</p>

<pre><code>Plugin::log(\CVarDumper::dumpAsString(array('test')), LogLevel::Error);
</code></pre>

<p>Note the <code>\</code> in front of <code>CVarDumper</code> to tell PHP that class is not in the Craft namespace, but in the global one.</p>

CC BY-SA 3.0
2015-02-27T23:08:57.167Z
Looks good, but the following error ```Fatal error: Call to undefined method CVarDumper::export()```
crawf
CC BY-SA 3.0
2015-02-27T23:10:31.947Z
My bad... I guess I should actually read the error message.  It's `dump`, not `export`. Updated the answer.
Brad Bell
CC BY-SA 3.0
2015-02-27T23:15:23.890Z
Haha, yeah thats better :) Still outputs a blank row in the log ```2015/02/27 23:12:37 [error] [plugin] ```
crawf
CC BY-SA 3.0
2015-02-27T23:28:42.150Z
I think the example might be missing a parenthesis at the end of the first argument: `\CVarDumper::dump(array('test'))`
Ben Parizek
CC BY-SA 3.0
2015-02-27T23:32:07.057Z
Thanks Ben, in practice its correct. In fact, it outputs the array to the screen, just not in the log file. This might be a devMode things though...
crawf
CC BY-SA 3.0
2015-02-28T04:28:41.897Z
Didn't realize dump echo'd out the results.  dumpAsString will work writing it to the log, though... just tested it.
Brad Bell
CC BY-SA 3.0
2015-02-28T12:58:36.020Z
Thanks Brad, that works a treat as well! Too bad I can't mark both answers as accepted :)
crawf
CC BY-SA 3.0
2015-02-27T23:06:40.147Z
2015-02-28T04:28:49.863Z
2015-02-28T04:28:49.863Z
Brad Bell
<p>Passing <code>true</code> as the second parameter to <a href="http://php.net/manual/en/function.print-r.php" rel="noreferrer">print_r</a> returns a string that can be written to the log.</p>

<pre><code>Plugin::log(print_r(array('test'), true));
</code></pre>

CC BY-SA 3.0
2015-02-28T00:35:58.767Z
2015-02-28T00:35:58.767Z
Mike Pepper
<p>Just wondering if its possible to output an array to the Plugin::log call? Would be really handy to see if an error occurs, what a data object's values are!</p>

<p>Tried the following:</p>

<pre><code>Plugin::log(array('test')), LogLevel::Error);
Plugin::log(json_decode(array('test')), LogLevel::Error);
Plugin::log(var_dump(array('test')), LogLevel::Error);
Plugin::log(print_r(array('test')), LogLevel::Error);
Plugin::log(\CVarDumper::dump(array('test')), LogLevel::Error);
</code></pre>

<plugin-development><logs>
Output array to Plugin::log
# Output array to Plugin::log

(Asked by: username_0 on 2015-02-27)

Just wondering if its possible to output an array to the Plugin::log call? Would be really handy to see if an error occurs, what a data object's values are!
Tried the following:
Plugin::log(array('test')), LogLevel::Error);
Plugin::log(json_decode(array('test')), LogLevel::Error);
Plugin::log(var_dump(array('test')), LogLevel::Error);
Plugin::log(print_r(array('test')), LogLevel::Error);
Plugin::log(\CVarDumper::dump(array('test')), LogLevel::Error);

**Tags:** plugin-development, logs

---

## 2 answers

### Answer by username_3 on 2015-02-28. Score: 6 | Accepted answer

Passing true as the second parameter to print_r returns a string that can be written to the log.
Plugin::log(print_r(array('test'), true));


---

### Answer by username_1 on 2015-02-27. Score: 3

Something like this should work for you:
Plugin::log(\CVarDumper::dumpAsString(array('test')), LogLevel::Error);

Note the \ in front of CVarDumper to tell PHP that class is not in the Craft namespace, but in the global one.

> **Comments:**
> **username_0**: Looks good, but the following error ```Fatal error: Call to undefined method CVarDumper::export()```  
> **username_1**: My bad... I guess I should actually read the error message.  It's `dump`, not `export`. Updated the answer.  
> **username_0**: Haha, yeah thats better :) Still outputs a blank row in the log ```2015/02/27 23:12:37 [error] [plugin] ```  
> **username_2**: I think the example might be missing a parenthesis at the end of the first argument: `\CVarDumper::dump(array('test'))`  
> **username_0**: Thanks Ben, in practice its correct. In fact, it outputs the array to the screen, just not in the log file. This might be a devMode things though...  
> **username_1**: Didn't realize dump echo'd out the results.  dumpAsString will work writing it to the log, though... just tested it.  
> **username_0**: Thanks Brad, that works a treat as well! Too bad I can't mark both answers as accepted :)  

---

