Example #1
0
        /// <exception cref="System.Exception"/>
        public static void UpdateLog4jConfiguration(Type targetClass, string log4jPath)
        {
            Properties      customProperties = new Properties();
            FileInputStream fs  = null;
            InputStream     @is = null;

            try
            {
                fs  = new FileInputStream(log4jPath);
                @is = targetClass.GetResourceAsStream("/log4j.properties");
                customProperties.Load(fs);
                Properties originalProperties = new Properties();
                originalProperties.Load(@is);
                foreach (KeyValuePair <object, object> entry in customProperties)
                {
                    originalProperties.SetProperty(entry.Key.ToString(), entry.Value.ToString());
                }
                LogManager.ResetConfiguration();
                PropertyConfigurator.Configure(originalProperties);
            }
            finally
            {
                IOUtils.CloseQuietly(@is);
                IOUtils.CloseQuietly(fs);
            }
        }
Example #2
0
 private void InitLogging(string confDir)
 {
     if (Runtime.GetProperty("log4j.configuration") == null)
     {
         Runtime.SetProperty("log4j.defaultInitOverride", "true");
         bool     fromClasspath = true;
         FilePath log4jConf     = new FilePath(confDir, Log4jProperties).GetAbsoluteFile();
         if (log4jConf.Exists())
         {
             PropertyConfigurator.ConfigureAndWatch(log4jConf.GetPath(), 1000);
             fromClasspath = false;
         }
         else
         {
             ClassLoader cl       = Thread.CurrentThread().GetContextClassLoader();
             Uri         log4jUrl = cl.GetResource(Log4jProperties);
             if (log4jUrl != null)
             {
                 PropertyConfigurator.Configure(log4jUrl);
             }
         }
         Log = LoggerFactory.GetLogger(typeof(KMSWebApp));
         Log.Debug("KMS log starting");
         if (fromClasspath)
         {
             Log.Warn("Log4j configuration file '{}' not found", Log4jProperties);
             Log.Warn("Logging with INFO level to standard output");
         }
     }
     else
     {
         Log = LoggerFactory.GetLogger(typeof(KMSWebApp));
     }
 }
 private static void ConfigureLog4J()
 {
     if (System.IO.File.Exists(Log4JConfigFileName))
     {
         PropertyConfigurator.configureAndWatch(Log4JConfigFileName);
         return;
     }
 }
Example #4
0
 public virtual void SetUp()
 {
     originalOut = System.Console.Error;
     memOut      = new ByteArrayOutputStream();
     filterOut   = new TestKMSAudit.FilterOut(memOut);
     capturedOut = new TextWriter(filterOut);
     Runtime.SetErr(capturedOut);
     PropertyConfigurator.Configure(Thread.CurrentThread().GetContextClassLoader
                                        ().GetResourceAsStream("log4j-kmsaudit.properties"));
     this.kmsAudit = new KMSAudit(1000);
 }
Example #5
0
        /**
         * This method should be called first so the log4j logger can be created.
         */
        protected void initializeLogger()
        {
            setPropertiesFilePath();

            // Initial the logger objects.
            logger = Logger.getLogger(this.getClass().getSimpleName());

            // Load the properties for the log4j loggers.

            PropertyConfigurator.configure(propertiesFilePath + this.getClass().getSimpleName() + ".log4j.properties");
        }
Example #6
0
        /// <summary>Initializes Log4j logging.</summary>
        /// <exception cref="ServerException">thrown if Log4j could not be initialized.</exception>
        /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServerException"/>
        protected internal virtual void InitLog()
        {
            VerifyDir(logDir);
            LogManager.ResetConfiguration();
            FilePath log4jFile = new FilePath(configDir, name + "-log4j.properties");

            if (log4jFile.Exists())
            {
                PropertyConfigurator.ConfigureAndWatch(log4jFile.ToString(), 10 * 1000);
                //every 10 secs
                log = LoggerFactory.GetLogger(typeof(Org.Apache.Hadoop.Lib.Server.Server));
            }
            else
            {
                Properties props = new Properties();
                try
                {
                    InputStream @is = GetResource(DefaultLog4jProperties);
                    try
                    {
                        props.Load(@is);
                    }
                    finally
                    {
                        @is.Close();
                    }
                }
                catch (IOException ex)
                {
                    throw new ServerException(ServerException.ERROR.S03, DefaultLog4jProperties, ex.Message
                                              , ex);
                }
                PropertyConfigurator.Configure(props);
                log = LoggerFactory.GetLogger(typeof(Org.Apache.Hadoop.Lib.Server.Server));
                log.Warn("Log4j [{}] configuration file not found, using default configuration from classpath"
                         , log4jFile);
            }
        }
        public void Setup()
        {
            contentType = Mock.Of <IContentType>();
            StubContentType(1, "contentType", contentType);
            contentType.PropertyGroups = new PropertyGroupCollection(new List <PropertyGroup>());
            tab = new PropertyGroup()
            {
                Name = "tab"
            };
            contentType.PropertyGroups.Add(tab);

            dataTypeDefinition    = StubDataType(5, "richtext");
            urlPropertyDefinition = StubDataType(6, "textstring");

            AddRichTextProperty();
            AddUrlProperty();

            var tabConfigurator = Config
                                  .DocumentType("contentType")
                                  .Tab("tab");

            richTextConfig = tabConfigurator
                             .Property("richtext")
                             .DisplayName("Rich text")
                             .Description("Write rich content here")
                             .DataType("richtext");

            urlConfigurator = tabConfigurator
                              .Property("url")
                              .DisplayName("Url")
                              .Description("A relevant link")
                              .DataType("textstring")
                              .Mandatory()
                              .Regex("https?://[a-zA-Z0-9-.]+.[a-zA-Z]{2,}");

            // TODO: Sort order
        }