Exemplo n.º 1
0
        /// <summary>
        /// Adds a log output to the ADL system that is writing to a file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="mask"></param>
        /// <param name="timestamp"></param>
        private static void AddLogOutput(string file, int mask, bool timestamp)
        {
            if (File.Exists(file))
            {
                File.Delete(file);
            }
            LogTextStream lll = new LogTextStream(File.OpenWrite(file), MaskMatchType.MatchAll, timestamp);

            Debug.AddOutputStream(lll);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Initialization
        ///     Gets the File Stream and the Logstream ready.
        /// </summary>
        public void Initialize()
        {
            var str = GetLogPath();

            _fileStream = File.Open(str, FileMode.Create);
            _lts        = new LogTextStream(_fileStream, InstanceId)
            {
                OverrideChannelTag = true
            };
            Debug.AddOutputStream(_lts);
        }
Exemplo n.º 3
0
        public void ADL_Debug_RemoveOutputStream_Test()
        {
            LogTextStream lts = new LogTextStream(new PipeStream());

            Debug.AddOutputStream(lts);
            int newCount = Debug.LogStreamCount;

            Debug.RemoveOutputStream(lts);

            Assert.True(Debug.LogStreamCount == newCount - 1);
        }
Exemplo n.º 4
0
        public static void InitializeLogging()
        {
            OpenFLDebugConfig.Settings.MinSeverity             = Verbosity.Level1;
            InternalADLProjectDebugConfig.Settings.MinSeverity = Verbosity.Level1;
            ManifestIODebugConfig.Settings.MinSeverity         = Verbosity.Level1;

            LogTextStream ls = new LogTextStream(LogStream);

            Debug.DefaultInitialization();
            Debug.AddOutputStream(ls);
            LogReader = new StreamReader(LogStream);
        }
Exemplo n.º 5
0
        public void Test_RemoveOutputStream()
        {
            var lts = new LogTextStream(new PipeStream());

            Debug.AddOutputStream(lts);
            var newCount = Debug.LogStreamCount;

            Debug.AdlEnabled = false;
            Debug.RemoveOutputStream(lts);

            Debug.AdlEnabled = true;
            Debug.RemoveOutputStream(lts);
            Debug.RemoveOutputStream(lts);

            Assert.IsTrue(Debug.LogStreamCount == newCount - 1);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Function that sets up ADL to operate with the DebugLevel enum and more.
        /// </summary>
        private static void InitAdl()
        {
            CrashHandler.Initialize((int)DebugLevel.INTERNAL_ERROR, false);
            Debug.LoadConfig((AdlConfig) new AdlConfig().GetStandard());
            Debug.SetAllPrefixes("[ERRORS]", "[WARNINGS]", "[LOGS]", "[INTERNAL_ERROR]", "[PROGRESS]");
            Debug.AddPrefixForMask(-1, "[ALL]");
            Debug.CheckForUpdates = false;
            Debug.AdlWarningMask  = (int)DebugLevel.WARNINGS;
            lts = new LogTextStream(
                Console.OpenStandardOutput(),
                -1,
                MatchType.MatchAll,
                false);

            Debug.AddOutputStream(lts);
        }
Exemplo n.º 7
0
        private static void TestConsoleOut()
        {
            //First we want to Specify what Messages we want to let trough the LogStream we are creating in a minute.

            //You have multiple ways to create a Bitmask without getting cancer from bitwise operations
            var bMaskWildCard = new BitMask(true); //Creates a Wildcard(Everything will be let through)
            var bMaskNone     = new BitMask();     //Creates the opposite of Wildcard(Nothing will be let through)

            //There are also more readable ways to create a mask.
            //For example with enums. The Implementation will stay the same.
            var bMaskGenericWildcard = new BitMask <LoggingTypes>(true);
            var bMaskGenericNone     = new BitMask <LoggingTypes>();

            //But you can do masks easier now.
            //This bitmask only lets through logs and errors
            var bMaskGenericCustom = new BitMask <LoggingTypes>(LoggingTypes.Error, LoggingTypes.Log);


            //Then we want to create a LogStream that receives the Messages
            //Important: Its much easier to use CreateLogStreamFromStream than setting everything manually
            LogStream logStream = new LogTextStream(
                Console.OpenStandardOutput(),
                bMaskGenericCustom, //Lets use the generic custom
                MatchType.MatchOne, //We want to make the logs pass when there is at least one tag that is included in the filter.
                true                //Get that fancy timestamp infront of the log.
                );

            Debug.AddOutputStream(logStream); //Now we have Created the stream, just add it to the system.


            //This is a test.
            //for (var i = 1;
            //    i < 64;
            //    i++) //63 because its the highest value the current enum can take(every bit beeing 1)
            //{
            //    var mask = i;
            //    //Debug.Log(mask, "Test with mask " + mask);
            //}

            Debug.LogGen(LoggingTypes.Log, "Finished the Console Out Test.");

            //Now we want to remove the stream from the system.
            //Debug.RemoveOutputStream(logStream, true); //We want to remove a single one.
            //But we can remove all Streams in one go
            //Debug.RemoveAllOutputStreams(true);
        }
Exemplo n.º 8
0
        public static void Initialize()
        {
            Debug.AdlEnabled       = true;
            Debug.CheckForUpdates  = false;
            Debug.AdlWarningMask   = 2;
            Debug.SendWarnings     = true;
            Debug.PrefixLookupMode = PrefixLookupSettings.Addprefixifavailable | PrefixLookupSettings.Bakeprefixes |
                                     PrefixLookupSettings.Deconstructmasktofind;
            Debug.UpdateMask = 8;
            Debug.SetAllPrefixes("[Error]", "[Warning]", "[Log]", "[Internal Error]", "[Progress]");
            Debug.AddPrefixForMask(-1, "[ALL]");
            Debug.AddPrefixForMask(-1, "[NONE]");


            lts = new LogTextStream(Console.OpenStandardOutput(), BitMask.WildCard, MatchType.MatchAll, true);
            Debug.AddOutputStream(lts);
        }
Exemplo n.º 9
0
        public void Test_Log()
        {
            Debug.SendUpdateMessageOnFirstLog = false;
            var lts = new LogTextStream(new PipeStream())
            {
                AddTimeStamp = false
            };


            Debug.PrefixLookupMode            = PrefixLookupSettings.Noprefix;
            Debug.SendUpdateMessageOnFirstLog = false;
            Assert.IsTrue(Debug.PrefixLookupMode == PrefixLookupSettings.Noprefix);
            Assert.IsFalse(Debug.SendUpdateMessageOnFirstLog);

            Debug.AddOutputStream(lts);
            Debug.Log(1, "ffffffffff");

            var buf = new byte[lts.Length];

            lts.Read(buf, 0, buf.Length);
            var s = Debug.TextEncoding.GetString(buf);

            Assert.IsTrue(s.EndsWith("ffffffffff\n")); //ADL is appending the \n when using LogTextStreams


            Debug.LogGen(1, "ffffffffff");
            Debug.AdlEnabled = false;
            Debug.LogGen(1, "ffffffffff");
            Debug.AdlEnabled = true;
            buf = new byte[lts.Length];
            lts.Read(buf, 0, buf.Length);
            s = Debug.TextEncoding.GetString(buf);

            Assert.IsTrue(s.EndsWith("ffffffffff\n"));


            Debug.PrefixLookupMode = PrefixLookupSettings.Addprefixifavailable | PrefixLookupSettings.Bakeprefixes;

            Debug.Log(2 | 4, "CODE COVERAGE");
            Debug.Log(2 | 4, "CODE COVERAGE");
            Debug.SendUpdateMessageOnFirstLog = true;
        }
Exemplo n.º 10
0
        private static void TestLogFileOut()
        {
            //First we want to Specify what Messages we want to let trough the LogStream we are creating in a minute.

            //You have multiple ways to create a Bitmask without getting cancer from bitwise operations
            var bMaskWildCard = new BitMask(true); //Creates a Wildcard(Everything will be let through)
            var bMaskNone     = new BitMask();     //Creates the opposite of Wildcard(Nothing will be let through)

            //There are also more readable ways to create a mask.
            //For example with enums. The Implementation will stay the same.
            var bMaskGenericWildcard = new BitMask <LoggingTypes>(true);
            var bMaskGenericNone     = new BitMask <LoggingTypes>();

            //But you can do masks easier now.
            //This bitmask only lets through logs and errors
            var bMaskGenericCustom = new BitMask <LoggingTypes>(LoggingTypes.Fatal);


            //Then we want to create a LogStream that receives the Messages
            //Important: Its much easier to use CreateLogStreamFromFile than setting everything manually
            LogStream logStream = new LogTextStream(new FileStream("test.log", FileMode.OpenOrCreate),
                                                    bMaskGenericWildcard,
                                                    MatchType.MatchAll,
                                                    true//Get that fancy timestamp infront of the log.
                                                    );

            //logStream.OverrideChannelTag = true; //Forces the LogStream to discard all Tag and timestamps and ONLY save the actual log.

            Debug.AddOutputStream(logStream); //Now we have Created the stream, just add it to the system.



            Debug.LogGen(LoggingTypes.Log, "Finished adding the File Out.");

            //Now we want to remove the stream from the system.
            //Debug.RemoveOutputStream(logStream, true); //We want to remove a single one.
            //But we can remove all Streams in one go
            //Debug.RemoveAllOutputStreams(true);

            //In this case we want to delete the created log file to prevent logs piling up in the test project.
            //System.IO.File.Delete("test.log");
        }
Exemplo n.º 11
0
        public void ADL_Debug_Log_Test()
        {
            LogTextStream lts = new LogTextStream(new PipeStream())
            {
                AddTimeStamp = false
            };


            Debug.PrefixLookupMode = PrefixLookupSettings.Noprefix;
            Assert.True(Debug.PrefixLookupMode == PrefixLookupSettings.Noprefix);


            ADLLogger logger = new ADLLogger("UnitTest");


            Debug.AddOutputStream(lts);
            logger.Log(1, "ffffffffff");

            byte[] buf = new byte[lts.Length];
            lts.Read(buf, 0, buf.Length);
            string s = Debug.TextEncoding.GetString(buf);

            Assert.EndsWith("ffffffffff\n", s); //ADL is appending the \n when using LogTextStreams


            logger.Log(1, "ffffffffff");
            Debug.AdlEnabled = false;
            logger.Log(1, "ffffffffff");
            Debug.AdlEnabled = true;
            buf = new byte[lts.Length];
            lts.Read(buf, 0, buf.Length);
            s = Debug.TextEncoding.GetString(buf);

            Assert.EndsWith("ffffffffff\n", s);


            Debug.PrefixLookupMode = PrefixLookupSettings.Addprefixifavailable | PrefixLookupSettings.Bakeprefixes;

            logger.Log(2 | 4, "CODE COVERAGE");
            logger.Log(2 | 4, "CODE COVERAGE");
        }
Exemplo n.º 12
0
        public void ADL_Debug_Log_Test()
        {
            LogTextStream lts = new LogTextStream(new PipeStream())
            {
                AddTimeStamp = false
            };


            Debug.PrefixLookupMode = PrefixLookupSettings.NoPrefix;
            Assert.True(Debug.PrefixLookupMode == PrefixLookupSettings.NoPrefix);


            ADLLogger logger = new ADLLogger(InternalADLProjectDebugConfig.Settings, "UnitTest");


            Debug.AddOutputStream(lts);
            logger.Log(1, "ffffffffff", 0);

            byte[] buf = new byte[lts.Length];
            lts.Read(buf, 0, buf.Length);
            string s = Debug.TextEncoding.GetString(buf);

            Assert.True(s.EndsWith("ffffffffff\n")); //ADL is appending the \n when using LogTextStreams


            logger.Log(1, "ffffffffff", 0);
            buf = new byte[lts.Length];
            lts.Read(buf, 0, buf.Length);
            s = Debug.TextEncoding.GetString(buf);

            Assert.True(s.EndsWith("ffffffffff\n"));


            Debug.PrefixLookupMode = PrefixLookupSettings.AddPrefixIfAvailable | PrefixLookupSettings.BakePrefixes;

            logger.Log(2 | 4, "CODE COVERAGE", 0);
            logger.Log(2 | 4, "CODE COVERAGE", 0);
        }