We consider a modified version of the classical optimal dividends problem of de Finetti in which the objective function is altered by adding in an extra term which takes account of the ruin time of the risk process, the latter being modeled by a spectrally negative Lévy process. We show that, with the exception of a small class, a barrier strategy forms an optimal strategy under the condition that the Lévy measure has a completely monotone density. As a prerequisite for the proof, we show that, under the aforementioned condition on the Lévy measure, the q-scale function of the spectrally negative Lévy process has a derivative which is strictly log-convex.