Logistic regression is used for classification tasks, that predict discrete values as a result.
If you consider a binary classification problem, then the hypothesis function is bounded between [0, 1]
Logistic regression formula:
The cost function represents the optimization objective.
The cost function could be the mean of the Euclidean distance between the hypothesis h_θ(x) and the actual value y among all them samples in the training set, when the hypothesis function is formed using the sigmoid function, this term would result in a non-convex cost function, which means that a local minimum can be easily located before reaching the global minimum. The cost function is convex, it is transformed using the logarithm of the sigmoid function.
In this way, the optimization objective function can be defined as the mean of the costs/errors in the training set:
Hope this answer helps.