Germany has a number of American cultural centers, which are generally called an Amerika-Haus. The one here in Freiburg is named after Carl Schurz, who is not actually from this part of Germany, but was involved in the Revolution of 1848, which was very strong in Baden. (For those of you who think that Germany does not have historical roots connecting it to democracy, there was not only this revolution, but the Revolution of 1918-1919.)
Anyway, the saying above was apparently in circulation during Schurz's lifetime (having apparently been coined generations before by a Mister Decatur), and he had something to say about it:
I confidently trust that the American people will prove themselves … too wise not to detect the false pride or the dangerous ambitions or the selfish schemes which so often hide themselves under that deceptive cry of mock patriotism: "Our country, right or wrong!" They will not fail to recognize that our dignity, our free institutions and the peace and welfare of this and coming generations of Americans will be secure only as we cling to the watchword of true patriotism: "Our country—when right to be kept right; when wrong to be put right."
That was in 1899. And while he was right about US chauvinism -- which somehow goes under the epithet of patriotism in the US, though any equivalent spirit abroad is degraded as nationalism -- his confident trust was misplaced. 100 years later, the saying is still being debunked, i.e. that thinking is still alive and well.