Exemple #1
0
        public static void TestParseLine(string sConfig, string sLine, string sPartitionExpected, string sRowKeyExpected, string sTickCountExpected, string sAppNameExpected,
                                         string sLevelExpected, string sEventIDExpected, string sInstanceIDExpected, string sPidExpected, string sTidExpected, string sMessageRawExpected,
                                         string sMessage0Expected,
                                         string sMessage1Expected, string sMessage2Expected, string sMessage3Expected, string sMessage4Expected, string sMessage5Expected, string sMessage6Expected,
                                         string sMessage7Expected, string sMessage8Expected, string sMessage9Expected)
        {
            TextLogConverter tlc          = TextLogConverter.CreateFromConfig(sConfig);
            AzLogEntry       azle         = tlc.ParseLine(sLine, 0);
            AzLogEntry       azleExpected = new AzLogEntry();

            azleExpected.InitMessageParts(10);

            azleExpected.SetColumn(AzLogEntry.LogColumn.Partition, sPartitionExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.RowKey, sRowKeyExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.EventTickCount, sTickCountExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.AppName, sAppNameExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Level, sLevelExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.EventID, sEventIDExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.InstanceID, sInstanceIDExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Pid, sPidExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Tid, sTidExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message, sMessageRawExpected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message0, sMessage0Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message1, sMessage1Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message2, sMessage2Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message3, sMessage3Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message4, sMessage4Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message5, sMessage5Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message6, sMessage6Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message7, sMessage7Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message8, sMessage8Expected);
            azleExpected.SetColumn(AzLogEntry.LogColumn.Message9, sMessage9Expected);


            AssertAzleEqual(azle, azleExpected);
        }
Exemple #2
0
        /* P A R S E  L I N E */

        /*----------------------------------------------------------------------------
        *   %%Function: ParseLine
        *   %%Qualified: AzLog.AzLogFile.TextLogConverter.ParseLine
        *   %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public AzLogEntry ParseLine(string sLine, int nLine)
        {
            AzLogEntry azle = new AzLogEntry();

            azle.InitMessageParts(10);

            int ilc     = 0;
            int ich     = 0;
            int ichLast = 0;

            int ichMac = sLine.Length;

            while (ilc < m_pltlc.Count)
            {
                ichLast = 0;

                TextLogColumn tlc = m_pltlc[ilc];

                // by definition we are already positioned at the beginning of this column except for possible whitespace
                // skip leading whitespace exc
                while (ich < ichMac && sLine[ich] == ' ')
                {
                    ich++;
                }

                if (ich >= ichMac)
                {
                    if (ilc < m_pltlc.Count)
                    {
                        return(null);
                    }
                    break;
                }
                int ichEnd = 0;

                // look for the separator
                if (tlc.Separator == TextLogColumn.Sep.Comma)
                {
                    if (!FParseQuotedCommaColumn(sLine, ich, ref ichLast, ref ichEnd, ichMac, ilc + 1 == m_pltlc.Count))
                    {
                        return(null);
                    }

                    // else, we'll calculate ichLim below
                }
                else if (tlc.Separator == TextLogColumn.Sep.FixedWidth)
                {
                    if (!FParseFixedWidthColumn(sLine, tlc.Cch, ich, ref ichLast, ref ichEnd, ichMac, ilc + 1 == m_pltlc.Count))
                    {
                        return(null);
                    }
                }

                if (ichLast == 0)
                {
                    if (ilc + 1 == m_pltlc.Count)
                    {
                        ichEnd = ichLast = sLine.Length - 1;
                    }
                    else
                    {
                        char chSep = TextLogColumn.CharFromSep(tlc.Separator);
                        ichLast = sLine.IndexOf(chSep, ich);
                        if (ichLast == -1)
                        {
                            return(null); // couldn't find the separator for this column
                        }
                        ichLast--;        // we want this to point to the last char, not to the separator
                        ichEnd = ichLast;
                    }
                }
                // at this point we have ich pointing to start of string; ichEnd pointing to last char before the separator (maybe a quote),
                // at ichLast pointing to just before the separator (never a quote)
                //, lets trim the string
                int ichFirst = ich;


                if (sLine[ichFirst] == '"' && sLine[ichEnd] == '"')
                {
                    ichFirst++;
                    ichEnd--;
                }

                while (ichEnd > ichFirst && sLine[ichEnd] == ' ')
                {
                    ichEnd--;
                }

                // now we have the string
                if (tlc.Column == AzLogEntry.LogColumn.EventTickCount)
                {
                    DateTime dttm = DateTime.Parse(sLine.Substring(ichFirst, ichEnd - ichFirst + 1));
                    dttm = dttm.ToUniversalTime();

                    azle.SetColumn(AzLogEntry.LogColumn.Partition, dttm.ToString("yyyyMMddHH"));
                    azle.EventTickCount = dttm.Ticks + nLine;
                    if (tlc.ColumnCopy != AzLogEntry.LogColumn.Nil)
                    {
                        azle.SetColumn(tlc.ColumnCopy, dttm.ToString("MM/dd/yyyy HH:mm:ss"));
                    }

                    // and manufacture a partition as well
                    azle.SetColumn(AzLogEntry.LogColumn.Partition, AzLogModel.SPartitionFromDate(dttm, dttm.Hour));
                }
                else
                {
                    azle.SetColumn(tlc.Column, sLine.Substring(ichFirst, ichEnd - ichFirst + 1));
                }

                if (tlc.Separator == TextLogColumn.Sep.FixedWidth)
                {
                    ich = ichLast;
                }
                else
                {
                    ich = ichLast + 2;
                }
                ilc++;
                if (ich >= ichMac)
                {
//                    if (ilc < m_pltlc.Count)
//                        return null;
                    break;
                }
            }

            //
            return(azle);
        }