I’ve noticed that when David talks to the Lord He describes the way he feels and what he is going through. In some Psalms David sounds depressed or in anguish, like he’s hit rock bottom (you can see this at the end of some of his Psalms).But even after all Davids depressing thoughts, Gods light shines through the darkness David is in. Davids focus then becomes the Truth of God himself; he brings praise and glory to God.
Sometimes I wonder, “How was he able to give praise to God when he felt discouraged and depressed?”
I think it was because David was able to stop focusing on himself and focus on God instead.
Psalm 102:1-17 (the writer of this Psalm is not David but someone who felt pain and still praised God.