Debugging sleep mode?

Every time when I close the lid gnome freeze out completely and only I receive back the cursor. Everything else is not responding nor keys nor clicks, only emergency shutdown with the power button solves the problem. How can I catch this bug?TIA