Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestDynamicLogLevel()
        {
            string logName = typeof(TestLogLevel).FullName;

            Org.Apache.Commons.Logging.Log testlog = LogFactory.GetLog(logName);
            //only test Log4JLogger
            if (testlog is Log4JLogger)
            {
                Logger log = ((Log4JLogger)testlog).GetLogger();
                log.Debug("log.debug1");
                log.Info("log.info1");
                log.Error("log.error1");
                Assert.True(!Level.Error.Equals(log.GetEffectiveLevel()));
                HttpServer2 server = new HttpServer2.Builder().SetName("..").AddEndpoint(new URI(
                                                                                             "http://*****:*****@out.WriteLine("*** Connecting to " + url);
                URLConnection connection = url.OpenConnection();
                connection.Connect();
                BufferedReader @in = new BufferedReader(new InputStreamReader(connection.GetInputStream
                                                                                  ()));
                for (string line; (line = @in.ReadLine()) != null; @out.WriteLine(line))
                {
                }
                @in.Close();
                log.Debug("log.debug2");
                log.Info("log.info2");
                log.Error("log.error2");
                Assert.True(Level.Error.Equals(log.GetEffectiveLevel()));
                //command line
                string[] args = new string[] { "-setlevel", authority, logName, Level.Debug.ToString
                                                   () };
                LogLevel.Main(args);
                log.Debug("log.debug3");
                log.Info("log.info3");
                log.Error("log.error3");
                Assert.True(Level.Debug.Equals(log.GetEffectiveLevel()));
            }
            else
            {
                @out.WriteLine(testlog.GetType() + " not tested.");
            }
        }
Пример #2
0
            /// <exception cref="Javax.Servlet.ServletException"/>
            /// <exception cref="System.IO.IOException"/>
            protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                          )
            {
                // Do the authorization
                if (!HttpServer2.HasAdministratorAccess(GetServletContext(), request, response))
                {
                    return;
                }
                PrintWriter @out    = ServletUtil.InitHTML(response, "Log Level");
                string      logName = ServletUtil.GetParameter(request, "log");
                string      level   = ServletUtil.GetParameter(request, "level");

                if (logName != null)
                {
                    @out.WriteLine("<br /><hr /><h3>Results</h3>");
                    @out.WriteLine(Marker + "Submitted Log Name: <b>" + logName + "</b><br />");
                    Org.Apache.Commons.Logging.Log log = LogFactory.GetLog(logName);
                    @out.WriteLine(Marker + "Log Class: <b>" + log.GetType().FullName + "</b><br />");
                    if (level != null)
                    {
                        @out.WriteLine(Marker + "Submitted Level: <b>" + level + "</b><br />");
                    }
                    if (log is Log4JLogger)
                    {
                        Process(((Log4JLogger)log).GetLogger(), level, @out);
                    }
                    else
                    {
                        if (log is Jdk14Logger)
                        {
                            Process(((Jdk14Logger)log).GetLogger(), level, @out);
                        }
                        else
                        {
                            @out.WriteLine("Sorry, " + log.GetType() + " not supported.<br />");
                        }
                    }
                }
                @out.WriteLine(Forms);
                @out.WriteLine(ServletUtil.HtmlTail);
            }