Jump to content

Developer Documentation

Logging

Logging issues unexpected issues that occur in your third part application or plugin is the #1 way you can help diagnose  problems that have occurred after the fact. Often times, proper logging can completely eliminate the need to spend valuable time reproducing an obscure issue and allow you to cut to the chase and look into the problem that actually occurred in the first place.

The primary means of logging issues in the Community Suite is through the \IPS\Log class.

Generalized logging

When you  need to log an unexpected situation, you should use the \IPS\Log::log() method. The first parameter should either be an Exception  instance, or a string to log. The second parameter should be a randomly-chosen "category"  for the log.

try
{
    throw new \UnexpectedValueException( 'My message', 200 );
}
catch( \Exception  $e )
{
    \IPS\Log::log( $e, 'my_app_issue'  );
    \\ No handle the issue gracefully, i.e. by showing an error  message
}

Here, the details about the exception will be logged in a category 'my_app_issue', which you can name whatever you want. By using unique error codes, you can more easily identify where the system log entry came from when a user reports the issue to the administrator.

Debug logging

In addition to generalized logging, you can log debug messages as well, useful when working to diagnose issues in your application and primarily meant for development purposes. The function definition is the same as the log() method, except you call debug() instead.

try
{
    throw new \UnexpectedValueException( 'My message', 200 );
}
catch( \Exception  $e )
{
    \IPS\Log::debug( $e, 'my_app_issue'  );
    \\ No handle the issue gracefully, i.e. by showing an error  message
}

In order to enable debug logging, you will need to set a constant in your constants.php file to enable it.

define( 'DEBUG_LOG', true );

You can then view the system logs in the AdminCP by using the  live search to look for "System logs".


  Report Document


×
×
  • Create New...