The second console appender (SYSTEM_ERR) was just to check if I can still
log anything to the console.
If I only use one, then after I redeploy I don't get any output.
I add everything programatically, so here's the code I use.
The code runs in a Singleton bean annotated with @Startup.
*****************************************
public static final Logger logger = LogManager.getLogger(Log4jSetup.class);
org.apache.logging.log4j.core.LoggerContext loggerContext =
(org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
org.apache.logging.log4j.core.Logger rootLogger =
(org.apache.logging.log4j.core.Logger)
LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).setLevel(org.apache.logging.log4j.Level.TRACE);
ConsoleAppender consoleAppender =
ConsoleAppender.createAppender(PatternLayout.createLayout("%d [%t] %-5p %c
- %m%n", configuration, null, null, "true"), null, "SYSTEM_OUT", "true",
"ConsoleAppender", "true");
if (!consoleAppender.isStarted()) {
consoleAppender.start();
}
configuration.addLoggerAppender(rootLogger, consoleAppender);
ConsoleAppender consoleErrAppender =
ConsoleAppender.createAppender(PatternLayout.createLayout("%d [%t] %-5p %c
- %m%n", configuration, null, null, "true"), null, "SYSTEM_ERR", "true",
"ConsoleAppender", "true");
if (!consoleErrAppender.isStarted()) {
consoleErrAppender.start();
}
configuration.addLoggerAppender(rootLogger, consoleErrAppender);
loggerContext.updateLoggers();
logger.info("Test");
***********************************************
JD
On Thu, Oct 10, 2013 at 2:49 PM, Gary Gregory <[email protected]>wrote:
> On Thu, Oct 10, 2013 at 6:07 AM, JD Buys <[email protected]> wrote:
> > Hi,
> >
> > I am running log4j2 beta 9 on Glassfish 3.1.1.
> > My configuration is very simple, I have two console appenders one where
> the
> > target is "SYSTEM_OUT" and the other where the target is "SYSTEM_ERR".
>
> Why?
>
> What happens if you use just one Console appender?
>
> You probably should show your config file too.
>
> Gary
>
> >
> > The problem is this: When Glassfish starts up it logs my info messages
> > correctly to the console/server.log, but when I redeploy my application,
> > only the "SYSTEM_ERR" messages display.
> >
> > Any ideas of how to debug it or what could be wrong?
> >
> > Thanks,
> > JD
>
>
>
> --
> E-Mail: [email protected] | [email protected]
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>