void OnGUI() { GUILayout.BeginHorizontal(); // Enable pre-filter if process is not started GUI.enabled = logCatProcess == null; prefilterOnlyUnity = GUILayout.Toggle(prefilterOnlyUnity, "Only Unity", "Button", GUILayout.Width(80)); // Enable button if process is not started GUI.enabled = logCatProcess == null; if (GUILayout.Button("Start", GUILayout.Width(60))) { string adbPath = GetAdbPath(); // Start `adb logcat -c` to clear the log buffer ProcessStartInfo clearProcessInfo = new ProcessStartInfo(); clearProcessInfo.WindowStyle = ProcessWindowStyle.Hidden; clearProcessInfo.CreateNoWindow = true; clearProcessInfo.UseShellExecute = false; clearProcessInfo.FileName = adbPath; clearProcessInfo.Arguments = @"logcat -c"; Process.Start(clearProcessInfo); // Start `adb logcat` (with additional optional arguments) process for filtering ProcessStartInfo logProcessInfo = new ProcessStartInfo(); logProcessInfo.CreateNoWindow = true; logProcessInfo.UseShellExecute = false; logProcessInfo.RedirectStandardOutput = true; logProcessInfo.RedirectStandardError = true; logProcessInfo.StandardOutputEncoding = Encoding.UTF8; logProcessInfo.FileName = adbPath; logProcessInfo.WindowStyle = ProcessWindowStyle.Hidden; // Add additional -s argument for filtering by Unity tag. logProcessInfo.Arguments = "logcat -v time" + (prefilterOnlyUnity ? " -s \"Unity\"": ""); logCatProcess = Process.Start(logProcessInfo); logCatProcess.ErrorDataReceived += (sender, errorLine) => { if (errorLine.Data != null && errorLine.Data.Length > 2) { AddLog(new LogCatLog(errorLine.Data)); } }; logCatProcess.OutputDataReceived += (sender, outputLine) => { if (outputLine.Data != null && outputLine.Data.Length > 2) { AddLog(new LogCatLog(outputLine.Data)); } }; logCatProcess.BeginErrorReadLine(); logCatProcess.BeginOutputReadLine(); } // Disable button if process is already started GUI.enabled = logCatProcess != null; if (GUILayout.Button("Stop", GUILayout.Width(60))) { StopLogCatProcess(); } GUI.enabled = true; if (GUILayout.Button("Clear", GUILayout.Width(60))) { lock (logsList) { logsList.Clear(); filteredList.Clear(); } } GUILayout.Label(filteredList.Count + " matching logs", GUILayout.Height(20)); // Create filters filterByString = GUILayout.TextField(filterByString, GUILayout.Height(20)); GUI.color = new Color(0.75f, 0.5f, 0.5f, 1f); filterOnlyError = GUILayout.Toggle(filterOnlyError, "Error", "Button", GUILayout.Width(80)); GUI.color = new Color(0.95f, 0.95f, 0.3f, 1f); filterOnlyWarning = GUILayout.Toggle(filterOnlyWarning, "Warning", "Button", GUILayout.Width(80)); GUI.color = new Color(0.5f, 0.5f, 0.75f, 1f); filterOnlyDebug = GUILayout.Toggle(filterOnlyDebug, "Debug", "Button", GUILayout.Width(80)); GUI.color = new Color(0.5f, 0.75f, 0.5f, 1f); filterOnlyInfo = GUILayout.Toggle(filterOnlyInfo, "Info", "Button", GUILayout.Width(80)); GUI.color = Color.white; filterOnlyVerbose = GUILayout.Toggle(filterOnlyVerbose, "Verbose", "Button", GUILayout.Width(80)); GUILayout.EndHorizontal(); GUIStyle lineStyle = new GUIStyle(); lineStyle.normal.background = MakeTexture(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f)); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(Screen.height - 45)); // Show only top `showingLimit` log entries int fromIndex = filteredList.Count - showLimit; if (fromIndex < 0) { fromIndex = 0; } for (int i = fromIndex; i < filteredList.Count; i++) { LogCatLog log = filteredList[i]; GUI.backgroundColor = log.GetBgColor(); GUILayout.BeginHorizontal(lineStyle); GUILayout.Label(log.CreationDate + " | " + log.Message); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }
void OnGUI() { GUILayout.BeginHorizontal(); GUI.enabled = logCatProcess == null; prefilterOnlyUnity = GUILayout.Toggle(prefilterOnlyUnity, "Unity Logs Only", "Button", GUILayout.Width(110f)); GUI.enabled = true; GUI.color = Color.white; if (logCatProcess != null && GUILayout.Button("Stop", GUILayout.Width(55f))) { StopLogCat(); } else if (logCatProcess == null && GUILayout.Button("Start", GUILayout.Width(55f))) { StartLogCat(); } GUI.enabled = true; if (GUILayout.Button("Clear", GUILayout.Width(55f))) { ClearLogCat(); } // Create filters filterByString = GUILayout.TextField(filterByString, GUILayout.Height(20f)); GUI.color = color_error; filterError = GUILayout.Toggle(filterError, "Error", "Button", GUILayout.Width(60f)); GUI.color = color_warning; filterWarning = GUILayout.Toggle(filterWarning, "Warning", "Button", GUILayout.Width(60f)); GUI.color = color_debug; filterDebug = GUILayout.Toggle(filterDebug, "Debug", "Button", GUILayout.Width(60f)); GUI.color = color_info; filterInfo = GUILayout.Toggle(filterInfo, "Info", "Button", GUILayout.Width(60f)); GUI.color = Color.white; filterVerbose = GUILayout.Toggle(filterVerbose, "Verbose", "Button", GUILayout.Width(60f)); GUILayout.EndHorizontal(); GUIStyle lineStyle = new GUIStyle(); lineStyle.normal.background = MakeTexture(600, 1, color_background); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(Screen.height - 45)); // Show log entries bool shouldFilterByString = filterByString.Length > 1; for (int index = oldestLogIndex, i = 0; i < count; i++) { LogCatLog log = logsList[index]; // Filter if ((!shouldFilterByString || log.Message.ToLower().Contains(filterByString.ToLower())) && (filterError && log.Type == 'E' || filterWarning && log.Type == 'W' || filterDebug && log.Type == 'D' || filterInfo && log.Type == 'I' || filterVerbose && log.Type == 'V')) { GUI.backgroundColor = log.GetBgColor(); GUILayout.BeginHorizontal(lineStyle); GUILayout.Label(log.Message); GUILayout.EndHorizontal(); } index = (index + 1) % CAPACITY; } GUILayout.EndScrollView(); }