Search in sources :

Example 1 with LoggerNodeIdAndApplicationAware

use of org.apache.ignite.logger.LoggerNodeIdAndApplicationAware in project ignite by apache.

the class Log4j2LoggerSelfTest method testUrlConstructor.

/**
 * @throws Exception If failed.
 */
@Test
public void testUrlConstructor() throws Exception {
    File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
    assert xml != null;
    assert xml.exists();
    URL url = xml.toURI().toURL();
    IgniteLogger log = new Log4J2Logger(url).getLogger(getClass());
    System.out.println(log.toString());
    assertTrue(log.toString().contains("Log4J2Logger"));
    assertTrue(log.toString().contains(url.getPath()));
    ((LoggerNodeIdAndApplicationAware) log).setApplicationAndNode(null, UUID.randomUUID());
    checkLog(log);
}
Also used : LoggerNodeIdAndApplicationAware(org.apache.ignite.logger.LoggerNodeIdAndApplicationAware) IgniteLogger(org.apache.ignite.IgniteLogger) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 2 with LoggerNodeIdAndApplicationAware

use of org.apache.ignite.logger.LoggerNodeIdAndApplicationAware in project ignite by apache.

the class Log4j2LoggerSelfTest method testPathConstructor.

/**
 * @throws Exception If failed.
 */
@Test
public void testPathConstructor() throws Exception {
    IgniteLogger log = new Log4J2Logger(LOG_PATH_TEST).getLogger(getClass());
    System.out.println(log.toString());
    assertTrue(log.toString().contains("Log4J2Logger"));
    assertTrue(log.toString().contains(LOG_PATH_TEST));
    ((LoggerNodeIdAndApplicationAware) log).setApplicationAndNode(null, UUID.randomUUID());
    checkLog(log);
}
Also used : LoggerNodeIdAndApplicationAware(org.apache.ignite.logger.LoggerNodeIdAndApplicationAware) IgniteLogger(org.apache.ignite.IgniteLogger) Test(org.junit.Test)

Example 3 with LoggerNodeIdAndApplicationAware

use of org.apache.ignite.logger.LoggerNodeIdAndApplicationAware in project ignite by apache.

the class IgniteUtils method initLogger.

/**
 * @param cfgLog Configured logger.
 * @param app Application name.
 * @param workDir Work directory.
 * @return Initialized logger.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("ErrorNotRethrown")
public static IgniteLogger initLogger(@Nullable IgniteLogger cfgLog, @Nullable String app, UUID nodeId, String workDir) throws IgniteCheckedException {
    try {
        Exception log4jInitErr = null;
        if (cfgLog == null) {
            Class<?> log4jCls;
            try {
                log4jCls = Class.forName("org.apache.ignite.logger.log4j.Log4JLogger");
            } catch (ClassNotFoundException | NoClassDefFoundError ignored) {
                log4jCls = null;
            }
            if (log4jCls != null) {
                try {
                    URL url = U.resolveIgniteUrl("config/ignite-log4j.xml");
                    if (url == null) {
                        File cfgFile = new File("config/ignite-log4j.xml");
                        if (!cfgFile.exists())
                            cfgFile = new File("../config/ignite-log4j.xml");
                        if (cfgFile.exists()) {
                            try {
                                url = cfgFile.toURI().toURL();
                            } catch (MalformedURLException ignore) {
                            // No-op.
                            }
                        }
                    }
                    if (url != null) {
                        boolean configured = (Boolean) log4jCls.getMethod("isConfigured").invoke(null);
                        if (configured)
                            url = null;
                    }
                    if (url != null) {
                        Constructor<?> ctor = log4jCls.getConstructor(URL.class);
                        cfgLog = (IgniteLogger) ctor.newInstance(url);
                    } else
                        cfgLog = (IgniteLogger) log4jCls.newInstance();
                } catch (Exception e) {
                    log4jInitErr = e;
                }
            }
            if (log4jCls == null || log4jInitErr != null)
                cfgLog = new JavaLogger();
        }
        // Special handling for Java logger which requires work directory.
        if (cfgLog instanceof JavaLogger)
            ((JavaLogger) cfgLog).setWorkDirectory(workDir);
        // Set node IDs for all file appenders.
        if (cfgLog instanceof LoggerNodeIdAndApplicationAware)
            ((LoggerNodeIdAndApplicationAware) cfgLog).setApplicationAndNode(app, nodeId);
        else if (cfgLog instanceof LoggerNodeIdAware)
            ((LoggerNodeIdAware) cfgLog).setNodeId(nodeId);
        if (log4jInitErr != null)
            U.warn(cfgLog, "Failed to initialize Log4JLogger (falling back to standard java logging): " + log4jInitErr.getCause());
        return cfgLog;
    } catch (Exception e) {
        throw new IgniteCheckedException("Failed to create logger.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IgnitePeerToPeerClassLoadingException(org.apache.ignite.internal.processors.cache.IgnitePeerToPeerClassLoadingException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteTxAlreadyCompletedCheckedException(org.apache.ignite.internal.transactions.IgniteTxAlreadyCompletedCheckedException) JMException(javax.management.JMException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) SocketTimeoutException(java.net.SocketTimeoutException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) ClosedChannelException(java.nio.channels.ClosedChannelException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) URISyntaxException(java.net.URISyntaxException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) ComputeTaskCancelledCheckedException(org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) UTFDataFormatException(java.io.UTFDataFormatException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ComputeTaskTimeoutCheckedException(org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException) TransactionDuplicateKeyException(org.apache.ignite.transactions.TransactionDuplicateKeyException) NoSuchElementException(java.util.NoSuchElementException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CancellationException(java.util.concurrent.CancellationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedObjectNameException(javax.management.MalformedObjectNameException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) IgniteTxSerializationCheckedException(org.apache.ignite.internal.transactions.IgniteTxSerializationCheckedException) SocketException(java.net.SocketException) SQLException(java.sql.SQLException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) NamingException(javax.naming.NamingException) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) FileNotFoundException(java.io.FileNotFoundException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) MalformedURLException(java.net.MalformedURLException) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxDuplicateKeyCheckedException(org.apache.ignite.internal.transactions.IgniteTxDuplicateKeyCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) URL(java.net.URL) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LoggerNodeIdAndApplicationAware(org.apache.ignite.logger.LoggerNodeIdAndApplicationAware) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) IgniteLogger(org.apache.ignite.IgniteLogger) LoggerNodeIdAware(org.apache.ignite.logger.LoggerNodeIdAware) ZipFile(java.util.zip.ZipFile) File(java.io.File) JarFile(java.util.jar.JarFile) JavaLogger(org.apache.ignite.logger.java.JavaLogger)

Example 4 with LoggerNodeIdAndApplicationAware

use of org.apache.ignite.logger.LoggerNodeIdAndApplicationAware in project ignite by apache.

the class GridTestLog4jLogger method setApplicationAndNode.

/**
 * {@inheritDoc}
 */
@Override
public void setApplicationAndNode(@Nullable String application, UUID nodeId) {
    A.notNull(nodeId, "nodeId");
    this.nodeId = nodeId;
    for (FileAppender a : fileAppenders) {
        if (a instanceof LoggerNodeIdAndApplicationAware) {
            ((LoggerNodeIdAndApplicationAware) a).setApplicationAndNode(application, nodeId);
            a.activateOptions();
        }
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) LoggerNodeIdAndApplicationAware(org.apache.ignite.logger.LoggerNodeIdAndApplicationAware)

Example 5 with LoggerNodeIdAndApplicationAware

use of org.apache.ignite.logger.LoggerNodeIdAndApplicationAware in project ignite by apache.

the class Log4j2LoggerSelfTest method testFileConstructor.

/**
 * @throws Exception If failed.
 */
@Test
public void testFileConstructor() throws Exception {
    File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
    assert xml != null;
    assert xml.exists();
    IgniteLogger log = new Log4J2Logger(xml).getLogger(getClass());
    System.out.println(log.toString());
    assertTrue(log.toString().contains("Log4J2Logger"));
    assertTrue(log.toString().contains(xml.getPath()));
    ((LoggerNodeIdAndApplicationAware) log).setApplicationAndNode(null, UUID.randomUUID());
    checkLog(log);
}
Also used : LoggerNodeIdAndApplicationAware(org.apache.ignite.logger.LoggerNodeIdAndApplicationAware) IgniteLogger(org.apache.ignite.IgniteLogger) File(java.io.File) Test(org.junit.Test)

Aggregations

LoggerNodeIdAndApplicationAware (org.apache.ignite.logger.LoggerNodeIdAndApplicationAware)5 IgniteLogger (org.apache.ignite.IgniteLogger)4 File (java.io.File)3 URL (java.net.URL)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UTFDataFormatException (java.io.UTFDataFormatException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1 NoSuchElementException (java.util.NoSuchElementException)1