Use a server-side scripting language. Create this PHP script:
<?php
$handle=fopen("301tracking.log","a+");
fwrite($handle,"1 guest from IP".$_SERVER['REMOTE_ADDR']."arrived at ".time()."\n");
fclose($handle);
$newhost="http://domainB.com";
$url=$newhost.$_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently",true);
header("Location: ".$url,true);
?>
<html>
<head>
<title>Redirect</title>
</head>
<body>
<p>Document moved <a href="<?php echo $url; ?>">here</a></p>
</body>
</html>
Save this as index.php and upload it to document root of domainA. Also, use mod_rewrite to redirect all requests on domainA to the script like so:
RewriteEngine On
RewriteRule ^(.*)$ /index.php [L]
You may have to add a check for the redirect status environment variable right after "RewriteEngine On" just incase the above lines go in an endless loop and/or you get error 500 (internal server error). An alternative is to upload the script to all folders on domainA. To customize the log, change the fwrite line. I apologize for poor grammar in the text part of the code, but you'll understand how the code works when you try it.