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)?

1 Answer 1


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 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.

  • Thanks this makes it clearer. One question: Is there a difference between Craft::log and PluginHandle::log?
    – Victor
    Commented Jun 25, 2014 at 19:41
  • 2
    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
    Commented Jun 25, 2014 at 19:50
  • 1
    and its the whole class name, not just the handle, so PluginHandlePlugin::log, yes?
    – Tim Kelty
    Commented Jun 27, 2014 at 14:53
  • @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. Commented Nov 6, 2014 at 11:42
  • 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.
    – Brad Bell
    Commented Nov 6, 2014 at 17:42

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.