logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Migrating from log4j to log4j2
Date Wed, 02 Dec 2015 14:02:45 GMT
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 <chathura@adroitlogic.com> 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message