Thank you for your replies, I will mark this as solved.
One thing to note for anyone who might be thinking about implemented custom loss functions in the future: be careful about the numeric stability of your implementation.