public MainForm() { InitializeComponent(); selectedLogListControl = logListControlMain; this.Size = new Size(1600, 800); streamingFactory = new StreamingFactory(); selectedLogListControl.SetStreamingFactory(streamingFactory, null); streamingFactory.IsInconsistent += StreamingFactory_IsInConsistent; currentMainForm = this; workerIndex = new BackgroundWorker(); workerIndex.WorkerReportsProgress = true; workerIndex.WorkerSupportsCancellation = true; workerIndex.ProgressChanged += WorkerIndex_ProgressChanged; workerIndex.DoWork += WorkerIndex_DoWork; workerIndex.RunWorkerCompleted += WorkerIndex_RunWorkerCompleted; workerSearch = new BackgroundWorker(); workerSearch.WorkerReportsProgress = true; workerSearch.WorkerSupportsCancellation = true; workerSearch.ProgressChanged += WorkerSearch_ProgressChanged; workerSearch.DoWork += WorkerSearch_DoWork; workerSearch.RunWorkerCompleted += WorkerSearch_RunWorkerCompleted; timerNewLogFilesAdded = new System.Windows.Forms.Timer(); timerNewLogFilesAdded.Interval = 500; timerNewLogFilesAdded.Enabled = false; timerNewLogFilesAdded.Tick += TimerNewLogFilesAdded_Tick; }
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)); }
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 ")); }
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 ")); }