Beispiel #1
0
        public static string ReadLine(LogPos logPos)
        {
            if (logPos == null)
            {
                return($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} FATAL [log4jDigger] log4jDigger - Unvalid Request for Loline");
            }

            if (logPos.StreamingHost.IsDisposed)
            {
                return($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} FATAL [log4jDigger] log4jDigger - Stream is disposed");
            }

            try
            {
                logPos.StreamingHost.Reader.SetPosition(logPos.Pos);
                String line = logPos.StreamingHost.Reader.ReadLine();

                if (line == null)
                {
                    return($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} FATAL [log4jDigger] log4jDigger - Inconsistent Logdata, please refresh (F5)");
                }
                else
                {
                    return(line);
                }
            }
            catch (Exception ex)
            {
                return($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} FATAL [log4jDigger] log4jDigger - Error resolving Logline from Stream: " + ex.Message);
            }
        }
Beispiel #2
0
 public void SetLastMaxPosition(LogPos logPos)
 {
     LastMaxLogPosition = logPos;
     LastMaxPosition    = Reader.GetPosition();
     lastFileLength     = new FileInfo(Filename).Length;
     LastMaxLine        = LoglineObject.ReadLine(logPos);
     IsDisposed         = false;
 }
Beispiel #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);
        }
Beispiel #4
0
        private void AddToPositionList(LogPos logPos)
        {
            PositionList.Add(logPos);

            //Suchergebnisse aktualisieren
            if (searchResults.Count > 0)
            {
                foreach (KeyValuePair <SearchEventArgs, List <LogPos> > kv in searchResults)
                {
                    if (MatchSearch(logPos, kv.Key))
                    {
                        kv.Value.Add(logPos);
                    }

                    if (kv.Key.OnlyLinesWithStackTrace && logPos.Parent != null && kv.Value[kv.Value.Count - 1] != logPos.Parent &&
                        kv.Value[kv.Value.Count - 1] != logPos)
                    {
                        kv.Value.Add(logPos.Parent);
                    }
                }
            }
        }
Beispiel #5
0
        private void LogListControlMain_DoubleClickListView(object sender, ListViewControlEventArgs e)
        {
            LogListControl llc = sender as LogListControl;

            Follow = false;

            if (e.SearchEventArgs != null)
            {
                LogPos lp = llc.SelectedLogPos;
                if (lp != null)
                {
                    JumpToLine((int)lp.Order);
                }
            }

            if (e.Bookmark)
            {
                TabPage oldPage      = tabPageInfo;
                TabPage selectedPage = AddInfoTabPage(llc.SelectedIndex);

                if (oldPage != tabPageInfo && oldPage != null)
                {
                    oldPage.Text = $"Bookmark {llc.SelectedIndex:n0}";
                    LoglineInfoControl llic = (LoglineInfoControl)oldPage.Controls[0];
                    llic.SelectedLine          = llc.SelectedIndex;
                    llic.DoubleClickTextBox   += InfoControl_DoubleClickTextBox;
                    tabControlMain.SelectedTab = oldPage;
                }
                else
                {
                    tabControlMain.SelectedTab = selectedPage;
                }
            }
            else
            {
                tabControlMain.SelectedTab = tabPageInfo;
            }
        }
Beispiel #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));
        }
Beispiel #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 "));
        }
Beispiel #8
0
        private long ScanFile(BackgroundWorker worker, int progess, StreamingHost sh)
        {
            int newPositions = PositionList.Count;

            isBusy = true;

            try
            {
                LogSource source = new LogSource()
                {
                    Filename = sh.Filename
                };
                String line;
                int    lastRelPos = 0;
                sh.Reader.SetPosition(sh.LastMaxPosition);
                long position = sh.Reader.GetPosition();

                LogPos lastMainLog = sh.LastMaxLogPosition;
                while ((line = sh.Reader.ReadLine()) != null)
                {
                    if (worker != null && (worker.CancellationPending || isDisposing))
                    {
                        break;
                    }

                    DateTime date;
                    if (line.Length >= 23 && Char.IsDigit(line[0]) && DateTime.TryParseExact(line.Substring(0, 23), "yyyy-MM-dd HH:mm:ss,fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                    {
                        lastMainLog = new LogPos()
                        {
                            TimeStamp = date, Pos = position, Order = PositionList.Count(), LoglineType = LoglineType.MAIN_LOG, StreamingHost = sh, LogSource = source
                        };
                        AddToPositionList(lastMainLog);
                    }
                    else if (!String.IsNullOrWhiteSpace(line))
                    {
                        if (line.StartsWith("#"))
                        {
                            String[] parts = line.Split('#');

                            if (parts.Length == 10)
                            {
                                int index = parts[6].IndexOf(" - ");
                                if (index > 0)
                                {
                                    source = new LogSource()
                                    {
                                        Filename = parts[6].Substring(10, index - 10), Servername = parts[3].Trim()
                                    };
                                }
                            }
                        }
                        else if (CheckCatalinaLine(line, out date))
                        {
                            lastMainLog = new LogPos()
                            {
                                TimeStamp = date, Pos = position, Order = PositionList.Count(), LoglineType = LoglineType.CATALINA_LOG, StreamingHost = sh, LogSource = source
                            };
                            AddToPositionList(lastMainLog);
                        }
                        else if (lastMainLog != null)
                        {
                            LogPos childLogPos = new LogPos()
                            {
                                TimeStamp     = PositionList[PositionList.Count - 1].TimeStamp,
                                Pos           = position,
                                Order         = PositionList.Count(),
                                LoglineType   = LoglineType.CHILD_LINE,
                                StreamingHost = sh,
                                LogSource     = source,
                                Parent        = lastMainLog
                            };

                            if (lastMainLog != null)
                            {
                                if (lastMainLog.Childs == null)
                                {
                                    lastMainLog.Childs = new List <LogPos>();
                                }

                                lastMainLog.Childs.Add(childLogPos);
                            }

                            AddToPositionList(childLogPos);
                        }
                    }

                    position = sh.Reader.GetPosition();
                    int relPos = (int)(100.0 * (double)position / (double)sh.Stream.Length);

                    if (lastRelPos != relPos)
                    {
                        lastRelPos = relPos;
                        if (worker != null)
                        {
                            worker.ReportProgress(progess + lastRelPos);
                        }
                    }
                }
                sh.SetLastMaxPosition(lastMainLog);
                System.Diagnostics.Debug.WriteLine($"{sh.Filename}; last position  {sh.LastMaxPosition:n0}; new lines {PositionList.Count - newPositions:n0};");
                isBusy = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("ScanFile: " + ex.Message);
            }
            return(PositionList.Count - newPositions);
        }
Beispiel #9
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);
        }