[
https://issues.apache.org/jira/browse/LOG4J2-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13541065#comment-13541065
]
Pavel Trka commented on LOG4J2-138:
-----------------------------------
Ralph: I think I described the reason why it would be useful (to me) to have
such method in the interface - I need precisely the code you described -
logger.log(Level.WARN,...), if I have to use logger.info(), logger.warn() etc
my implementations get cluttered with methods and copy/paste, loggerl.log()
method is ideal single "entry point" trough which I can implement all
trace/debug/... functionality.
If I undestand well, using AbstractLogger or AbstractLoggerWrapper are intended
for someone who is implementing own logger and who are extending Log4j2 classes
but IM NOT extending, Im only using Log4j - I simply want to get the Logger
iface trough LogManager.getLogger() and then use the iface.
I know that I can cast returned iface to AbstractLogger or create new
AbstractLoggerWrapper around returned iface I simply wanted to know if there is
a chance to push log() method to the interface as it would be simpliest
straitforward solution hardened against possible inner implementation details
changes in the future as the iface is hiding AbstractLogger details. Im not an
Log4j API expert but my personal opinion is that exposing Level is not big
implementation detail, correct me if Im wrong but as I was using old Log4j for
looong time, I guess Level is the thing which gets hardly changed in the
future. But I dont want to be a smartass, as I said Im not the expert.
To demonstrate what Im doing and why I see it as useful Im attaching my log
package code (is pretty simple so I think it should be clear) -
Logger.java - my log interface defining our logging methods
AbstractLogger.java - common ancestor implementing most of the Logger interface
methods. The goal is to have as many as possible implementation code here, not
in the subclasses.
Log4jLogger.java - old Log4j logger implementation
Log4j2Logger.java - new Log4j2 implementation, there is a "NOT POSSIBLE NOW"
comment on the critical line
JDKLogger.java - JDK logger implementation
As you can see, as most of the code is in AbstractLogger, implementation
classes (Log4j, JDK...) are pretty simple and thats a good thing. But now with
Log4J2 it is a problem - if I will be exactly clean and use Log4j2 Logger
interface, I have to override all debug/trace/... methods in Log4j2Logger.java
implementation and that the thing I dont want to do.
Of course for now i will use AbstratLoggerWrapper or casting in my
implementation but the iface modification would be best for me ;)
Sorry for such long post,
thanks
> org.apache.logging.log4j.Logger lacks some log(Level, String, ...) method
> -------------------------------------------------------------------------
>
> Key: LOG4J2-138
> URL: https://issues.apache.org/jira/browse/LOG4J2-138
> Project: Log4j 2
> Issue Type: Wish
> Components: API
> Affects Versions: 2.0-beta3
> Reporter: Pavel Trka
> Labels: API, log4j, logging, method
>
> Hello,
> I dont know if Im not alone with this problem but I encountered blocker in
> Log4j2 usage (blocker for me personally of course ;) ). Im posting it as Wish
> issue as it is not a bug.
> Im trying to switch from Log4j 1.2 to 2 and it looked like piece of cake but
> - I have developped some logging facade or wrapper solution around log4j 1.2,
> it's something like simple SLF4J, it was necessary because my project logging
> needs are pretty special and also I wanted to have the option to easilly
> switch logging frameworks.
> Problem is that most of my logging code is in own abstract class that is
> common for all implementations, concrete implementations are extending this
> base and have to implement only few methods like log(Level, String) and
> isLevelLoggable(Level) etc.. The advantage is that implementations are very
> simple to write with minimal amount of copy/paste programming.
> Problem is that the new org.apache.logging.log4j.Logger iface does not
> contain any log(...) method and Im stuck.
> I have only 2 options - I can use org.apache.logging.log4j.core.Logger class
> without using iface but I dont want that for obvious reasons - I want to do
> it properly. Second option is to implement all info(), debug(),trace(),....
> methods in my implementation class but I dont wanna do that because that is
> exactly what I wanted to avoid in my facade solution.
> I know it's my wish only, I dont know if this change had some good reasons
> but Im voting for adding some log() method to Logger iface ;) The same thing
> applies for missing getLevel() method but I already solved this one easilly
> so it's not my priority.
> Thanks,
> Pavel
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]