public void SaveLoggingData() { LoggingContainer container = this.GetCurrentContainer(); var list = container.GetLoggingList(); string filename = string.Format("log-{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now); string location = EditorUtility.SaveFilePanel("Save", lastSaveDir, filename, "txt"); if (string.IsNullOrEmpty(location)) { return; } FileInfo file = new FileInfo(location); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } this.lastSaveDir = dir.FullName; StringBuilder buf = new StringBuilder(); foreach (LoggingEntry entry in list) { foreach (LoggingData data in entry.LoggingDatas) { buf.AppendFormat("{0:yyyy-MM-dd HH:mm:ss.fff}", data.TimeStamp); buf.AppendFormat(" Thread[{0}]", data.ThreadName); buf.AppendFormat(" {0}", data.Level.ToString()); buf.AppendFormat(" {0}", data.LoggerName); buf.AppendFormat(" - {0}", data.Message); buf.Append("\r\n"); if (data.LocationInfo != null && data.LocationInfo.StackFrames != null) { foreach (var frame in data.LocationInfo.StackFrames) { buf.Append(frame.FullInfo.Replace(Directory.GetCurrentDirectory().ToString() + @"\", "")).Append("\r\n"); } } buf.Append("\r\n"); } } File.WriteAllText(location, buf.ToString()); }
void DrawLoggingGrid(LoggingContainer container) { var areaRect = new Rect(0f, toolbarHeight, position.width, position.height * this.verticalSplitterPercent - toolbarHeight - splitterRectHeight / 2f); List <LoggingEntry> list = container.GetLoggingList(); this.renderedList.Clear(); this.renderedLineCountList.Clear(); foreach (LoggingEntry logging in list) { if (!ShouldShow(logging)) { continue; } if (consoleVM.Collapse) { renderedList.Add(logging.LoggingData); renderedLineCountList.Add(logging.Count); } else { renderedList.AddRange(logging.LoggingDatas); } } int count = renderedList.Count; var viewRect = new Rect(0, 0, areaRect.width - 20, count * lineHeight); if (viewRect.height >= areaRect.height && this.loggingVerticalScrollBarPercent > 0.95f) { loggingPanelScrollPosition.y = viewRect.height - areaRect.height; } loggingPanelScrollPosition = GUI.BeginScrollView(areaRect, loggingPanelScrollPosition, viewRect); if (viewRect.height >= areaRect.height) { this.loggingVerticalScrollBarPercent = loggingPanelScrollPosition.y / (viewRect.height - areaRect.height); } int firstIndex = (int)(loggingPanelScrollPosition.y / lineHeight); int lastIndex = firstIndex + (int)(areaRect.height / lineHeight); firstIndex = Mathf.Clamp(firstIndex - 5, 0, count); lastIndex = Mathf.Clamp(lastIndex + 5, 0, count); if (this.selectedIndex >= count) { this.selectedIndex = -1; } for (int i = firstIndex; i < lastIndex; i++) { LoggingData data = renderedList[i]; var content = this.GetLogLineGUIContent(data); var lineStyle = (i % 2 == 0) ? entryStyleBackEven : entryStyleBackOdd; bool selected = i == selectedIndex; lineStyle.normal = selected ? GUI.skin.GetStyle(lineStyle.name).onNormal : GUI.skin.GetStyle(lineStyle.name).normal; if (GUI.Button(new Rect(0f, i * lineHeight, viewRect.width, lineHeight), content, lineStyle)) { if (selected) { if (EditorApplication.timeSinceStartup - lastClickTime < doubleClickInterval) { lastClickTime = 0; OpenSourceFile(data.LocationInfo); } else { lastClickTime = EditorApplication.timeSinceStartup; } } else { this.selectedIndex = i; lastClickTime = EditorApplication.timeSinceStartup; } } if (consoleVM.Collapse) { int logCount = renderedLineCountList[i]; GUIContent countContent = new GUIContent(logCount < 100 ? logCount.ToString() : "99+"); var size = countBadgeStyle.CalcSize(countContent); size.x = Mathf.Clamp(size.x + 5, 20, 30); size.y = Mathf.Clamp(size.y, 20, lineHeight); GUI.Label(new Rect(viewRect.width - 15f - size.x / 2f, i * lineHeight + (lineHeight - size.y) / 2f, size.x, size.y), countContent, countBadgeStyle); } } GUI.EndScrollView(); }