Logged in only custom page

You can redirect non logged in users to login page using following code if they access custom.php page link. Create custom_login.php as custom template and assign it a page, in the code below i have assigned it to a page “login page” having slug “login-page”

function redirect_to_login(){
    if( ! is_user_logged_in() && is_page_template('custom.php') ){
        wp_redirect( home_url() . '/login-page' );
        exit();
    }
}
add_action('template_redirect','redirect_to_login');