Is there a way to write L.e(…) instead of Logger.getLogger(getClass()).error(…)?
// A foolish simple implementation
public class L {
public static void e(String msg) {
Logger.getLogger(L.class).error(msg);
}
}
The main problems to deal with are filtering and line numbers. If someone adds a filter to the log4j config file then it should apply the same as if I had called the Logger.getLogger(getClass()) method from the original class. That means the class object passed in needs to be pulled from the stack trace. I think that’s doable. I would just do “new Throwable()” then call fillStackTrace and then navigate it to get the information about the calling method.
Second, and perhaps intractable without modifying Log4j code directly, the line number output by the logger should be the line number of the method calling L.e(msg), not the line number inside that method.
Any suggestions on getting around these problems?
You could do something like this
Then you can call
L.e(this.getClass(), e);for errors.