concider use of "trigger_error()"
you can define the type of error to log an error.
trigger_error('usererror occured...', E_ERROR);
take care if you are using variables in the error-text that they could cause a security risk due to that they are not escaped or can contain html (including <script>) code if the error gets echo'ed to the browser.