Search in sources :

Example 6 with NullAppender

use of org.apache.log4j.varia.NullAppender in project ACS by ACS-Community.

the class Log4jFactory method enableAcsLogging.

/**
	 * This method must be called once in order to enable ACS logging behind the scenes of log4j logging.
	 * <p>
	 * The log4j framework is quite resistant against being substituted with a different logging framework.
	 * Even though it is possible to configure a custom logger factory using <code>log4j.loggerFactory</code>,
	 * that factory will not be used when 3rd party code calls the usual <code>Logger.getLogger(name)</code>.
	 * It seems to make sense only for cases where the custom logger is used as in <code>MyLogger.getLogger(name)</code>.
	 * log4j-over-slf4j (http://www.slf4j.org/legacy.html) simply re-implements the relevant log4j classes, 
	 * which is too much trouble here for us because only basic log4j features are being used. 
	 * <p>
	 * We make use of the RepositorySelector mechanism, which log4j foresees for a different purpose, 
	 * to separate logging contexts in an application server that does not have classloader separation.
	 * (See also http://articles.qos.ch/sc.html.) 
	 * It is not possible to configure this externally, so that an application must call this method.
	 * See also http://mail-archives.apache.org/mod_mbox/logging-log4j-user/200904.mbox/%3Ca44e15a30904020424g4b7d7fcx63ca32152c81f80d@mail.gmail.com%3E
	 * <p>
	 * @TODO: In the future we could let ClientLogManager call this method, 
	 * but currently we are afraid of side effects with frameworks other than the laser alarm system
	 * that also use log4j (see http://jira.alma.cl/browse/COMP-8423).
	 */
public static void enableAcsLogging() {
    System.setProperty("log4j.defaultInitOverride", "true");
    //		System.setProperty("log4j.debug", "true");
    Hierarchy h = new MyLog4jHierarchy();
    RepositorySelector repositorySelector = new DefaultRepositorySelector(h);
    LogManager.setRepositorySelector(repositorySelector, null);
    Logger rootLogger = Logger.getRootLogger();
    rootLogger.removeAllAppenders();
    // to avoid "log4j:WARN No appenders could be found for logger (root)."
    rootLogger.addAppender(new NullAppender());
    rootLogger.setLevel(Level.ALL);
}
Also used : Hierarchy(org.apache.log4j.Hierarchy) DefaultRepositorySelector(org.apache.log4j.spi.DefaultRepositorySelector) RepositorySelector(org.apache.log4j.spi.RepositorySelector) DefaultRepositorySelector(org.apache.log4j.spi.DefaultRepositorySelector) NullAppender(org.apache.log4j.varia.NullAppender) RootLogger(org.apache.log4j.spi.RootLogger) Logger(org.apache.log4j.Logger) AcsLogger(alma.acs.logging.AcsLogger)

Example 7 with NullAppender

use of org.apache.log4j.varia.NullAppender in project voltdb by VoltDB.

the class Collector method main.

public static void main(String[] args) {
    // get rid of log4j "no appenders could be found for logger" warning when called from VEM
    Logger.getRootLogger().addAppender(new NullAppender());
    m_config = new CollectConfig();
    m_config.parse(Collector.class.getName(), args);
    if (!m_config.outputFile.trim().isEmpty() && !m_config.prefix.trim().isEmpty()) {
        System.err.println("For outputfile, specify either --output or --prefix. Can't specify " + "both of them.");
        m_config.printUsage();
        VoltDB.exit(-1);
    }
    populateVoltDBCollectionPaths();
    JSONObject jsonObject = parseJSONFile(m_configInfoPath);
    parseJSONObject(jsonObject);
    String systemStatsPathBase;
    if (m_config.libPathForTest.isEmpty())
        systemStatsPathBase = System.getenv("VOLTDB_LIB");
    else
        systemStatsPathBase = m_config.libPathForTest;
    String systemStatsPath;
    if (System.getProperty("os.name").contains("Mac"))
        systemStatsPath = systemStatsPathBase + File.separator + "macstats.properties";
    else
        systemStatsPath = systemStatsPathBase + File.separator + "linuxstats.properties";
    try {
        InputStream systemStatsIS = new FileInputStream(systemStatsPath);
        m_systemStats.load(systemStatsIS);
    } catch (IOException e) {
        Throwables.propagate(e);
    }
    Set<String> collectionFilesList = setCollection(m_config.skipheapdump);
    if (m_config.dryrun) {
        System.out.println("List of the files to be collected:");
        for (String path : collectionFilesList) {
            System.out.println("  " + path);
        }
        System.out.println("[dry-run] A tgz file containing above files would be generated in current dir");
        System.out.println("          Use --upload option to enable uploading via SFTP");
    } else {
        generateCollection(collectionFilesList);
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) NullAppender(org.apache.log4j.varia.NullAppender) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 8 with NullAppender

use of org.apache.log4j.varia.NullAppender in project ignite by apache.

the class GridCacheAbstractLoadTest method configuration.

/**
 * Initializes configurations.
 *
 * @param springCfgPath Configuration file path.
 * @param log Log file name.
 * @return Configuration.
 * @throws IgniteCheckedException If fails.
 */
@SuppressWarnings("unchecked")
protected IgniteConfiguration configuration(String springCfgPath, String log) throws IgniteCheckedException {
    File path = GridTestUtils.resolveIgnitePath(springCfgPath);
    if (path == null)
        throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
    if (!path.isFile())
        throw new IgniteCheckedException("Provided file path is not a file: " + path);
    // Add no-op logger to remove no-appender warning.
    Appender app = new NullAppender();
    Logger.getRootLogger().addAppender(app);
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
    } catch (BeansException | MalformedURLException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
    // Remove previously added no-op logger.
    Logger.getRootLogger().removeAppender(app);
    if (cfgMap.isEmpty())
        throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
    else if (cfgMap.size() > 1)
        throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
    IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
    cfg.setGridLogger(initLogger(log));
    cfg.getTransactionConfiguration().setDefaultTxIsolation(isolation);
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(concurrency);
    return cfg;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NullAppender(org.apache.log4j.varia.NullAppender) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Example 9 with NullAppender

use of org.apache.log4j.varia.NullAppender in project traccar by tananaev.

the class Log method setupLogger.

public static void setupLogger(Config config) throws IOException {
    Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
    Appender appender = new DailyRollingFileAppender(layout, config.getString("logger.file"), "'.'yyyyMMdd");
    LogManager.resetConfiguration();
    LogManager.getRootLogger().addAppender(new NullAppender());
    logger = Logger.getLogger(LOGGER_NAME);
    logger.addAppender(appender);
    logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
    // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
    InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {

        @Override
        public InternalLogger newInstance(String string) {
            return new NettyInternalLogger();
        }
    });
    Log.logSystemInfo();
    Log.info("Version: " + getAppVersion());
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) NullAppender(org.apache.log4j.varia.NullAppender) PatternLayout(org.apache.log4j.PatternLayout) InternalLoggerFactory(org.jboss.netty.logging.InternalLoggerFactory) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) InternalLogger(org.jboss.netty.logging.InternalLogger) AbstractInternalLogger(org.jboss.netty.logging.AbstractInternalLogger)

Aggregations

NullAppender (org.apache.log4j.varia.NullAppender)9 Appender (org.apache.log4j.Appender)5 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 BeansException (org.springframework.beans.BeansException)4 ApplicationContext (org.springframework.context.ApplicationContext)4 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 Logger (org.apache.log4j.Logger)2 RollingFileAppender (org.apache.log4j.RollingFileAppender)2 AcsLogger (alma.acs.logging.AcsLogger)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UUID (java.util.UUID)1