logging - Standard way to implement a Logger across classes in Java? -
i'm building javafx application many classes. i'd utilize java logging classes. options seem come excessive or repetitive code. these ones can think of:
declare logger private static final field in each class i.e.
private static final logger logger = logger.getlogger(myclass.class.getname());
this alternative seems kind of annoying having in each class.
pass logger main class each constructoragain not seem elegant
create class logger, , phone call static methods on class each log item. seems creating additional class logger excessive.so how guys deal situation ? matter of choosing to the lowest degree bad alternative ?
i disagree "excessiveness" of 3rd option: "wrapper" alternative quite elegant because has dedicated class logger (srp) , allows switch implementations (log4j, apache-commons-logging, java.util.logging etc) "under hood" without coupling rest of code implementation.
as luiggi mentioned in comments below slf4j such implementation.
java logging
No comments:
Post a Comment