void PerformanceTestRL()
        {
            // create a lox for release logging
            Lox          lox       = new Lox("ReleaseLox");
            TextLogger   relLogger = Lox.CreateConsoleLogger();
            MemoryLogger ml        = new MemoryLogger();


            lox.SetVerbosity(relLogger, Verbosity.Verbose, "/CON");
            lox.SetVerbosity(ml, Verbosity.Verbose, "/MEM");


            lox.Info("/CON", "Logging simple info lines into a memory logger");

            AString msgBuf   = new AString( );
            long    fastest  = long.MaxValue;
            Ticks   timer    = new Ticks();
            int     qtyLines = 1000;
            int     qtyLoops = 2000; //1000

            if (System.Diagnostics.Debugger.IsAttached)
            {
                qtyLines = qtyLoops = 10;
            }

            for (int i = 0; i < qtyLoops; i++)
            {
            #if ALOX_DBG_LOG || ALOX_REL_LOG
                ml.MemoryLog.Clear();
            #endif

                timer.Set();
                for (int ii = 0; ii < qtyLines; ii++)
                {
                    lox.Info("/MEM", "Test Line");
                    if (i == 0 && ii == 0)
                    {
                        Console.WriteLine(ml.MemoryLog.ToString());
                    }
                }
                long t = timer.Age().Raw();

                if (fastest > t)
                {
                    fastest = t;
                    lox.Info("/CON", msgBuf.Clear()._("Pass ")._(i, 3)._(" is new fastest:  ")
                             ._((int)(new Ticks(fastest)).InMicros(), 0)
                             ._(" micros per ")._(qtyLines)._(" logs."));
                }
            }

            double microsPerLog  = ((double)(new Ticks(fastest)).InMicros()) / qtyLines;
            int    logsPerSecond = (int)(1000000.0 / microsPerLog);
            lox.Info("/CON", msgBuf._()._("  ")._(ESC.MAGENTA)._("Fastest Release Logging: ")
                     ._(microsPerLog)._(" micros per log (resp ")
                     ._(logsPerSecond)._(" logs per second) "));

            lox.RemoveLogger(ml);
            lox.RemoveLogger(relLogger);
        }
        public UTWriter()
        {
            lox = new Lox("UTLox");
            // This does not work/make sense with MonoDevelop.
            //if( System.Diagnostics.Debugger.IsAttached )
            //    logger= new CLRDebuggerLogger();
            //else
            logger = Lox.CreateConsoleLogger("UT ALib ReportWriter");

            lox.SetVerbosity(logger, Verbosity.Verbose, "UT");
            lox.SetVerbosity(logger, Verbosity.Verbose, ALox.InternalDomains);
            lox.SetPrefix(ESC.BG_GRAY, "/");

            cs.aworx.lib.Report.GetDefault().PushWriter(this);
        }
        public void ReleaseLogging()
        {
            // create a lox for release logging
            Lox lox = new Lox("ReleaseLox");

            // let the system choose an appropriate console logger
            TextLogger releaseLogger = Lox.CreateConsoleLogger();

            // we set a format string without scope information (as this is of-course not available in release logging)
        #if ALOX_DBG_LOG || ALOX_REL_LOG
            releaseLogger.MetaInfo.Format = new AString("[%TC +%TL][%tN]%V[%D]%A1(%#): ");
        #endif
            lox.SetVerbosity(releaseLogger, Verbosity.Info, "A_DOMAIN");

            lox.Info("A_DOMAIN", "Hello ALox, this is release logging");

            lox.RemoveLogger(releaseLogger);
        }
        public void Lox_ScopeDomains()
        {
            UT_INIT();

            // we have tell alox to include more directories in the scope path
            Log.ClearSourcePathTrimRules(Inclusion.Include, false);
            Log.SetSourcePathTrimRule("*/alox/src.cs/", Inclusion.Exclude);

            Lox          lox           = new Lox("ReleaseLox");
            TextLogger   consoleLogger = Lox.CreateConsoleLogger();
            MemoryLogger ml            = new MemoryLogger();

            ml.MetaInfo.Format._()._("@%D#");
            lox.SetVerbosity(ml, Verbosity.Verbose);

            lox.SetVerbosity(consoleLogger, Verbosity.Verbose);
            lox.SetVerbosity(consoleLogger, Verbosity.Verbose, ALox.InternalDomains);

            // scope global
            lox.SetDomain("REPLACE", Scope.Global);  lox.Info("", ""); SDCHECK_RL("@/REPLACE#", ml);
            lox.SetDomain("GLOBAL", Scope.Global);  lox.Info("", ""); SDCHECK_RL("@/GLOBAL#", ml);

            lox.SetDomain(null, Scope.Global);  lox.Info("", ""); SDCHECK_RL("@/#", ml);

            // scope source
            lox.SetDomain("REPLACE", Scope.Filename);  lox.Info("", ""); CICHECK_RL("@/REPLACE#", ml);
            lox.SetDomain("FILE", Scope.Filename);  lox.Info("", ""); CICHECK_RL("@/FILE#", ml);

            // scope method
            lox.SetDomain("REPLACE", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/FILE/REPLACE#", ml);
            lox.SetDomain("Method", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/FILE/METHOD#", ml);
            lox.SetDomain("/ABS", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/ABS#", ml);

            // unset method with null
            lox.SetDomain(null, Scope.Method);  lox.Info("", ""); CICHECK_RL("@/FILE#", ml);

            // unset method with ""
            lox.SetDomain("/METHOD", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/METHOD#", ml);
            lox.SetDomain("", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/FILE#", ml);
            lox.SetDomain("Method", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/FILE/METHOD#", ml);

            // source path
            lox.SetDomain("REPLACE", Scope.Path);  lox.Info("", ""); CICHECK_RL("@/REPLACE/FILE/METHOD#", ml);
            lox.SetDomain("PATH", Scope.Path);  lox.Info("", ""); CICHECK_RL("@/PATH/FILE/METHOD#", ml);
            lox.SetDomain("REPLACE", Scope.Path, 1);  lox.Info("", ""); CICHECK_RL("@/REPLACE/PATH/FILE/METHOD#", ml);
            lox.SetDomain("PO1", Scope.Path, 1);  lox.Info("", ""); CICHECK_RL("@/PO1/PATH/FILE/METHOD#", ml);
            lox.SetDomain("REPLACE", Scope.Path, 2);  lox.Info("", ""); CICHECK_RL("@/REPLACE/PO1/PATH/FILE/METHOD#", ml);
            lox.SetDomain("PO2", Scope.Path, 2);  lox.Info("", ""); CICHECK_RL("@/PO2/PO1/PATH/FILE/METHOD#", ml);

            lox.SetDomain("GLOBAL", Scope.Global);  lox.Info("", ""); CICHECK_RL("@/GLOBAL/PO2/PO1/PATH/FILE/METHOD#", ml);


            // remove all previous scope domains
            lox.SetDomain("", Scope.Global);
            lox.SetDomain("", Scope.Path);
            lox.SetDomain("", Scope.Path, 1);
            lox.SetDomain("", Scope.Path, 2);
            lox.SetDomain("", Scope.Filename);
            lox.SetDomain("", Scope.Method);  lox.Info("LOC", ""); SDCHECK_RL("@/LOC#", ml);

            // Thread-related
            lox.SetDomain("T_O", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/T_O#", ml);
            lox.SetDomain("GL", Scope.Global);  lox.Info("", ""); SDCHECK_RL("@/GL/T_O#", ml);
            lox.SetDomain("MET", Scope.Method);  lox.Info("", ""); CICHECK_RL("@/GL/T_O/MET#", ml);
            lox.Info("LOC", ""); CICHECK_RL("@/GL/T_O/MET/LOC#", ml);
            lox.SetDomain("T_I", Scope.ThreadInner);  lox.Info("", ""); CICHECK_RL("@/GL/T_O/MET/T_I#", ml);
            lox.Info("LOC", ""); CICHECK_RL("@/GL/T_O/MET/LOC/T_I#", ml);
            lox.SetDomain("T_O2", Scope.ThreadOuter);  lox.Info("", ""); CICHECK_RL("@/GL/T_O/T_O2/MET/T_I#", ml);
            lox.SetDomain("T_I2", Scope.ThreadInner);  lox.Info("", ""); CICHECK_RL("@/GL/T_O/T_O2/MET/T_I/T_I2#", ml);

            lox.SetDomain("/T_O3", Scope.ThreadOuter);  lox.Info("", ""); CICHECK_RL("@/T_O3/MET/T_I/T_I2#", ml);
            lox.SetDomain("/T_I3", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_I3#", ml);
            lox.SetDomain("", Scope.Method);  lox.Info("", ""); SDCHECK_RL("@/T_I3#", ml);

            lox.SetDomain("", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_O3/T_I/T_I2#", ml);
            lox.RemoveThreadDomain("T_IXX", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_O3/T_I/T_I2#", ml);
            lox.RemoveThreadDomain("T_I", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_O3/T_I2#", ml);
            lox.RemoveThreadDomain("", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_O3/T_I2#", ml);
            lox.SetDomain("", Scope.ThreadInner);  lox.Info("", ""); SDCHECK_RL("@/T_O3#", ml);
            lox.SetDomain("", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/GL/T_O/T_O2#", ml);
            lox.SetDomain("T_O3", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/GL/T_O/T_O2/T_O3#", ml);
            lox.RemoveThreadDomain("T_O2", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/GL/T_O/T_O3#", ml);
            lox.RemoveThreadDomain("T_O", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/GL/T_O3#", ml);
            lox.SetDomain("", Scope.ThreadOuter);  lox.Info("", ""); SDCHECK_RL("@/GL#", ml);
            lox.SetDomain("", Scope.Global);  lox.Info("", ""); SDCHECK_RL("@/#", ml);


            // second thread
            Thread thread = new Thread(new ParameterizedThreadStart(DomainTestThreadRun_RL));

            lox.SetDomain("THIS_THREAD", Scope.ThreadOuter);
            lox.SetDomain("OTHER_THREAD", Scope.ThreadOuter, thread);
            thread.Start(lox);
            while (thread.IsAlive)
            {
                ALIB.SleepMillis(1);
            }
            UT_EQ("@/OTHER_THREAD/DTT#", ml.MemoryLog);  ml.MemoryLog._(); ml.AutoSizes.Reset();
            lox.Info("ME", "");  UT_EQ("@/THIS_THREAD/ME#", ml.MemoryLog);  ml.MemoryLog._(); ml.AutoSizes.Reset();

            // cleanup
            lox.RemoveLogger(consoleLogger);
            lox.RemoveLogger(ml);
        }
        public void Log_Domain_IniFile()
        {
            UT_INIT();

            // Without priorities
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_TESTML_VERBOSITY",
                             "/DOM_VERB  = VerboseXX  ;" // xx is allowed!
                             + "/DOM_INFO  = Info       ;"
                             + "/DOM_WARN  = WARNING    ;"
                             + "/DOM_ERR   = erRor      ;"
                             + "/DOM_OFF   = off        ;"
                             + "/DOM_OFF2  = xxx        ;"
                             + "/ATSTART*  = Info       ;"
                             + "*ATEND     = Info       ;"
                             + "*SUBSTR*   = Info       ;"
                             + "/OVERWRITE = Info       ;"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                // pre-create one of the domains to test if loggers added later get config for existing domains
                lox.Verbose("DOM_INFO", "test");

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Off);

                lox.Info("test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Error("NOSETTING", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;

                lox.Verbose("DOM_VERB", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs = 0;

                lox.Verbose("DOM_INFO", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("DOM_INFO", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                lox.Info("DOM_WARN", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;
                lox.Warning("DOM_WARN", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs = 0;

                lox.Warning("DOM_ERR", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Error("DOM_ERR", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs   = 0;

                lox.Error("DOM_OFF", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs  = 0;
                lox.Error("DOM_OFF2", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;

                lox.Verbose("ATSTART", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs   = 0;
                lox.Info("ATSTART", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs      = 0;
                lox.Verbose("ATSTARTXX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("ATSTARTXX", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XXATSTART", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XXATSTART", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XATSTARTX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XATSTARTX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;

                lox.Verbose("ATEND", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs   = 0;
                lox.Info("ATEND", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs      = 0;
                lox.Verbose("ATENDXX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("ATENDXX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XXATEND", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XXATEND", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XATENDX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XATENDX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;

                lox.Verbose("SUBSTR", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs   = 0;
                lox.Info("SUBSTR", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs      = 0;
                lox.Verbose("SUBSTRXX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("SUBSTRXX", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XXSUBSTR", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XXSUBSTR", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("XSUBSTRX", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("XSUBSTRX", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                // overwrite config
                lox.Verbose("/OVERWRITE", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/OVERWRITE", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                lox.SetVerbosity(ml, Verbosity.Warning, "/OVERWRITE"); // does not overwrite
                lox.Verbose("/OVERWRITE", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/OVERWRITE", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                lox.SetVerbosity(ml, Verbosity.Warning, "/OVERWRITE", 1000); // does overwrite
                lox.Verbose("/OVERWRITE", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/OVERWRITE", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;
                lox.Warning("/OVERWRITE", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs = 0;

                // overwrite non-config
                lox.Error("/A", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs   = 0;
                lox.Error("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Error("/A/C", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;

                lox.SetVerbosity(ml, Verbosity.Info, "/A/B", Lox.PrioSource - 1); // does not overwrite
                lox.Verbose("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs    = 0;

                lox.SetVerbosity(ml, Verbosity.Info, "/A/B", Lox.PrioSource); // does overwrite
                lox.Verbose("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/A/B", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                lox.SetVerbosity(ml, Verbosity.Info, "/A/B", Lox.PrioSource + 1); // one higher
                lox.Verbose("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/A/B", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;

                lox.SetVerbosity(ml, Verbosity.Verbose, "/A");
                lox.Verbose("/A", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs   = 0;
                lox.Verbose("/A/B", "test");    UT_EQ(0, ml.CntLogs); ml.CntLogs = 0;
                lox.Info("/A/B", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs    = 0;
                lox.Verbose("/A/C", "test");    UT_EQ(1, ml.CntLogs); ml.CntLogs = 0;

                //lox.LogConfig( "", Verbosity.Info, "Configuration now is:" ); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }
        }
        public void Log_DomainSubstitutions_IniFile()
        {
            UT_INIT();

            // create ini file
            String iniFileContents =
                "[ALOX]\n"
                + "TESTMEMLOGGER_FORMAT= \"<%D>\"  \n"

                + "MYLOX_DOMAIN_SUBSTITUTION = /A_DOM -> /BETTER_NAME   ;\\ \n"
                + "    /UI    -> /LIBS/UI    \n"

                + "x\n"
            ;

/* SNIPPIT FOR Dox
 * //! [Man_DomSubst_Config]
 * [ALOX]
 * MYLOX_DOMAIN_SUBSTITUTION= /A_DOM -> /BETTER_NAME   ; \
 *                         /UI    -> /LIBS/UI
 * //! [Man_DomSubst_Config]
 */
            String       fileName = Environment.CurrentDirectory + "/Log_DomainSubstitutions_IniFile.ini";
            StreamWriter file     = new StreamWriter(fileName);

            file.Write(iniFileContents);
            file.Close();

            IniFile iniFile = new IniFile(fileName);

            iniFile.ReadFile();
            //iniFile.WriteFile(); // temporarily enable to see what we have written above

            // add to config
            ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);

            // create lox, loggers
            Lox myLox = new Lox("MyLox"); // name will be upper case

            myLox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
            myLox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

// SNIPPIT FOR Dox
#if NEVER_DEFINED
//! [Man_DomSubst_Config_Prevent]
            myLox = new Lox("MyLox");                    // name will be converted to upper case
            myLox.SetDomainSubstitutionRule(null, null); // clear rules eventually read in constructor
//! [Man_DomSubst_Config_Prevent]
#endif


            MemoryLogger ml = new MemoryLogger("TESTMEMLOGGER");
            myLox.SetVerbosity(ml, Verbosity.Verbose);

            LOG_CHECK("DOM", "</DOM>", ml, myLox);
            LOG_CHECK("A_DOM", "</BETTER_NAME>", ml, myLox);
            LOG_CHECK("UI", "</LIBS/UI>", ml, myLox);

            //Log.LogConfig( "", Verbosity.Info, "Configuration now is:" );

            ALIB.Config.RemovePlugin(iniFile);
            myLox.RemoveLogger(ml);
            myLox.RemoveLogger("CONSOLE");
        }
Exemple #7
0
        public void Lox_LogLevelSetting()
        {
            UT_INIT();
            Lox        lox    = new Lox("ReleaseLox");
            TextLogger logger = Lox.CreateConsoleLogger(null);

            lox.SetDomain("TLLS_DF", Scope.Method);
            int logLinesBefore = logger.CntLogs;

            // Test Verbosity setting

            lox.SetVerbosity(logger, Verbosity.Verbose, "");
            lox.Verbose("This Verbose line should be logged");
            lox.Info("This Info    line should be logged");
            lox.Warning("This WARN    line should be logged");
            lox.Error("This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Info, "");
            lox.Verbose("This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("This Info    line should be logged");
            lox.Warning("This Warning line should be logged");
            lox.Error("This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Warning, "");
            lox.Verbose("This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("This Warning line should be logged");
            lox.Error("This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Error, "");
            lox.Verbose("This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("This Warning line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Error("This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Off, "");
            lox.Verbose("This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("This Warning line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Error("This Error   line should NOT be logged. !!!!!Test Error!!!!!");

            lox.SetVerbosity(logger, Verbosity.Verbose, "/TLLS");
            lox.Verbose("/TLLS", "This Verbose line should be logged");
            lox.Info("/TLLS", "This Info    line should be logged");
            lox.Warning("/TLLS", "This WARN    line should be logged");
            lox.Error("/TLLS", "This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Info, "/TLLS");
            lox.Verbose("/TLLS", "This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("/TLLS", "This Info    line should be logged");
            lox.Warning("/TLLS", "This Warning line should be logged");
            lox.Error("/TLLS", "This Error   line should be logged");


            lox.SetVerbosity(logger, Verbosity.Warning, "/TLLS");
            lox.Verbose("/TLLS", "This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("/TLLS", "This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("/TLLS", "This Warning line should be logged");
            lox.Error("/TLLS", "This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Error, "/TLLS");
            lox.Verbose("/TLLS", "This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("/TLLS", "This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("/TLLS", "This Warning line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Error("/TLLS", "This Error   line should be logged");

            lox.SetVerbosity(logger, Verbosity.Off, "/TLLS");
            lox.Verbose("/TLLS", "This Verbose line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Info("/TLLS", "This Info    line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Warning("/TLLS", "This Warning line should NOT be logged. !!!!!Test Error!!!!!");
            lox.Error("/TLLS", "This Error   line should NOT be logged. !!!!!Test Error!!!!!");

            UT_EQ((uint)20, logger.CntLogs - logLinesBefore);

            lox.RemoveLogger(logger);
        }
Exemple #8
0
        public void Log_SetSourcePathTrimRuleExternal()
        {
            UT_INIT();

            // for the unit tests to reset, we need an extra lox to be able to clear the global rules
            // beforewe initialize our main lox
            Lox clearLox = new Lox("ClearingRules");

            // global rule
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                String iniFileContents =
                    "[ALOX]\n"
                    + "TESTML_FORMAT= \"%Sp\"  \n"

                    + "GLOBAL_SOURCE_PATH_TRIM_RULES=  *src.cs/   , true  ;     \\   \n"
                    + "    /usr/lib/libzip/include/  , false, 9, true"
                    + "\n"
                ;

/* SNIPPIT FOR Dox
 * //! [Man_SourcePathTrimming]
 * [ALOX]
 * GLOBAL_SOURCE_PATH_TRIM_RULES= *src.cs/                  , true                ; \
 *                             /usr/lib/libzip/include/  , false, 9, true
 * //! [Man_SourcePathTrimming]
 */
                String       fileName = Environment.CurrentDirectory + "/Log_ConfigTrimRules.ini";
                StreamWriter file     = new StreamWriter(fileName);
                file.Write(iniFileContents);
                file.Close();

                IniFile iniFile = new IniFile(fileName);
                iniFile.ReadFile();
                //iniFile.WriteFile(); // temporarily enable to see what we have written above

                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);

                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info("");  UT_EQ("alox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            // local rule
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*;**;*alox.u*, incl ;*;**"   // default values, 0, ignore"
                                                           // the * will be removed
                                                           // two illegal rules before and after
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("nittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*alox.u, excl, 2, sens"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("ox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            // ignore case
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*aLOX.U, exc, 2, ign"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("ox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*aLOX.U, excl, 2, sens"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info("");
                if (Path.DirectorySeparatorChar == '/')
                {
                    UT_EQ("src.cs/alox.unittests", ml.MemoryLog);
                }
                else
                {
                    UT_EQ("src.cs\\alox.unittests", ml.MemoryLog);
                }

                ml.MemoryLog._(); ml.AutoSizes.Reset();
                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }
        }