Пример #1
0
        static bool GetCallstack(ref List <LogStackFrame> callstack)
        {
            callstack.Clear();
            StackTrace stackTrace = new StackTrace(true);       // get call stack

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

            foreach (StackFrame stackFrame in stackFrames)
            {
                var method = stackFrame.GetMethod();
                if (method.IsDefined(typeof(LogUnityOnly), true))
                {
                    return(true);
                }
                if (!method.IsDefined(typeof(StackTraceIgnore), true))
                {
                    //Cut out some internal noise from Unity stuff
                    if (!(method.Name == "CallLogCallback" && method.DeclaringType.Name == "Application") &&
                        !(method.DeclaringType.Name == "Debug" && (method.Name == "Internal_Log" || method.Name == "Log")))
                    {
                        var logStackFrame = new LogStackFrame(stackFrame);

                        callstack.Add(logStackFrame);
                    }
                }
            }

            return(false);
        }
Пример #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;

            // Iterate backwards over stackframes; this enables us to show the "first" ignored Unity method if need be, but hide subsequent ones
            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)
                    {
                        // "show if first ignored" methods are part of the stack trace only if no other ignored methods have been encountered already
                        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
        /// <summary>
        /// Converts a Unity callstack string into a list of UberLogger's LogStackFrame
        /// Doesn't do any filtering, since this should only be dealing with internal Unity errors rather than client code
        /// </summary>
        static List <LogStackFrame> GetCallstackFromUnityLog(string unityCallstack, out LogStackFrame originatingSourceLocation)
        {
            var lines = System.Text.RegularExpressions.Regex.Split(unityCallstack, UberLogger.Logger.UnityInternalNewLine);

            var stack = new List <LogStackFrame>();

            foreach (var line in lines)
            {
                var frame = new LogStackFrame(line);
                if (!string.IsNullOrEmpty(frame.GetFormattedMethodNameWithFileName()))
                {
                    stack.Add(new LogStackFrame(line));
                }
            }

            if (stack.Count > 0)
            {
                originatingSourceLocation = stack[0];
            }
            else
            {
                originatingSourceLocation = null;
            }

            return(stack);
        }
Пример #4
0
        public LogInfo(UnityEngine.Object source, string channel, LogSeverity severity, List <LogStackFrame> callstack, LogStackFrame originatingSourceLocation, object message, params object[] par)
        {
            Source   = source;
            Channel  = channel;
            Severity = severity;
            Message  = "";
            OriginatingSourceLocation = originatingSourceLocation;

            var messageString = message as String;

            if (messageString != null)
            {
                if (par.Length > 0)
                {
                    Message = System.String.Format(messageString, par);
                }
                else
                {
                    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);
        }
Пример #5
0
        static bool GetCallstack(ref List <LogStackFrame> callstack, out LogStackFrame originatingSourceLocation)
        {
            callstack.Clear();
            StackTrace stackTrace = new StackTrace(true);

            StackFrame[] stackFrames = stackTrace.GetFrames();

            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.Reverse();

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Converts a Unity callstack string into a list of UberLogger's LogStackFrame
        /// Doesn't do any filtering, since this should only be dealing with internal Unity errors rather than client code
        /// </summary>
        static List <LogStackFrame> GetCallstackFromUnityLog(string unityCallstack)
        {
            var lines = System.Text.RegularExpressions.Regex.Split(unityCallstack, System.Environment.NewLine);
            var stack = new List <LogStackFrame>();

            foreach (var line in lines)
            {
                var frame = new LogStackFrame(line);
                if (!string.IsNullOrEmpty(frame.GetFormattedMethodName()))
                {
                    stack.Add(new LogStackFrame(line));
                }
            }
            return(stack);
        }
Пример #7
0
        private static bool GetCallstack(ref List <LogStackFrame> callstack, out LogStackFrame originatingSourceLocation)
        {
            callstack.Clear();
            StackFrame[] frames = new StackTrace(true).GetFrames();
            bool         flag   = false;

            originatingSourceLocation = null;
            for (int i = frames.Length - 1; i >= 0; i--)
            {
                StackFrame stackFrame = frames[i];
                MethodBase method     = stackFrame.GetMethod();
                if (method.IsDefined(typeof(LogUnityOnly), true))
                {
                    return(true);
                }
                if (!method.IsDefined(typeof(StackTraceIgnore), true))
                {
                    UberLogger.Logger.IgnoredUnityMethod.Mode mode = UberLogger.Logger.ShowOrHideMethod(method);
                    bool flag2 = mode == UberLogger.Logger.IgnoredUnityMethod.Mode.Show;
                    if (mode == UberLogger.Logger.IgnoredUnityMethod.Mode.ShowIfFirstIgnoredMethod)
                    {
                        if (!flag)
                        {
                            flag = true;
                            mode = UberLogger.Logger.IgnoredUnityMethod.Mode.Show;
                        }
                        else
                        {
                            mode = UberLogger.Logger.IgnoredUnityMethod.Mode.Hide;
                        }
                    }
                    if (mode == UberLogger.Logger.IgnoredUnityMethod.Mode.Show)
                    {
                        LogStackFrame logStackFrame = new LogStackFrame(stackFrame);
                        callstack.Add(logStackFrame);
                        if (flag2)
                        {
                            originatingSourceLocation = logStackFrame;
                        }
                    }
                }
            }
            callstack.Reverse();
            return(false);
        }
Пример #8
0
        static List <LogStackFrame> GetCallstackFromLuaLog(string unityCallstack, out LogStackFrame originatingSourceLocation)
        {
            var lines = System.Text.RegularExpressions.Regex.Split(unityCallstack, UberLogger.Logger.UnityInternalNewLine);

            // lua trace
            var stack   = new List <LogStackFrame>();
            var luaRoot = "Assets/BundleRes/";

            foreach (var line in lines)
            {
                /*
                 * "[debug] LUA: test traceback OpenTest
                 * stack traceback:
                 *  [string "ui/login/login"]:34: in field 'OpenTest'
                 *  [string "ui/login/login"]:81: in function <[string "ui/login/login"]:80>
                 */
                var match = LuaTraceRegex.Match(line);
                if (match.Groups.Count > 1)
                {
                    var filename   = luaRoot + match.Groups[1].Value + ".lua";
                    var lineNumber = Convert.ToInt32(match.Groups[2].Value);
                    var frame      = new LogStackFrame(line, filename, lineNumber);
                    stack.Add(frame);
                }
            }

            if (stack.Count > 0)
            {
                originatingSourceLocation = stack[0];
                stack.Insert(0, new LogStackFrame("lua traceback:"));
            }
            else
            {
                originatingSourceLocation = null;
            }

            return(stack);
        }
Пример #9
0
        public LogInfo(UnityEngine.Object source, string channel, LogSeverity severity, List <LogStackFrame> callstack, LogStackFrame originatingSourceLocation, object message, params object[] par)
        {
            this.Source   = source;
            this.Channel  = channel;
            this.Severity = severity;
            this.Message  = "";
            this.OriginatingSourceLocation = originatingSourceLocation;
            string text = message as string;

            if (text != null)
            {
                if (par.Length != 0)
                {
                    this.Message = string.Format(text, par);
                }
                else
                {
                    this.Message = text;
                }
            }
            else if (message != null)
            {
                this.Message = message.ToString();
            }
            this.Callstack                 = callstack;
            this.RelativeTimeStamp         = UberLogger.Logger.GetRelativeTime();
            this.AbsoluteTimeStamp         = DateTime.UtcNow;
            this.RelativeTimeStampAsString = string.Format("{0:0.0000}", this.RelativeTimeStamp);
            this.AbsoluteTimeStampAsString = this.AbsoluteTimeStamp.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
        }
Пример #10
0
        private static List <LogStackFrame> GetCallstackFromUnityLog(string unityCallstack, out LogStackFrame originatingSourceLocation)
        {
            string[]             array = Regex.Split(unityCallstack, UberLogger.Logger.UnityInternalNewLine);
            List <LogStackFrame> list  = new List <LogStackFrame>();

            foreach (string unityStackFrame in array)
            {
                if (!string.IsNullOrEmpty(new LogStackFrame(unityStackFrame).GetFormattedMethodNameWithFileName()))
                {
                    list.Add(new LogStackFrame(unityStackFrame));
                }
            }
            if (list.Count > 0)
            {
                originatingSourceLocation = list[0];
            }
            else
            {
                originatingSourceLocation = null;
            }
            return(list);
        }