Search in sources :

Example 1 with LoggerNodeIdAware

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

the class GridLog4j2LoggingFileTest method setUp.

/** {@inheritDoc} */
@Override
protected void setUp() throws Exception {
    File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j2-test.xml");
    assert xml != null;
    assert xml.exists() == true;
    log = new Log4J2Logger(xml).getLogger(getClass());
    ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
}
Also used : LoggerNodeIdAware(org.apache.ignite.logger.LoggerNodeIdAware) File(java.io.File)

Example 2 with LoggerNodeIdAware

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

the class GridTestLog4jLogger method setNodeId.

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

Example 3 with LoggerNodeIdAware

use of org.apache.ignite.logger.LoggerNodeIdAware 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)

Aggregations

LoggerNodeIdAware (org.apache.ignite.logger.LoggerNodeIdAware)3 File (java.io.File)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 URL (java.net.URL)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 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CancellationException (java.util.concurrent.CancellationException)1