You missed a part in the code, however helped me to solve this issue by myself :). Here is my code, adjust it appropriately:
<?php
if (is_user_logged_in() ) {
wp_get_current_user();
$current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) )
return;
echo 'You are currently logged in as <span id="user-loged-name">' . $current_user->user_login . '</span><br />';
wp_loginout( home_url()); // Display "Log Out" link.
}
?>