Search in sources :

Example 1 with Log4j2Factory

use of com.hazelcast.logging.Log4j2Factory in project hazelcast by hazelcast.

the class ClientLoggerConfigurationTest method testLoggingWithConfiguration.

// Test with programmatic or system property configuration according to boolean parameter.
// the idea of the test is to configure a specific logging type for a client and then
// test its LoggingService produce instances of the expected Logger impl
protected void testLoggingWithConfiguration(boolean programmaticConfiguration) throws IOException {
    hazelcastFactory = new TestHazelcastFactory();
    Config cg = new Config();
    cg.setProperty("hazelcast.logging.type", "jdk");
    hazelcastFactory.newHazelcastInstance(cg);
    ClientConfig config = new ClientConfig();
    if (programmaticConfiguration) {
        config.setProperty("hazelcast.logging.type", "log4j2");
    } else {
        System.setProperty("hazelcast.logging.type", "log4j2");
    }
    client = hazelcastFactory.newHazelcastClient(config);
    ILogger clientLogger = client.getLoggingService().getLogger("loggerName");
    // this part is fragile.
    // client wraps the actual logger in its own class
    ILogger actualLogger = (ILogger) getFromField(clientLogger, "logger");
    Class<?> clientLoggerClass = actualLogger.getClass();
    ILogger expectedLogger = new Log4j2Factory().getLogger("expectedLogger");
    Class<?> expectedLoggerClass = expectedLogger.getClass();
    assertSame(expectedLoggerClass, clientLoggerClass);
}
Also used : Log4j2Factory(com.hazelcast.logging.Log4j2Factory) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ILogger(com.hazelcast.logging.ILogger) ClientConfig(com.hazelcast.client.config.ClientConfig)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)1 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1 Config (com.hazelcast.config.Config)1 ILogger (com.hazelcast.logging.ILogger)1 Log4j2Factory (com.hazelcast.logging.Log4j2Factory)1