You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Bobby Bissett <ro...@enterprisedb.com> on 2018/10/01 17:23:23 UTC

how to know when logging setup failed (and hide stack trace)

Hi,

I have to set up our logging programmatically, which I'm doing through a
ConfigurationBuilder<BuiltConfiguration>. In some cases, like syslog
appender using TCP and syslog isn't set up to allow connections yet, when I
make the init call Configurator.initialize(builder.build()), I get a stack
trace printed to std err and I don't get anything back from the call to let
me know there was a problem so that I can fail to start at that point.

A) Is there any way to know there was a failure so I can abort startup?
I've tried looking at fields in the returned LoggerContext but can't find
something to tell me there was a problem.

B) Can I tell log4j2 not to output the stack trace? It's coming from here
in TcpSocketManager, line 451:
                LOGGER.error("TcpSocketManager ({}) caught exception and
will continue:", name, ex, ex);
...where LOGGER is StatusLogger.getLogger().

Would I have to set something on the status logger at startup? Am using
this 'dummy' file now at startup that gets overwritten by the programmatic
initialization. It's just here to prevent error messages going to std err
in cases my app needs to exit before startup is fully complete:

<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="error">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

Thanks,
Bobby