Complaining tends to be a coded message you are sending out for someone to care about what you are going through. I find it rarely has much to do with a desire for someone to tell you how to fix it.
You have to develop self-discipline, and think about what you are about to say before you say it. If it is whiny, complainy, or self-pity-ish, then refuse to say it aloud. You can actually change your own mood by forcing yourself to say only positive things.