private void JumpToSource( BluLog log, int row) { var file = ""; var line = -1; var frames = log.StackTrace; if (frames.Count == 0) { file = log.File; line = log.Line; } else if (row < frames.Count) { file = frames[row].File; line = frames[row].Line; } if (string.IsNullOrEmpty(file) || line == -1) { return; } var filename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), file); if (System.IO.File.Exists(filename)) { UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(file, line); } }
public static BluLog GetBluLog( object obj) { var log = new BluLog(); var logEntryType = LogEntryType; var condition = (string)GetField("condition", logEntryType).GetValue(obj); log.SetMessage(condition); log.SetStackTrace(condition); var file = (string)GetField("file", logEntryType).GetValue(obj); log.SetFile(file); var line = (int)GetField("line", logEntryType).GetValue(obj); log.SetLine(line); var mode = (int)GetField("mode", logEntryType).GetValue(obj); log.SetMode(mode); var instanceID = (int)GetField("instanceID", logEntryType).GetValue(obj); log.SetInstanceID(instanceID); return(log); }
private List <BluDetailWindowCell> GetCells(BluLog log) { var cells = new List <BluDetailWindowCell>(1 + log.StackTrace.Count); cells.Add(new BluDetailWindowCell( message: log.Message, selectedMessageWhenClicked: 0, stackTraceIndex: 0, messageStyle: BluConsoleSkin.MessageDetailCallstackStyle, backgroundStyle: BluConsoleSkin.GetLogBackStyle(1) )); for (int i = 0; i < log.StackTrace.Count; i++) { cells.Add(new BluDetailWindowCell( message: log.StackTrace[i].FrameInformation, selectedMessageWhenClicked: i + 1, stackTraceIndex: i, messageStyle: BluConsoleSkin.MessageDetailCallstackStyle, backgroundStyle: BluConsoleSkin.GetLogBackStyle(1) )); } return(cells); }
public static void PingLog(BluLog log) { if (log.InstanceID != 0) { EditorGUIUtility.PingObject(log.InstanceID); } }
private bool ShouldLog(BluLog log, int row) { var messageLower = log.MessageLower; if (_toolbarWindow.SearchStringPatterns != null && _toolbarWindow.SearchStringPatterns.Any(pattern => !messageLower.Contains(pattern))) { CacheLogComparer(row, false); return(false); } var hasPattern = true; for (var i = 0; i < _settings.Filters.Count; i++) { if (!_toolbarWindow.ToggledFilters[i]) { continue; } if (!_settings.Filters[i].Patterns.Any(pattern => messageLower.Contains(pattern))) { hasPattern = false; break; } } CacheLogComparer(row, hasPattern); return(hasPattern); }
private static BluLogType GetLogType(BluLog log) { if (HasMode(log.Mode, (ConsoleWindowMode)GetLogMask(BluLogType.Error))) { return(BluLogType.Error); } if (HasMode(log.Mode, (ConsoleWindowMode)GetLogMask(BluLogType.Warning))) { return(BluLogType.Warning); } return(BluLogType.Normal); }
public static BluLog GetSimpleLog(int row) { var mode = 0; var message = ""; GetFirstTwoLinesEntryTextAndModeInternal(row, ref mode, ref message); BluLog log = new BluLog(); log.SetMessage(message); log.SetMode(mode); return(log); }
private void PreProcessLogs() { _qtLogs = UnityLoggerServer.StartGettingLogs(); _cacheLogCount = _qtLogs; // Filtering logs with ugly code int cntLogs = 0; int[] rows = GetCachedIntArr(_qtLogs); BluLog[] logs = GetCachedLogsArr(_qtLogs); int index = 0; int cacheLogComparerCount = _cacheLogComparer.Count; for (int i = 0; i < _qtLogs; i++) { // Ugly code to avoid function call int realCount = _cacheLog.Count; BluLog log = null; if (i < _cacheLogCount && i < realCount) { log = _cacheLog[i]; } else { log = GetSimpleLog(i); } // Ugly code to avoid function call bool has = false; if (i < cacheLogComparerCount) { has = _cacheLogComparer[i]; } else { has = ShouldLog(log, i); } if (has) { cntLogs++; rows[index] = i; logs[index++] = log; } } _qtLogs = cntLogs; UnityLoggerServer.StopGettingsLogs(); }
private void DrawPopup( Event clickEvent, BluLog log) { GenericMenu.MenuFunction copyCallback = () => { EditorGUIUtility.systemCopyBuffer = log.Message; }; GenericMenu menu = new GenericMenu(); menu.AddItem(content: new GUIContent("Copy"), on: false, func: copyCallback); menu.ShowAsContext(); clickEvent.Use(); }
private bool HasPattern( BluLog log, int row) { if (row < _cacheLogComparer.Count) { return(_cacheLogComparer[row]); } string messageLower = log.MessageLower; int size = _searchStringPatterns.Length; for (int i = 0; i < size; i++) { string pattern = _searchStringPatterns[i]; if (pattern == "") { continue; } if (!messageLower.Contains(pattern)) { CacheLogComparer(row, false); return(false); } } for (int i = 0; i < _settings.Filters.Count; i++) { if (!_additionalFilters[i]) { continue; } foreach (var pattern in _settings.Filters[i].Patterns) { if (!messageLower.Contains(pattern)) { CacheLogComparer(row, false); return(false); } } } CacheLogComparer(row, true); return(true); }
protected override void OnEnterKeyPressed() { BluLog log = null; if (SelectedMessage != -1 && SelectedMessage >= 0 && SelectedMessage < QtLogs) { log = GetCompleteLog(Rows[SelectedMessage]); } if (log != null) { BluUtils.JumpToSourceFile(log, 0); } }
private GUIStyle GetLogListStyle( BluLog log) { BluLogType logType = GetLogType(log); switch (logType) { case BluLogType.Normal: return(BluConsoleSkin.LogInfoStyle); case BluLogType.Warning: return(BluConsoleSkin.LogWarnStyle); case BluLogType.Error: return(BluConsoleSkin.LogErrorStyle); } return(BluConsoleSkin.LogInfoStyle); }
private BluLogType GetLogType( BluLog log) { int mode = log.Mode; if (UnityLoggerServer.HasMode(mode, (ConsoleWindowMode)GetLogMask(BluLogType.Error))) { return(BluLogType.Error); } else if (UnityLoggerServer.HasMode(mode, (ConsoleWindowMode)GetLogMask(BluLogType.Warning))) { return(BluLogType.Warning); } else { return(BluLogType.Normal); } }
public static void JumpToSourceFile(BluLog log, int row) { var file = ""; var line = -1; if (log.StackTrace.Count == 0) { file = log.File; line = log.Line; } else if (row < log.StackTrace.Count) { file = log.StackTrace[row].File; line = log.StackTrace[row].Line; } if (string.IsNullOrEmpty(file) || line == -1) { return; } BluUtils.OpenFileOnEditor(file, line); }
private void DrawLogList() { _qtLogs = UnityLoggerServer.StartGettingLogs(); _cacheLogCount = _qtLogs; int cntLogs = 0; List <int> rows = new List <int>(_qtLogs); List <BluLog> logs = new List <BluLog>(_qtLogs); for (int i = 0; i < _qtLogs; i++) { var log = GetSimpleLog(i); if (HasPattern(log, i)) { cntLogs++; rows.Add(i); logs.Add(log); } } _qtLogs = cntLogs; float windowWidth = WindowWidth; float windowHeight = _topPanelHeight - DrawYPos; float buttonWidth = ButtonWidth; if (_qtLogs * ButtonHeight > windowHeight) { buttonWidth -= 15f; } float viewWidth = buttonWidth; float viewHeight = _qtLogs * ButtonHeight; Rect scrollViewPosition = new Rect(x: 0f, y: DrawYPos, width: windowWidth, height: windowHeight); Rect scrollViewViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight); GUI.DrawTexture(scrollViewPosition, BluConsoleSkin.EvenBackTexture); Vector2 oldScrollPosition = _logListScrollPosition; _logListScrollPosition = GUI.BeginScrollView(position: scrollViewPosition, scrollPosition: _logListScrollPosition, viewRect: scrollViewViewRect); int firstRenderLogIndex = (int)(_logListScrollPosition.y / ButtonHeight); firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, _qtLogs); int lastRenderLogIndex = firstRenderLogIndex + (int)(windowHeight / ButtonHeight) + 2; lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, _qtLogs); float buttonY = firstRenderLogIndex * ButtonHeight; bool hasSomeClick = false; int cnt = 0; for (int i = firstRenderLogIndex; i < lastRenderLogIndex; i++) { var row = rows[i]; var log = logs[i]; var styleBack = GetLogBackStyle(i); var styleMessage = GetLogListStyle(log); string showMessage = GetTruncatedMessage(GetLogListMessage(log)); var contentMessage = new GUIContent(showMessage); var rectMessage = new Rect(x: 0, y: buttonY, width: viewWidth, height: ButtonHeight); bool isSelected = i == _logListSelectedMessage ? true : false; DrawBack(rectMessage, styleBack, isSelected); if (IsRepaintEvent) { styleMessage.Draw(rectMessage, contentMessage, false, false, isSelected, false); } bool messageClicked = IsClicked(rectMessage); bool isLeftClick = messageClicked ? Event.current.button == 0 : false; if (UnityLoggerServer.HasFlag(ConsoleWindowFlag.Collapse)) { int quantity = UnityLoggerServer.GetLogCount(row); var collapseCount = Mathf.Min(quantity, MAX_LENGTH_COLLAPSE); var collapseText = collapseCount.ToString(); if (collapseCount >= MAX_LENGTH_COLLAPSE) { collapseText += "+"; } var collapseContent = new GUIContent(collapseText); var collapseSize = BluConsoleSkin.CollapseStyle.CalcSize(collapseContent); var collapseRect = new Rect(x: viewWidth - collapseSize.x - 5f, y: (buttonY + buttonY + ButtonHeight - collapseSize.y) * 0.5f, width: collapseSize.x, height: collapseSize.y); GUI.Label(collapseRect, collapseContent, BluConsoleSkin.CollapseStyle); } if (messageClicked) { _selectedLog = GetCompleteLog(row); hasSomeClick = true; if (!isLeftClick && i == _logListSelectedMessage) { DrawPopup(Event.current, log); } if (isLeftClick && i == _logListSelectedMessage) { if (IsDoubleClickLogListButton) { _logListLastTimeClicked = 0.0f; var completeLog = GetCompleteLog(row); JumpToSource(completeLog, 0); } else { PingLog(_selectedLog); _logListLastTimeClicked = EditorApplication.timeSinceStartup; } } else { PingLog(_selectedLog); _logListSelectedMessage = i; } _logDetailSelectedFrame = -1; } buttonY += ButtonHeight; cnt++; } UnityLoggerServer.StopGettingsLogs(); GUI.EndScrollView(); if (_hasScrollWheelUp || hasSomeClick) { _isFollowScroll = false; } else if (_logListScrollPosition != oldScrollPosition) { _isFollowScroll = false; float topOffset = viewHeight - windowHeight; if (_logListScrollPosition.y >= topOffset) { _isFollowScroll = true; } } if (!IsFollowScroll) { return; } float endY = viewHeight - windowHeight; _logListScrollPosition.y = endY; }
public override void OnGUI(int id) { base.OnGUI(id); UnityLoggerServer.StartGettingLogs(); SelectedMessage = Mathf.Clamp(SelectedMessage, -1, QtLogs - 1); float buttonWidth = DefaultButtonWidth; if (QtLogs * DefaultButtonHeight > WindowRect.height) { buttonWidth -= 15f; } float viewWidth = buttonWidth; float viewHeight = QtLogs * DefaultButtonHeight; Rect scrollWindowRect = WindowRect; Rect scrollViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight); GUI.DrawTexture(scrollWindowRect, BluConsoleSkin.EvenBackTexture); Vector2 oldScrollPosition = ScrollPosition; ScrollPosition = GUI.BeginScrollView(position: scrollWindowRect, scrollPosition: ScrollPosition, viewRect: scrollViewRect); GUI.DrawTexture(WindowRect, BluConsoleSkin.OddBackTexture); int firstRenderLogIndex = (int)(ScrollPosition.y / DefaultButtonHeight); firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, QtLogs); int lastRenderLogIndex = firstRenderLogIndex + (int)(WindowRect.height / DefaultButtonHeight) + 2; lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, QtLogs); // Handling up/down arrow keys if (HasKeyboardArrowKeyInput) { bool isFrameOutsideOfRange = SelectedMessage <firstRenderLogIndex + 1 || SelectedMessage> lastRenderLogIndex - 3; if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Up) { ScrollPosition.y = DefaultButtonHeight * SelectedMessage; } else if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Down) { int md = lastRenderLogIndex - firstRenderLogIndex - 3; float ss = md * DefaultButtonHeight; float sd = WindowRect.height - ss; ScrollPosition.y = (DefaultButtonHeight * (SelectedMessage + 1) - ss - sd); } } float buttonY = firstRenderLogIndex * DefaultButtonHeight; bool hasCollapse = UnityLoggerServer.HasFlag(ConsoleWindowFlag.Collapse); bool hasSomeClick = false; for (int i = firstRenderLogIndex; i < lastRenderLogIndex; i++) { int row = Rows[i]; BluLog log = Logs[i]; var styleBack = BluConsoleSkin.GetLogBackStyle(i); var styleMessage = BluConsoleSkin.GetLogListStyle(log.LogType); string showMessage = GetTruncatedListMessage(log); var contentMessage = new GUIContent(showMessage); var rectMessage = new Rect(x: 0, y: buttonY, width: viewWidth, height: DefaultButtonHeight); bool isSelected = i == SelectedMessage; DrawBackground(rectMessage, styleBack, isSelected); if (IsRepaintEvent) { styleMessage.Draw(rectMessage, contentMessage, false, false, isSelected, false); } bool messageClicked = IsClicked(rectMessage); bool isLeftClick = messageClicked && Event.current.button == 0; if (hasCollapse) { int quantity = UnityLoggerServer.GetLogCount(row); var collapseCount = Mathf.Min(quantity, LogConfiguration.MaxAmountOfLogsCollapse); var collapseText = collapseCount.ToString(); if (collapseCount >= LogConfiguration.MaxAmountOfLogsCollapse) { collapseText += "+"; } var collapseContent = new GUIContent(collapseText); var collapseSize = BluConsoleSkin.CollapseStyle.CalcSize(collapseContent); var collapseRect = new Rect(x: viewWidth - collapseSize.x - 5f, y: (buttonY + buttonY + DefaultButtonHeight - collapseSize.y) * 0.5f, width: collapseSize.x, height: collapseSize.y); GUI.Label(collapseRect, collapseContent, BluConsoleSkin.CollapseStyle); } if (messageClicked) { hasSomeClick = true; if (SelectedMessage != i) { LastTimeClicked = 0.0f; } if (isLeftClick) { BluUtils.PingLog(GetCompleteLog(row)); SelectedMessage = i; } if (!isLeftClick) { DrawPopup(log); } if (isLeftClick && i == SelectedMessage) { if (IsDoubleClick) { LastTimeClicked = 0.0f; var completeLog = GetCompleteLog(row); BluUtils.JumpToSourceFile(completeLog, 0); } else { LastTimeClicked = EditorApplication.timeSinceStartup; } } } buttonY += DefaultButtonHeight; } GUI.EndScrollView(); if (IsScrollUp || hasSomeClick) { IsFollowScroll = false; } else if (ScrollPosition != oldScrollPosition) { IsFollowScroll = false; float topOffset = viewHeight - WindowRect.height; if (ScrollPosition.y >= topOffset) { IsFollowScroll = true; } } if (IsFollowScroll) { ScrollPosition.y = viewHeight - WindowRect.height; } UnityLoggerServer.StopGettingsLogs(); }
public override void OnGUI(int id) { base.OnGUI(id); UnityLoggerServer.StartGettingLogs(); GUI.DrawTexture(WindowRect, BluConsoleSkin.OddBackTexture); if (ListWindowSelectedMessage != -1 && ListWindowSelectedMessage >= 0 && ListWindowSelectedMessage < QtLogs) { _selectedLog = GetCompleteLog(Rows[ListWindowSelectedMessage]); } if (_selectedLog != null) { SelectedMessage = Mathf.Clamp(SelectedMessage, 0, _selectedLog.StackTrace.Count); } else { SelectedMessage = -1; } if (ListWindowSelectedMessage == -1 || QtLogs == 0 || ListWindowSelectedMessage >= QtLogs || _selectedLog == null || _selectedLog.StackTrace == null) { UnityLoggerServer.StopGettingsLogs(); return; } float buttonWidth = DefaultButtonWidth; var cells = GetCells(_selectedLog); foreach (var cell in cells) { cell.Message = GetTruncatedDetailMessage(cell.Message); } sums = new float[cells.Count + 1]; sums[0] = 0; for (int i = 1; i <= cells.Count; i++) { sums[i] = cells[i - 1].GetHeight(buttonWidth) + sums[i - 1]; } float viewHeight = sums[cells.Count]; if (viewHeight > WindowRect.height) { buttonWidth -= 15f; } for (int i = 1; i <= cells.Count; i++) { sums[i] = cells[i - 1].GetHeight(buttonWidth) + sums[i - 1]; } viewHeight = sums[cells.Count]; float viewWidth = buttonWidth; Rect scrollViewPosition = WindowRect; Rect scrollViewViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight); ScrollPosition = GUI.BeginScrollView(position: scrollViewPosition, scrollPosition: ScrollPosition, viewRect: scrollViewViewRect); int firstRenderLogIndex = GetFirstGreaterCellIndex(cells, ScrollPosition.y, 0f) - 1; firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, cells.Count - 1); int lastRenderLogIndex = GetFirstGreaterCellIndex(cells, ScrollPosition.y, WindowRect.height); lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, cells.Count - 1); float buttonY = sums[firstRenderLogIndex]; // Handling up/down arrow keys if (HasKeyboardArrowKeyInput) { float lo = ScrollPosition.y; float hi = ScrollPosition.y + WindowRect.height; float selectedMessageLo = sums[SelectedMessage]; float selectedMessageHi = sums[SelectedMessage + 1]; bool isFrameOutsideOfRange = !(selectedMessageLo >= lo && selectedMessageHi <= hi); if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Up) { ScrollPosition.y = selectedMessageLo; } else if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Down) { ScrollPosition.y = selectedMessageHi - WindowRect.height; } } for (int i = firstRenderLogIndex; i <= lastRenderLogIndex; i++) { float cellHeight = sums[i + 1] - sums[i]; var rectButton = new Rect(x: 0, y: buttonY, width: viewWidth, height: cellHeight); var isSelected = cells[i].SelectedMessageWhenClicked == SelectedMessage; DrawBackground(rectButton, cells[i].BackgroundStyle, isSelected); if (IsRepaintEvent) { cells[i].MessageStyle.Draw(rectButton, cells[i].Message, false, false, isSelected, false); } bool messageClicked = IsClicked(rectButton); if (messageClicked) { bool isLeftClick = Event.current.button == 0; if (!isSelected) { LastTimeClicked = 0.0f; } if (isLeftClick && !IsDoubleClick) { SelectedMessage = cells[i].SelectedMessageWhenClicked; } if (!isLeftClick) { DrawPopup(cells[i].Message); } if (isLeftClick && SelectedMessage == cells[i].SelectedMessageWhenClicked) { if (IsDoubleClick) { LastTimeClicked = 0.0f; BluUtils.JumpToSourceFile(_selectedLog, cells[i].StackTraceIndex); } else { LastTimeClicked = EditorApplication.timeSinceStartup; } } } buttonY += cellHeight; } GUI.EndScrollView(); UnityLoggerServer.StopGettingsLogs(); }
protected void DrawPopup(BluLog log) { DrawPopup(log.Message); }
private string GetLogListMessage( BluLog log) { return(log.Message.Replace(System.Environment.NewLine, " ")); }
protected string GetTruncatedListMessage(BluLog log) { return(GetTruncatedListMessage(log.Message)); }