示例#1
0
        public LogInfo(UnityEngine.Object source, string channel, LogSeverity severity, List <LogStackFrame> callstack, LogStackFrame originatingSourceLocation, object message)
        {
            Source   = source;
            Channel  = channel;
            Severity = severity;
            Message  = "";
            OriginatingSourceLocation = originatingSourceLocation;

            var messageString = message as String;

            if (messageString != null)
            {
                Message = messageString;
            }
            else
            {
                if (message != null)
                {
                    Message = message.ToString();
                }
            }

            Callstack                 = callstack;
            RelativeTimeStamp         = Logger.GetRelativeTime();
            AbsoluteTimeStamp         = DateTime.UtcNow;
            RelativeTimeStampAsString = String.Format("{0:0.0000}", RelativeTimeStamp);
            AbsoluteTimeStampAsString = AbsoluteTimeStamp.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);
        }
示例#2
0
        static bool GetCallstack(ref List <LogStackFrame> callstack, out LogStackFrame originatingSourceLocation)
        {
            callstack.Clear();
            StackTrace stackTrace = new StackTrace(true);                   // get call stack

            StackFrame[] stackFrames = stackTrace.GetFrames();              // get method calls (frames)

            bool encounteredIgnoredMethodPreviously = false;

            originatingSourceLocation = null;

            for (int i = stackFrames.Length - 1; i >= 0; i--)
            {
                StackFrame stackFrame = stackFrames[i];

                var method = stackFrame.GetMethod();
                if (method.IsDefined(typeof(LogUnityOnly), true))
                {
                    return(true);
                }
                if (!method.IsDefined(typeof(StackTraceIgnore), true))
                {
                    IgnoredUnityMethod.Mode showHideMode = ShowOrHideMethod(method);

                    bool setOriginatingSourceLocation = (showHideMode == IgnoredUnityMethod.Mode.Show);

                    if (showHideMode == IgnoredUnityMethod.Mode.ShowIfFirstIgnoredMethod)
                    {
                        if (!encounteredIgnoredMethodPreviously)
                        {
                            encounteredIgnoredMethodPreviously = true;
                            showHideMode = IgnoredUnityMethod.Mode.Show;
                        }
                        else
                        {
                            showHideMode = IgnoredUnityMethod.Mode.Hide;
                        }
                    }

                    if (showHideMode == IgnoredUnityMethod.Mode.Show)
                    {
                        var logStackFrame = new LogStackFrame(stackFrame);

                        callstack.Add(logStackFrame);

                        if (setOriginatingSourceLocation)
                        {
                            originatingSourceLocation = logStackFrame;
                        }
                    }
                }
            }

            // Callstack has been processed backwards -- correct order for presentation
            callstack.Reverse();

            return(false);
        }
示例#3
0
        GUIContent GetFrameSourceGUIContent(LogStackFrame frame)
        {
            var source = GetSourceForFrame(frame);

            if (!String.IsNullOrEmpty(source))
            {
                var content = new GUIContent(source);
                return(content);
            }
            return(null);
        }
示例#4
0
        string GetSourceForFrame(LogStackFrame frame)
        {
            if (SourceLinesFrame == frame)
            {
                return(SourceLines);
            }


            if (frame.FileName == null)
            {
                return("");
            }

            var osFileName = MaxyGames.uNodeLogger.Logger.ConvertDirectorySeparatorsFromUnityToOS(frame.FileName);
            var filename   = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), osFileName);

            if (!System.IO.File.Exists(filename))
            {
                return("");
            }

            int lineNumber  = frame.LineNumber - 1;
            int linesAround = 3;
            var lines       = System.IO.File.ReadAllLines(filename);
            var firstLine   = Mathf.Max(lineNumber - linesAround, 0);
            var lastLine    = Mathf.Min(lineNumber + linesAround + 1, lines.Count());

            SourceLines = "";
            if (firstLine != 0)
            {
                SourceLines += "...\n";
            }
            for (int c1 = firstLine; c1 < lastLine; c1++)
            {
                string str = lines[c1] + "\n";
                if (c1 == lineNumber)
                {
                    str = "<color=#ff0000ff>" + str + "</color>";
                }
                SourceLines += str;
            }
            if (lastLine != lines.Count())
            {
                SourceLines += "...\n";
            }

            SourceLinesFrame = frame;
            return(SourceLines);
        }
示例#5
0
        bool JumpToSource(LogStackFrame frame)
        {
            if (frame.FileName != null)
            {
                var osFileName = MaxyGames.uNodeLogger.Logger.ConvertDirectorySeparatorsFromUnityToOS(frame.FileName);
                var filename   = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), osFileName);
                if (System.IO.File.Exists(filename))
                {
                    if (UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(filename, frame.LineNumber))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#6
0
 void ToggleShowSource(LogStackFrame frame)
 {
     ShowFrameSource = !ShowFrameSource;
 }
示例#7
0
        public void DrawLogDetails()
        {
            var oldColor = GUI.backgroundColor;

            SelectedRenderLog = Mathf.Clamp(SelectedRenderLog, 0, CurrentLogList.Count);

            if (RenderLogs.Count > 0 && SelectedRenderLog >= 0)
            {
                var countedLog   = RenderLogs[SelectedRenderLog];
                var log          = countedLog.Log;
                var logLineStyle = EntryStyleBackEven;

                var sourceStyle = new GUIStyle(GUI.skin.textArea);
                sourceStyle.richText = true;

                var drawRect = new Rect(DrawPos, new Vector2(position.width - DrawPos.x, position.height - DrawPos.y));

                //Work out the content we need to show, and the sizes
                var   detailLines   = new List <GUIContent>();
                float contentHeight = 0;
                float contentWidth  = 0;
                float lineHeight    = 0;
                int   messageLength = 0;
                var   message       = log.Message.Split('\n');
                for (int i = 1; i < message.Length; i++)
                {
                    var content = new GUIContent(message[i]);
                    detailLines.Add(content);

                    var contentSize = logLineStyle.CalcSize(content);
                    contentHeight += contentSize.y;
                    lineHeight     = Mathf.Max(lineHeight, contentSize.y);
                    contentWidth   = Mathf.Max(contentSize.x, contentWidth);
                    messageLength++;
                }

                for (int c1 = 0; c1 < log.Callstack.Count; c1++)
                {
                    var frame      = log.Callstack[c1];
                    var methodName = frame.GetFormattedMethodNameWithFileName();
                    if (!String.IsNullOrEmpty(methodName))
                    {
                        var content = new GUIContent(methodName);
                        detailLines.Add(content);

                        var contentSize = logLineStyle.CalcSize(content);
                        contentHeight += contentSize.y;
                        lineHeight     = Mathf.Max(lineHeight, contentSize.y);
                        contentWidth   = Mathf.Max(contentSize.x, contentWidth);
                        if (ShowFrameSource && c1 + messageLength == SelectedCallstackFrame)
                        {
                            var sourceContent = GetFrameSourceGUIContent(frame);
                            if (sourceContent != null)
                            {
                                var sourceSize = sourceStyle.CalcSize(sourceContent);
                                contentHeight += sourceSize.y;
                                contentWidth   = Mathf.Max(sourceSize.x, contentWidth);
                            }
                        }
                    }
                }

                //Render the content
                var contentRect = new Rect(0, 0, Mathf.Max(contentWidth, drawRect.width), contentHeight);

                LogDetailsScrollPosition = GUI.BeginScrollView(drawRect, LogDetailsScrollPosition, contentRect);

                float lineY = 0;
                for (int c1 = 0; c1 < detailLines.Count; c1++)
                {
                    var lineContent = detailLines[c1];
                    if (lineContent != null)
                    {
                        logLineStyle = (c1 % 2 == 0) ? EntryStyleBackEven : EntryStyleBackOdd;
                        if (c1 == SelectedCallstackFrame)
                        {
                            GUI.backgroundColor = new Color(0.5f, 0.5f, 1);
                        }
                        else
                        {
                            GUI.backgroundColor = Color.white;
                        }
                        var           lineRect = new Rect(0, lineY, contentRect.width, lineHeight);
                        LogStackFrame frame    = null;
                        if (messageLength <= c1)
                        {
                            frame = log.Callstack[c1 - messageLength];

                            // Handle clicks on the stack frame
                            if (GUI.Button(lineRect, lineContent, logLineStyle))
                            {
                                if (c1 == SelectedCallstackFrame)
                                {
                                    if (Event.current.button == 1)
                                    {
                                        ToggleShowSource(frame);
                                        Repaint();
                                    }
                                    else
                                    {
                                        if (EditorApplication.timeSinceStartup - LastFrameClickTime < DoubleClickInterval)
                                        {
                                            LastFrameClickTime = 0;
                                            JumpToSource(frame);
                                        }
                                        else
                                        {
                                            LastFrameClickTime = EditorApplication.timeSinceStartup;
                                        }
                                    }
                                }
                                else
                                {
                                    SelectedCallstackFrame = c1;
                                    LastFrameClickTime     = EditorApplication.timeSinceStartup;
                                }
                            }
                        }
                        else
                        {
                            if (GUI.Button(lineRect, lineContent, logLineStyle))
                            {
                                SelectedCallstackFrame = c1;
                                LastFrameClickTime     = EditorApplication.timeSinceStartup;
                            }
                        }
                        lineY += lineHeight;
                        //Show the source code if needed
                        if (ShowFrameSource && c1 == SelectedCallstackFrame)
                        {
                            GUI.backgroundColor = Color.white;

                            if (frame != null)
                            {
                                var sourceContent = GetFrameSourceGUIContent(frame);
                                if (sourceContent != null)
                                {
                                    var sourceSize = sourceStyle.CalcSize(sourceContent);
                                    var sourceRect = new Rect(0, lineY, contentRect.width, sourceSize.y);

                                    GUI.Label(sourceRect, sourceContent, sourceStyle);
                                    lineY += sourceSize.y;
                                }
                            }
                        }
                    }
                }
                GUI.EndScrollView();
            }
            GUI.backgroundColor = oldColor;
        }