The line numbers do appear in the debug logs, e.g.
08:02:34:164 USER_DEBUG [375]|DEBUG|LINE ITEM COUNTER B:1
That "[375]" in the log is the line number that this particular system.debug();
statement appears on.
If you're familiar enough with your codebase to take a guess at what classes might be involved, it's usually pretty simple to pin it down to the specific class based on the line number and the debug message. In some cases, line number alone is enough.
As for getting the class name into the debug statement, you'd have to add that yourself.
Apex doesn't really have that great of reflection/introspection capabilities. Personally, I've been adding a class variable to store the name of the class to minimize typing (and allow me to copy/paste debug statements). Something along the lines of
public Class MyClass{
// While this would be a fit for a static variable, doing so would mean
// that you'd need to type out "MyClass.className" every time you wanted to use it.
// We're mainly concerned about the name of the class that is currently
// executing, so having className being private is fine.
private String className;
public MyClass(){
// So, instead, I keep it as an instance variable, and populate
// it here in the constructor
this.className = MyClass.class.getName();
}
public void myMethod(){
// Using an instance variable means that we can just use "this.className"
// Applying this same pattern to other classes means you don't need to change
// anything if you copy/paste.
system.debug(this.className);
}
}
Of course, you could always just type out the name of the class in each debug statement, or forego a class variable and use MyClass.class.getName();
(every apex class, and classes provided by Salesforce, have a .class
variable that gets you a instance of Type
, which has the getName()
method).
I like being lazy though, er... uhh, I mean, re-using code and minimizing the work needed to do so.