<p>If you're throwing Exceptions from your plugin, then those will automatically get logged in Craft's log files at craft/storage/runtime/logs with full stack trace information, so there is no need for extra logging there.</p>

<p>In you're using <code>Craft::log</code> or <code>PluginHandlePlugin::log</code> statements, and you set <code>LogLevel::Error</code>, or <code>LogLevel::Warning</code>, then those messages will get logged regardless if <a href="http://buildwithcraft.com/docs/config-settings#devMode" rel="nofollow">devMode</a> is enabled or not.  <code>LogLevel::Info</code> and <code>LogLevel::Profile</code> will only get logged if devMode is enabled.</p>

<p>Logging the actual method name isn't really necessary because even with devMode disabled, you'll get a few steps in the stack leading up to the message so you can determine where it came from.  You will want to pass in any relevant variable names and values to the log message, though.</p>

CC BY-SA 3.0
2016-09-13T19:12:55.620Z
Just edited this answer... It was mistakenly referring to `PluginHandle::log`, when the correct format is `PluginHandlePlugin::log`.
Lindsey D
CC BY-SA 3.0
2014-06-25T19:41:42.370Z
Thanks this makes it clearer. One question: Is there a difference between `Craft::log` and `PluginHandle::log`?
Victor
CC BY-SA 3.0
2014-06-25T19:50:36.220Z
Craft::log calls end up in craft/storage/runtime/logs/craft.log, craft.log.1, etc. PluginHandle::log calls end up in their own pluginhandle.log, pluginhandle.log.1 etc.  Just makes them easier to search.
Brad Bell
CC BY-SA 3.0
2014-06-27T14:53:46.883Z
and its the whole class name, not just the handle, so `PluginHandlePlugin::log`, yes?
Tim Kelty
CC BY-SA 3.0
2014-11-06T11:42:05.650Z
@BradBell Is there a way to use other criterias than devMode, like my own config setting, to inform Craft to also log messages with LogLevel::Info? I need to do some temporary logging from my plugin in a prod environment, and enabling devMode seems like using a sledgehammer when I only need a needle. ;) I could of course change my plugin to log everything as LogLevel::Error, but that seems a bit bad too.
André Elvan
CC BY-SA 3.0
2014-11-06T17:42:33.420Z
@AndréElvan `PluginHandlePlugin::log('Message', LogLevel::Info, true);`. The 3rd parameter will force the message through regardless of the logging level or devMode status.
Brad Bell
CC BY-SA 3.0
2014-06-25T19:35:48.950Z
2016-09-13T19:11:45.753Z
2016-09-13T19:11:45.753Z
Brad Bell
<p>I'm currently adding messages to the log when an error occurs in my plugin.</p>

<p>Now I'm wondering what such a message should contain, to provide useful information to developers and end-users?</p>

<p>.</p>

<p>Currently my logged errors/warnings look like this:</p>

<blockquote>
  <p>"functionName": A simple explaination of the error:
  "$related_var"</p>
</blockquote>

<p>Actual example:</p>

<blockquote>
  <p>"_getUserGroupUsers": No Users found in UserGroups with ID: "1, 2"</p>
</blockquote>

<p>.</p>

<p>Is this something a developer/user checking the logs would find useful, or should more information be passed? If so, what else?</p>

<p>Also are you just logging errors/warnings or also valid operations (something like a StackTrace)?</p>

<plugin-development><best-practice>
What are the best-practices for useful logging messages?
# What are the best-practices for useful logging messages?

(Asked by: username_0 on 2014-06-25)

I'm currently adding messages to the log when an error occurs in my plugin.

Now I'm wondering what such a message should contain, to provide useful information to developers and end-users?

.

Currently my logged errors/warnings look like this:

> "functionName": A simple explaination of the error:
> "$related\_var"

Actual example:

> "\_getUserGroupUsers": No Users found in UserGroups with ID: "1, 2"

.

Is this something a developer/user checking the logs would find useful, or should more information be passed? If so, what else?

Also are you just logging errors/warnings or also valid operations (something like a StackTrace)?

**Tags:** plugin-development, best-practice

---

## 1 answers

### Answer by username_1 on 2014-06-25. Score: 6 | Accepted answer

If you're throwing Exceptions from your plugin, then those will automatically get logged in Craft's log files at craft/storage/runtime/logs with full stack trace information, so there is no need for extra logging there.

In you're using `Craft::log` or `PluginHandlePlugin::log` statements, and you set `LogLevel::Error`, or `LogLevel::Warning`, then those messages will get logged regardless if [devMode](http://buildwithcraft.com/docs/config-settings#devMode) is enabled or not. `LogLevel::Info` and `LogLevel::Profile` will only get logged if devMode is enabled.

Logging the actual method name isn't really necessary because even with devMode disabled, you'll get a few steps in the stack leading up to the message so you can determine where it came from. You will want to pass in any relevant variable names and values to the log message, though.

> **Comments:**
> **username_0**: Thanks this makes it clearer. One question: Is there a difference between `Craft::log` and `PluginHandle::log`?  
> **username_1**: Craft::log calls end up in craft/storage/runtime/logs/craft.log, craft.log.1, etc. PluginHandle::log calls end up in their own pluginhandle.log, pluginhandle.log.1 etc.  Just makes them easier to search.  
> **username_3**: and its the whole class name, not just the handle, so `PluginHandlePlugin::log`, yes?  
> **username_4**: @BradBell Is there a way to use other criterias than devMode, like my own config setting, to inform Craft to also log messages with LogLevel::Info? I need to do some temporary logging from my plugin in a prod environment, and enabling devMode seems like using a sledgehammer when I only need a needle. ;) I could of course change my plugin to log everything as LogLevel::Error, but that seems a bit bad too.  
> **username_1**: @AndréElvan `PluginHandlePlugin::log('Message', LogLevel::Info, true);`. The 3rd parameter will force the message through regardless of the logging level or devMode status.  
> **username_2**: Just edited this answer... It was mistakenly referring to `PluginHandle::log`, when the correct format is `PluginHandlePlugin::log`.  

---

