How about creating your custom logger stream? That way the user can specify the component that failed, like so:
namespace A {
void foo()
{
log("A") << "Something went very wrong" << endl;
}
}
namespace B {
void bar()
{
log("B") << "C should equal 3" << endl;
}
}
int main()
{
B::bar();
A::foo();
}
Perhaps less automagical, but __FILE__
macro could also give some information.