Esempio n. 1
0
        public virtual void TestAppenderDefined()
        {
            HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();

            requestLogAppender.SetName("testrequestlog");
            Logger.GetLogger("http.requests.test").AddAppender(requestLogAppender);
            RequestLog requestLog = HttpRequestLog.GetRequestLog("test");

            Logger.GetLogger("http.requests.test").RemoveAppender(requestLogAppender);
            NUnit.Framework.Assert.IsNotNull("RequestLog should not be null", requestLog);
            Assert.Equal("Class mismatch", typeof(NCSARequestLog), requestLog
                         .GetType());
        }
Esempio n. 2
0
        public virtual void TestStartedServerWithRequestLog()
        {
            HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();

            requestLogAppender.SetName("httprequestlog");
            requestLogAppender.SetFilename(Runtime.GetProperty("test.build.data", "/tmp/") +
                                           "jetty-name-yyyy_mm_dd.log");
            Logger.GetLogger(typeof(HttpServer2).FullName + ".test").AddAppender(requestLogAppender
                                                                                 );
            HttpServer2 server = null;

            server = CreateTestServer();
            AssertNotLive(server);
            server.Start();
            AssertAlive(server);
            Stop(server);
            Logger.GetLogger(typeof(HttpServer2).FullName + ".test").RemoveAppender(requestLogAppender
                                                                                    );
        }
Esempio n. 3
0
        public static RequestLog GetRequestLog(string name)
        {
            string lookup = serverToComponent[name];

            if (lookup != null)
            {
                name = lookup;
            }
            string loggerName   = "http.requests." + name;
            string appenderName = name + "requestlog";
            Log    logger       = LogFactory.GetLog(loggerName);
            bool   isLog4JLogger;

            try
            {
                isLog4JLogger = logger is Log4JLogger;
            }
            catch (NoClassDefFoundError err)
            {
                // In some dependent projects, log4j may not even be on the classpath at
                // runtime, in which case the above instanceof check will throw
                // NoClassDefFoundError.
                Log.Debug("Could not load Log4JLogger class", err);
                isLog4JLogger = false;
            }
            if (isLog4JLogger)
            {
                Log4JLogger httpLog4JLog = (Log4JLogger)logger;
                Logger      httpLogger   = httpLog4JLog.GetLogger();
                Appender    appender     = null;
                try
                {
                    appender = httpLogger.GetAppender(appenderName);
                }
                catch (LogConfigurationException e)
                {
                    Log.Warn("Http request log for " + loggerName + " could not be created");
                    throw;
                }
                if (appender == null)
                {
                    Log.Info("Http request log for " + loggerName + " is not defined");
                    return(null);
                }
                if (appender is HttpRequestLogAppender)
                {
                    HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender)appender;
                    NCSARequestLog         requestLog         = new NCSARequestLog();
                    requestLog.SetFilename(requestLogAppender.GetFilename());
                    requestLog.SetRetainDays(requestLogAppender.GetRetainDays());
                    return(requestLog);
                }
                else
                {
                    Log.Warn("Jetty request log for " + loggerName + " was of the wrong class");
                    return(null);
                }
            }
            else
            {
                Log.Warn("Jetty request log can only be enabled using Log4j");
                return(null);
            }
        }