src/java/org/apache/cassandra/service/AbstractCassandraDaemon.java
/**
     * Initialize logging in such a way that it checks for config changes every 10 seconds.
     */
Initialize logging in such a way that it checks for config changes every 10 seconds.
Initialize logging in such a way that it checks for config changes every 10 seconds .
public static void initLog4j()
    {
        if (System.getProperty("log4j.defaultInitOverride","false").equalsIgnoreCase("true"))
        {
            String config = System.getProperty("log4j.configuration", "log4j-server.properties");
            URL configLocation = null;
            try
            {
                configLocation = new URL(config);
            }
            catch (MalformedURLException ex)
            {
                configLocation = AbstractCassandraDaemon.class.getClassLoader().getResource(config);
            }
            if (configLocation == null)
                throw new RuntimeException("Couldn't figure out log4j configuration: "+config);
            String configFileName = null;
            try
            {
                configFileName = configLocation.getFile();
                File configFile = new File(configFileName);
                if (!configFile.exists())
                    configFileName = new File(configLocation.toURI()).getCanonicalPath();
            }
            catch (Exception e)
            {
                throw new RuntimeException("Couldn't convert log4j configuration location to a valid file", e);
            }
            PropertyConfigurator.configureAndWatch(configFileName, 10000);
            org.apache.log4j.Logger.getLogger(AbstractCassandraDaemon.class).info("Logging initialized");
        }
    }
public static void initLog4j ( ) { if ( System . getProperty ( "log4j.defaultInitOverride" , "false" ) . equalsIgnoreCase ( "true" ) ) { String config = System . getProperty ( "log4j.configuration" , "log4j-server.properties" ) ; URL configLocation = null ; try { configLocation = new URL ( config ) ; } catch ( MalformedURLException ex ) { configLocation = AbstractCassandraDaemon . class . getClassLoader ( ) . getResource ( config ) ; } if ( configLocation == null ) throw new RuntimeException ( "Couldn't figure out log4j configuration: " + config ) ; String configFileName = null ; try { configFileName = configLocation . getFile ( ) ; File configFile = new File ( configFileName ) ; if ( ! configFile . exists ( ) ) configFileName = new File ( configLocation . toURI ( ) ) . getCanonicalPath ( ) ; } catch ( Exception e ) { throw new RuntimeException ( "Couldn't convert log4j configuration location to a valid file" , e ) ; } PropertyConfigurator . configureAndWatch ( configFileName , 10000 ) ; org . apache . log4j . Logger . getLogger ( AbstractCassandraDaemon . class ) . info ( "Logging initialized" ) ; } }
Initialize logging in such a way that it checks for config changes every 10 seconds.
Initialize logging in such a way that it checks for config changes every 10 seconds .
// try loading from a physical location first. // then try loading from the classpath. // Now convert URL to a filename // first try URL.getFile() which works for opaque URLs (file:foo) and paths without spaces // then try alternative approach which works for all hierarchical URLs with or without spaces