Habari\EventLog::log PHP Method

log() public static method

Write an entry to the event log.
public static log ( string $message, string $severity = 'info', string $type = 'default', string $module = null, mixed $data = null ) : object
$message string The message
$severity string The severity
$type string The type
$module string The module
$data mixed The data
return object LogEntry The inserted LogEntry object
    public static function log($message, $severity = 'info', $type = 'default', $module = null, $data = null)
    {
        $module = self::get_module($module);
        $log = new LogEntry(array('message' => $message, 'severity' => $severity, 'module' => $module, 'type' => $type, 'data' => $data, 'ip' => Utils::get_ip()));
        $user = User::identify();
        if ($user->loggedin) {
            $log->user_id = $user->id;
        }
        $log->insert();
        return $log;
    }

Usage Example

 public function action_post_insert_after(Post $post)
 {
     if (Options::get(self::OPTION_ANNOUNCE_POSTS) == 'yes' && $post->statusname == 'published') {
         $params = array('article-author' => $post->author->username, 'article-author-email' => $post->author->email, 'article-title' => $post->title, 'article-content' => $post->content, 'permalink' => $post->permalink);
         try {
             $result = $this->defensio->announce_article($params);
         } catch (Exception $e) {
             EventLog::log($e->getMessage(), 'notice', 'content', 'Defensio');
         }
     }
 }