Well, the way I solve it is by always fetching the log (even if none is available) and after that check for success.
glGetShaderiv(m_HandleVertex, GL_INFO_LOG_LENGTH, &bufflen);
if (bufflen > 1)
{
GLchar* log_string = new char[bufflen + 1];
glGetShaderInfoLog(m_HandleVertex, bufflen, 0, log_string);
LOG_TRACE("Log found for '%s.vert':\n%s", m_Name.GetData(), log_string);
deletedelete[] log_string;
}
glGetShaderiv(m_HandleVertex, GL_COMPILE_STATUS, &success);
if (success != GL_TRUE)
{
LOG_ERROR("Failed to compile vertex shader.");
return false;
}
I did it this way because you might otherwise miss the warnings a shader returns. If a shader has warnings, but no errors, success will be true so you won't print the log, but warnings can also give you a clue as to why a shader fails to behave the way you want it.