logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chathura Widanage <chath...@adroitlogic.com>
Subject Migrating from log4j to log4j2
Date Wed, 02 Dec 2015 07:29:35 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message