Ejemplo n.º 1
0
 public void SetLastMaxPosition(LogPos logPos)
 {
     LastMaxLogPosition = logPos;
     LastMaxPosition    = Reader.GetPosition();
     lastFileLength     = new FileInfo(Filename).Length;
     LastMaxLine        = LoglineObject.ReadLine(logPos);
     IsDisposed         = false;
 }
Ejemplo n.º 2
0
            public HqlParameter(LoglineObject loglineObject)
            {
                MatchCollection mc = expression.Matches(loglineObject.Message);

                if (mc.Count >= 2)
                {
                    if (mc.Count == 3)
                    {
                        ParameterPos   = Int32.Parse(mc[0].Value.Trim("[]".ToCharArray()));
                        SqlType        = mc[1].Value.Trim("[]".ToCharArray());
                        ParameterValue = mc[2].Value.Trim("[]".ToCharArray());
                    }
                    else
                    {
                        ParameterValue = mc[0].Value.Trim("[]".ToCharArray());
                        ParameterPos   = Int32.Parse(mc[1].Value.Trim("[]".ToCharArray()));
                        SqlType        = "VARCHAR";
                    }

                    if (ParameterValue == "null")
                    {
                        Sql = "null";
                    }
                    else if (SqlType.Contains("CHAR"))
                    {
                        Sql = "'" + ParameterValue.Replace("'", "''") + "'";
                    }
                    else if (SqlType == "DATE" || SqlType == "TIMESTAMP")
                    {
                        DateTime date;
                        if (DateTime.TryParseExact(ParameterValue, "ddd MMM dd HH:mm:ss CET yyyy", culture, DateTimeStyles.None, out date))
                        {
                            if (SqlType == "DATE")
                            {
                                Sql = "'" + date.ToString("yyyy-MM-dd") + "'";
                            }
                            else
                            {
                                Sql = "'" + date.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                            }
                        }
                    }
                    else
                    {
                        Sql = ParameterValue;
                    }
                }
            }
Ejemplo n.º 3
0
        public static LoglineObject CreateLoglineObject(string line, LogPos logPos)
        {
            LoglineObject loglineObject = new LoglineObject()
            {
                LogPos = logPos
            };

            if (logPos.LoglineType == LoglineType.MAIN_LOG)
            {
                int    headerPos  = line.IndexOf(" - ");
                String header     = headerPos > 0 ? line.Substring(0, line.IndexOf(" - ")) : line;
                int    posThread  = header.IndexOf(" [");
                int    posThread2 = header.LastIndexOf("] ");
                loglineObject.Threadname = posThread > 0 && posThread2 > 0 ? header.Substring(posThread + 1, posThread2 - posThread) : String.Empty;
                int posClassname = header.LastIndexOf(' ');
                loglineObject.Classname      = posClassname > 0 ? header.Substring(header.LastIndexOf(' ') + 1) : String.Empty;
                loglineObject.ClassnameShort = posClassname > 0 ? loglineObject.Classname.Substring(loglineObject.Classname.LastIndexOf('.') + 1) : String.Empty;
                loglineObject.Message        = line.Length > header.Length + 3 ? line.Substring(header.Length + 3) : String.Empty;
                loglineObject.Level          = line.Length > 29 ? line.Substring(24, 5).Trim() : String.Empty;
                loglineObject.Timestamp      = line.Length > 23 ? line.Substring(0, 23) : String.Empty;

                int duration = GetDurationFromLogPos(loglineObject.Message);
                if (duration >= 0)
                {
                    loglineObject.Duration = duration;
                }
            }
            else
            {
                if (logPos.LoglineType == LoglineType.CATALINA_LOG)
                {
                    int index = Math.Max(line.IndexOf("AM"), line.IndexOf("PM"));

                    loglineObject.Timestamp = logPos.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss,fff");
                    loglineObject.Classname = "catalina";
                    loglineObject.Message   = index > 0 ? line.Substring(index + 3) : line;
                }
                else
                {
                    loglineObject.Message = line;
                }
            }

            return(loglineObject);
        }
Ejemplo n.º 4
0
        private void SelectedIndexChanged(LogListControl listViewLog)
        {
            if (listViewLog.SelectedIndex >= 0)
            {
                int index = listViewLog.SelectedIndex;
                if (infoControl != null)
                {
                    long selectedLine = LoglineObject.InfoTextFromLine(streamingFactory, index, infoControl.InfoTextBox);
                    infoControl.Tag = selectedLine;

                    if (!isFromSearchControl)
                    {
                        this.searchControlMain.SelectedLine      = (int)selectedLine;
                        this.searchControlMain.SelectedTimestamp = streamingFactory.PositionList[index].TimeStamp;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void Poll()
        {
            if (isBusy || isReleased || streamingHosts.Count == 0)
            {
                return;
            }

            isBusy = true;

            long newPositions = 0;

            foreach (StreamingHost sh in streamingHosts)
            {
                int isBigger = sh.HasChanged();
                if (isBigger > 0)
                {
                    if (sh.LastMaxLine == LoglineObject.ReadLine(sh.LastMaxLogPosition))
                    {
                        newPositions += ScanFile(null, 0, sh);
                    }
                    else
                    {
                        SetInconsistent();
                        return;
                    }
                }
                else if (isBigger < 0)
                {
                    SetInconsistent();
                    return;
                }
            }

            if (newPositions > 0 && NewPositions != null)
            {
                MainForm.FlashTrayIcon();
                NewPositions.Invoke(this, EventArgs.Empty);
            }
            isBusy = false;
        }
Ejemplo n.º 6
0
        public static long InfoTextFromLine(StreamingFactory streamingFactory, int index, RichTextBox infoTextBox)
        {
            LogPos logPos = streamingFactory.PositionList[index];

            logPos = logPos.Parent != null ? logPos.Parent : logPos;
            StringBuilder sb            = new StringBuilder();
            String        line          = ReadLine(logPos);
            LoglineObject loglineObject = CreateLoglineObject(line, logPos);

            if (logPos.LoglineType == LoglineType.MAIN_LOG)
            {
                String messageResult = loglineObject.Message;
                if (loglineObject.Classname.EndsWith("HttpAuthInterceptor"))
                {
                    int index1 = loglineObject.Message.LastIndexOf("):");
                    if (index1 >= 0)
                    {
                        messageResult = loglineObject.Message.Substring(0, index1 + 1) + Environment.NewLine
                                        + loglineObject.Message.Substring(index1 + 3);
                    }

                    int index2 = messageResult.IndexOf(" - ");
                    if (index2 >= 0)
                    {
                        messageResult = messageResult.Substring(0, index2) + Environment.NewLine
                                        + messageResult.Substring(index2 + 3);
                    }
                }
                else if (loglineObject.Classname == "org.hibernate.type.EnumType" ||
                         loglineObject.Classname == "org.hibernate.type.descriptor.sql.BasicBinder" ||
                         loglineObject.Classname == "org.hibernate.SQL")
                {
                    messageResult = LogLineObjectHibernateSql.Info(streamingFactory, index, loglineObject);
                }
                else if (loglineObject.Classname == "org.jdbcdslog.StatementLogger" ||
                         loglineObject.Classname == "org.jdbcdslog.SlowQueryLogger")
                {
                    messageResult = LogLineObjectStatementLoggerSql.Info(streamingFactory, index, loglineObject);
                }

                sb.AppendLine($"{loglineObject.Timestamp} {loglineObject.Level}\r\n{loglineObject.Threadname}\r\n{loglineObject.Classname}\r\n\r\n{messageResult}");
            }
            else if (logPos.LoglineType == LoglineType.CATALINA_LOG)
            {
                sb.AppendLine($"{loglineObject.Timestamp} {loglineObject.Classname}\r\n{loglineObject.Message}");
            }
            else
            {
                sb.AppendLine(line);
            }

            if (logPos.Childs != null)
            {
                foreach (LogPos lp in logPos.Childs)
                {
                    sb.AppendLine("    " + LoglineObject.ReadLine(lp));
                }
            }

            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine(logPos.LogSource.Filename);

            infoTextBox.Text = sb.ToString();
            int lineCounter = 0;

            foreach (string infoLine in infoTextBox.Lines)
            {
                foreach (String pattern in LogUtils.LineMarkerFont)
                {
                    if (infoLine.Contains(pattern))
                    {
                        infoTextBox.Select(infoTextBox.GetFirstCharIndexFromLine(lineCounter), infoLine.Length);
                        infoTextBox.SelectionBackColor = Color.LightGreen;
                        infoTextBox.SelectionFont      = new Font(infoTextBox.Font, FontStyle.Bold);
                    }
                }
                lineCounter++;
            }
            infoTextBox.Select(0, 0);

            return(index - (streamingFactory.PositionList[index].Order - logPos.Order));
        }
Ejemplo n.º 7
0
        public static string Info(StreamingFactory streamingFactory, int index, LoglineObject loglineObject)
        {
            string messageResult;
            int    pos = 0;
            Dictionary <int, LoglineObject> hibernateSqlDic = new Dictionary <int, LoglineObject>();

            hibernateSqlDic.Add(pos, loglineObject);
            LogPos        logPosSql  = null;
            String        lineSql    = null;
            String        threadName = loglineObject.Threadname;
            LoglineObject loglineObjectSql;

            if (loglineObject.Classname != "org.hibernate.SQL" && index > 0)
            {
                pos--;
                logPosSql        = streamingFactory.PositionList[index + pos];
                lineSql          = LoglineObject.ReadLine(logPosSql);
                loglineObjectSql = LoglineObject.CreateLoglineObject(lineSql, logPosSql);

                while (loglineObjectSql.Threadname == threadName &&
                       loglineObjectSql.Classname != "org.hibernate.SQL" &&
                       (loglineObject.Classname == "org.hibernate.type.descriptor.sql.BasicBinder" ||
                        (loglineObject.Classname == "org.hibernate.type.EnumType")) && index + pos > 0)
                {
                    pos--;
                    hibernateSqlDic.Add(pos, loglineObjectSql);
                    logPosSql        = streamingFactory.PositionList[index + pos];
                    lineSql          = LoglineObject.ReadLine(logPosSql);
                    loglineObjectSql = LoglineObject.CreateLoglineObject(lineSql, logPosSql);
                }

                if (loglineObjectSql.Classname == "org.hibernate.SQL")
                {
                    pos--;
                    hibernateSqlDic.Add(pos, loglineObjectSql);
                }
            }

            pos = 1;
            if (index + pos < streamingFactory.PositionList.Count)
            {
                logPosSql        = streamingFactory.PositionList[index + pos];
                lineSql          = LoglineObject.ReadLine(logPosSql);
                loglineObjectSql = LoglineObject.CreateLoglineObject(lineSql, logPosSql);

                while ((loglineObjectSql.Classname == "org.hibernate.type.descriptor.sql.BasicBinder" ||
                        loglineObjectSql.Classname == "org.hibernate.type.EnumType") &&
                       loglineObjectSql.Threadname == threadName &&
                       index + pos < streamingFactory.PositionList.Count)
                {
                    pos++;
                    hibernateSqlDic.Add(pos, loglineObjectSql);
                    if (index + pos < streamingFactory.PositionList.Count)
                    {
                        logPosSql        = streamingFactory.PositionList[index + pos];
                        lineSql          = LoglineObject.ReadLine(logPosSql);
                        loglineObjectSql = LoglineObject.CreateLoglineObject(lineSql, logPosSql);
                    }
                }
            }

            StringBuilder sqlFull = new StringBuilder();
            LoglineObject?sqlLine = hibernateSqlDic.Values.FirstOrDefault(x => x.Classname == "org.hibernate.SQL");

            if (sqlLine != null && !String.IsNullOrWhiteSpace(sqlLine.Value.Message))
            {
                var basicBinders = hibernateSqlDic.Values.Where(x =>
                                                                (x.Classname == "org.hibernate.type.descriptor.sql.BasicBinder" || x.Classname == "org.hibernate.type.EnumType") && x.Message.ToLower().StartsWith("binding"));
                List <HqlParameter> parameters = basicBinders.Select(x => new HqlParameter(x)).Where(x => x.ParameterPos > 0).ToList();
                String[]            parts      = sqlLine.Value.Message.Split('?');
                for (int i = 0; i < parts.Length; i++)
                {
                    sqlFull.Append(parts[i].Replace(", ", ",\r\n\t").Replace(" set ", " set\r\n\t").Replace(" (", "\r\n\t("));
                    if (i < parts.Length - 1)
                    {
                        HqlParameter hlq = parameters.FirstOrDefault(x => x.ParameterPos == i + 1);
                        if (hlq == null)
                        {
                            sqlFull.Append("?");
                        }
                        else
                        {
                            sqlFull.Append(hlq.Sql);
                        }
                    }
                }
            }

            if (sqlFull.Length > 0)
            {
                messageResult = sqlFull.ToString();
            }
            else
            {
                messageResult = String.Join(Environment.NewLine, hibernateSqlDic.OrderBy(x => x.Key).Select(x => x.Value.Message));
            }

            return(messageResult.Replace(") values (", "\r\n) values (")
                   .Replace(" where ", " \r\n    where ")
                   .Replace(" from ", " \r\n    from "));
        }
Ejemplo n.º 8
0
        private static bool MatchSearch(LogPos logPos, SearchEventArgs e)
        {
            bool   addLine = true;
            String line    = LoglineObject.ReadLine(logPos);

            if (line == null)
            {
                return(false);
            }

            addLine &= SearchText(e, addLine, line);

            if (e.LogSource != null && logPos.LogSource != e.LogSource)
            {
                addLine &= false;
            }

            if (e.SearchDuration)
            {
                int posMs2 = line.LastIndexOf(" ms");
                if (posMs2 > 0)
                {
                    int    posMs1 = line.LastIndexOf(" ", posMs2 - 1);
                    String ms     = line.Substring(posMs1 + 1, posMs2 - posMs1 - 1);
                    int    val;
                    if (Int32.TryParse(ms, out val))
                    {
                        if (!(val >= e.DurationFrom && (val <= e.DurationTo || e.DurationTo == 0)))
                        {
                            addLine &= false;
                        }
                    }
                    else
                    {
                        addLine &= false;
                    }
                }
                else
                {
                    addLine &= false;
                }
            }

            if (e.OnlyLinesWithStackTrace)
            {
                if (logPos.Childs == null)
                {
                    addLine &= false;
                }
            }

            if (!e.LevelTrace || !e.LevelDebug || !e.LevelInfo || !e.LevelWarn || !e.LevelError || !e.LevelFatal)
            {
                if (line.Length > 29)
                {
                    String level = line.Substring(24, 5);
                    switch (level)
                    {
                    case "TRACE":
                        if (!e.LevelTrace)
                        {
                            addLine &= false;
                        }
                        break;

                    case "DEBUG":
                        if (!e.LevelDebug)
                        {
                            addLine &= false;
                        }
                        break;

                    case "INFO ":
                        if (!e.LevelInfo)
                        {
                            addLine &= false;
                        }
                        break;

                    case "WARN ":
                        if (!e.LevelWarn)
                        {
                            addLine &= false;
                        }
                        break;

                    case "ERROR":
                        if (!e.LevelError)
                        {
                            addLine &= false;
                        }
                        break;

                    case "FATAL":
                        if (!e.LevelFatal)
                        {
                            addLine &= false;
                        }
                        break;

                    default:
                        addLine &= false;
                        break;
                    }
                }
                else
                {
                    addLine &= false;
                }
            }

            return(addLine);
        }
Ejemplo n.º 9
0
        public static string Info(StreamingFactory streamingFactory, int index, LoglineObject loglineObject)
        {
            String        message = loglineObject.Message;
            String        SqlClass;
            String        Statement;
            String        Entity;
            string        Exception;
            int?          MilliSeconds;
            List <String> Parameter = new List <string>();

            int index1 = message.IndexOf(" ");
            int index2 = message.IndexOf("parameters: {");

            if (index2 == -1)
            {
                index2 = message.IndexOf(" ms", index1);
            }

            index2 = index2 >= 0 ? index2 : 0;

            int index3 = message.IndexOf(" ms", index2);

            if (index3 < 0)
            {
                index3 = message.IndexOf(" throws exception: ", index2);
                if (index3 > 0)
                {
                    Exception = message.Substring(index3 + 1, message.Length - index3 - 1);
                    if (index2 > 0)
                    {
                        Parameter = message.Substring(index2 + 13, index3 - index2 - 14).Split(',').Select(x => x.Trim()).ToList();
                    }
                    else
                    {
                        index2 = index3;
                    }
                }
                else
                {
                    Exception = "Maximale Länge der Logzeile überschritten";
                }
            }
            else
            {
                string[] parts = message.Substring(index3 - 10, 10).Split(' ');
                string   ms    = parts[parts.Length - 1];
                MilliSeconds = Int32.Parse(ms);

                if (index2 != index3)
                {
                    string param = message.Substring(index2 + 13, index3 - index2 - 15 - ms.Length);
                    if (param.Length != 0)
                    {
                        Parameter = param.Split(',').Select(x => x.Trim()).ToList();
                    }
                    else
                    {
                        Parameter = new List <string>();
                    }
                }
                else
                {
                    Parameter = new List <string>();
                    index2   -= ms.Length;
                }
            }

            SqlClass = message.Substring(0, index1);

            if (index2 == 0)
            {
                Statement = message.Substring(index1 + 1);
            }
            else
            {
                Statement = message.Substring(index1 + 1, index2 - index1 - 2);

                int indexEntity     = Statement.ToLower().IndexOf(" from ");
                int indexEntityStop = Statement.IndexOf(" ", indexEntity + 6);
                indexEntityStop = indexEntityStop < 0 ? Statement.Length : indexEntityStop;
                if (indexEntity > -1 && indexEntity < indexEntityStop)
                {
                    Entity = "[select] " + Statement.Substring(indexEntity + 6, indexEntityStop - indexEntity - 6).ToLower();

                    while (Statement.ToLower().IndexOf(" from ", indexEntityStop) >= 0)
                    {
                        indexEntity     = Statement.ToLower().IndexOf(" from ", indexEntityStop);
                        indexEntityStop = Statement.IndexOf(" ", indexEntity + 6);

                        Entity += ", " + Statement.Substring(indexEntity + 6, indexEntityStop - indexEntity - 6).ToLower();
                    }
                }
                else
                {
                    indexEntity     = Statement.ToLower().IndexOf("insert into ");
                    indexEntityStop = Statement.IndexOf(" ", indexEntity + 13);
                    if (indexEntity > -1 && indexEntity < indexEntityStop)
                    {
                        Entity = "[insert] " + Statement.Substring(indexEntity + 12, indexEntityStop - indexEntity - 12).ToLower();
                    }
                    else
                    {
                        indexEntity     = Statement.ToLower().IndexOf("update ");
                        indexEntityStop = Statement.IndexOf(" ", indexEntity + 7);
                        if (indexEntity > -1 && indexEntity < indexEntityStop)
                        {
                            Entity = "[update] " + Statement.Substring(indexEntity + 7, indexEntityStop - indexEntity - 7).ToLower();
                        }
                        else
                        {
                            Entity = "unknown entity";
                        }
                    }
                }
            }

            int    statementCnt   = Statement.ToCharArray().Where(x => x == '?').Count();
            string paramStatement = Statement;

            for (int i = 0; i < statementCnt; i++)
            {
                int j = i + (Parameter.Count - statementCnt);
                if (regexDate.IsMatch(Parameter[j]))
                {
                    paramStatement = regexParam.Replace(paramStatement, "'" + Parameter[j] + "'", 1);
                }
                else
                {
                    paramStatement = regexParam.Replace(paramStatement, Parameter[j], 1);
                }
            }
            return(paramStatement.Replace(") values (", ") \r\n    values (")
                   .Replace(" where ", " \r\n    where ")
                   .Replace(" from ", " \r\n    from "));
        }