is not possible to capture the Restart,Shutdown,Log Out events in Macintosh?

Then How can I get the notification that user session is ending whenever the user Restart ,Shutdown or Log Out the machine?

waiting for the positive response.