Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:08:57.167Z
Answers.Text: Looks good, but the following error ```Fatal error: Call to undefined method CVarDumper::export()```
Answers.UserDisplayName: crawf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:10:31.947Z
Answers.Text: My bad... I guess I should actually read the error message.  It's `dump`, not `export`. Updated the answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:15:23.890Z
Answers.Text: Haha, yeah thats better :) Still outputs a blank row in the log ```2015/02/27 23:12:37 [error] [plugin] ```
Answers.UserDisplayName: crawf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:28:42.150Z
Answers.Text: I think the example might be missing a parenthesis at the end of the first argument: `\CVarDumper::dump(array('test'))`
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:32:07.057Z
Answers.Text: 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...
Answers.UserDisplayName: crawf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-28T04:28:41.897Z
Answers.Text: Didn't realize dump echo'd out the results.  dumpAsString will work writing it to the log, though... just tested it.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-28T12:58:36.020Z
Answers.Text: Thanks Brad, that works a treat as well! Too bad I can't mark both answers as accepted :)
Answers.UserDisplayName: crawf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T23:06:40.147Z
Answers.LastActivityDate: 2015-02-28T04:28:49.863Z
Answers.LastEditDate: 2015-02-28T04:28:49.863Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-28T00:35:58.767Z
Answers.LastActivityDate: 2015-02-28T00:35:58.767Z
Answers.UserDisplayName: Mike Pepper
Body: <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>
  
Tags: <plugin-development><logs>
Title: Output array to Plugin::log
ThreadText: # 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](http://php.net/manual/en/function.print-r.php) 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 username_1, that works a treat as well! Too bad I can't mark both answers as accepted :)  
  
  ---
  
  