On Wed, Dec 2, 2015 at 12:12 PM, Chathura Widanage <[email protected] > wrote:
> We are developing a product(ESB) that will be used by an end user. In our > product we have provided an interface to alter the logging patterns > according the user preference in run time is self. We were able to do this > using log4j1. But I can't find a way to alter the pattern of appender in > run time using log4j2. > > In case of Console appender, we want to collect information about the > appenders, so user can view them in a GUI which is provided by our product. > > Please let me know if there is a possible way of doing these thing using > log4j2. > > I would be glad if you can mention the log4j2 methods or procedures that > can be used to performs the exact same function of the following log4j1 > methods. > > setlayout > > https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Appender.html#setLayout(org.apache.log4j.Layout) > > https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/AppenderSkeleton.html#setLayout(org.apache.log4j.Layout) > > setThreshold > > https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/AppenderSkeleton.html#setThreshold(org.apache.log4j.Priority) Setting the log level is a topic usually address by calling the Configurator class. Gary > > > getTarget > > https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/ConsoleAppender.html#getTarget() > > getEncoding > > https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/ConsoleAppender.html#getFollow() > > Thanks in advance > > > On Wed, Dec 2, 2015 at 7:32 PM, Ralph Goers <[email protected]> > wrote: > > > I’m not sure what you are trying to do with the pattern is necessary. The > > latest version of Log4j supports a PatternSelector that should provide > what > > you need. > > > > I am not sure why the updating of the ConsoleAppender is necessary. Why > > can’t that just be configured? > > > > Ralph > > > > > On Dec 2, 2015, at 12:29 AM, Chathura Widanage < > [email protected]> > > wrote: > > > > > > Hi all, > > > > > > I am in a process of migrating an application from log4j1 to log4j2. > > > I have successfully migrated 98% of the application but I am stuck at a > > > point where it is required to alter the configurations of an Appender > at > > > the run time. > > > > > > Below is the piece of code that we used in log4j1 > > > > > > public void updateAppender(AppenderView view) { > > > auditLog.info("Updating the appender with the name : {}, of the > > > instance", view.getName()); > > > AppenderSkeleton appender = (AppenderSkeleton) > > > LogManager.getRootLogger().getAppender(view.getName()); > > > > > > if (view.getPattern() != null) { > > > appender.setLayout(new PatternLayout(view.getPattern())); > > > } > > > > > > if (!"null".equals(view.getThreshold())) { > > > appender.setThreshold(Level.toLevel(view.getThreshold())); > > > } > > > } > > > > > > Since in log4j2, there is no method called setLayout and setThreshold > in > > > Appender class, Can I know a way to implement the above functionality > > using > > > the log4j2 APIs. > > > > > > Further I want to migrate the following piece of code, > > > > > > else if (appender instanceof ConsoleAppender) { > > > ConsoleAppender consoleAppender = (ConsoleAppender) > appender; > > > properties.put(CONSOLE_APPENDER_TARGET, > > > consoleAppender.getTarget()); > > > properties.put(CONSOLE_APPENDER_ENCODING, > > > consoleAppender.getEncoding()); > > > properties.put(CONSOLE_APPENDER_FOLLOW, > > > String.valueOf(consoleAppender.getFollow())); > > > } > > > > > > Here I don't find getTarget,getEncoding,getFollow methods in > > > ConsoleAppender class. > > > > > > Can some one please lead me to the way which I can implement the above > > > functionalities using log4j2 APIs. > > > > > > Thanks, > > > Chathura > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory
