The judge considers what is in the "best interests" of the children. Best interests involves many different aspects of parenting, but basically the Judge is looking to see which parent is better suited to provide daily care for the child. Daily care involves the basic necessities like food and shelter, but also care for the child´s emotional and mental needs.
Issues of a parent´s "fitness" could arise in contested custody disputes. If fitness becomes an issue your behaviors and lifestyle will be used as evidence at trial.