At the temporary level, the judge is pretty much looking at need/ability to pay. This might be done by looking at the so-called "guideline spousal support" (although there is no actual such guideline formally adopted by law). At the permanent level, the judge is required to consider ONLY the elements of Family Code section 4320 and the standard of living established during the marriage.
The elements of F.C. section 4320 include the length of the marriage, the income of the parties, need and ability to pay, tax consequences, health, history of domestic violence and others, all as relates to what we call the "marital standard of living".
How long? A marriage of 10 years or more is statutorily considered "long term". Less than 10 years is "short". Generally, a marriage of less than 10 years will find spousal support ending in half the length of the marriage (but not always). A long term marriage will generally result in the court declining to set a termination date in advance.