using hook_user() to capture user actions I am trying to create a method to log the actions of users, specifically when they log in and out.  I am using hook_user() method to do this. This is my code.

function mymodule_user($op, &amp;$edit, &amp;$account, $category = NULL) {
     switch ($op) {
        case 'login':
            //log to db
           break;
         case 'logout':
           //log to db
            break;
    }
}


There are two problems with this code, and I can't figure out how to fix them.

When a user password is expired, and they attempt to log in, they are redirected to their profile page to change their password. In this event, $op is never "login" and, as such can never be loaded. Instead, $op = "load" but it is useless to log this as this hook gets called nearly 50 times (storing that much data would be to much). Is there a better way to capture this event?

Second, when a user logs out ($op = 'logout') all the other information about the user is lost: The $account array only has empty values (and I need the user ID). Is there a way to capture the logout event and know the user ID?
hope you are trying for drupal 7, there are hook for login and logout, hook_user_login and hook_user_logout respectively. the user id available for logout hook so you can populate the data you want about user.