Logout Code

I have a custom index I created and I was good able to detect if a user is signed in, but I want to include a logout button on the page, and when I use this:

 

<?php echo elgg_view('output/url', array('href' => "{$vars['url']}action/logout", 'text' => elgg_echo('logout'), 'class' => "logoutlink",'is_action' => TRUE)); ?>

It does not work at all for me. That code works everywhere except the on the index. I also tried
<?php echo elgg_view('output/url', array('href' => "<?php  echo $CONFIG->wwwroot;?>action/logout", 'text' => elgg_echo('logout'), 'class' => "logoutlink",'is_action' => TRUE)); ?>
but it also does not work, I've also tried changing action/logout to actions/logout but no luck. 
Anyone know a simple code for create a text link logout? I'd prefer staying away from elgg_views if possible. Thanks everyone!!!