What are the best-practices for useful logging messages? 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)?
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.