How do I get the user ID for the currently logged-in user?
$user = \Drupal::currentUser();


See the Drupal class. There are a lot of helper methods; most of them are shortcuts for services, so you don't have to call \Drupal::service() directly.

Note that the current user is not the user entity, it is just user proxy. You can get some basic information from it but fields or other entity-specific logic is not present. To access the user entity you have to load it manually:

$user = User::load(\Drupal::currentUser()-&gt;id());


Unfortunately there is no direct method like \Drupal::currentUser()-&gt;getEntity() :(