Example #1
0
        public void Log(string txt, string stack = null, LogType type = LogType.Log, Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            switch (type)
            {
            case LogType.Log:
                Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt);
                break;

            case LogType.Warning:
                Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt);
                break;

            case LogType.Exception:
            case LogType.Error:
                Console.SystemLog(stack != null ? txt.FastConcat(stack).FastConcat(" ", dataString) : txt);
                break;
            }
        }
Example #2
0
        public void Log(string txt, LogType type = LogType.Log, Exception e = null, Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            string stack = null;

            if (e != null)
            {
                stack = e.StackTrace;
            }

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            switch (type)
            {
            case LogType.Log:
                SystemLog(txt);
                break;

            case LogType.Warning:
                SystemLog(txt);
                break;

            case LogType.Error:
            case LogType.Exception:
                SystemLog(txt.FastConcat("</color> ", Environment.NewLine, stack)
                          .FastConcat(Environment.NewLine, dataString));
                break;
            }
        }
        public void Log(string txt, string stack = null, LogType type = LogType.Log, Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            switch (type)
            {
            case LogType.Log:
                UnityEngine.Debug.Log(txt);
                break;

            case LogType.Warning:
                UnityEngine.Debug.LogWarning(txt);
                break;

            case LogType.Exception:
            case LogType.Error:
                UnityEngine.Debug.LogError(stack != null ?
                                           "<color=cyan> ".FastConcat(txt, "</color> ", stack) :
                                           "<color=cyan> ".FastConcat(txt, "</color> ", dataString));
                break;
            }
        }
Example #4
0
        public void Log(string txt, LogType type         = LogType.Log, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            string stack = null;

            if (e != null)
            {
                stack = ExtractFormattedStackTrace(new StackTrace(e, true));
            }

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            switch (type)
            {
            case LogType.Log:
                Debug.Log(txt);
                break;

            case LogType.Warning:
                Debug.LogWarning(txt);
                break;

            case LogType.Exception:
            case LogType.Error:
                Debug.LogError("<color=cyan> ".FastConcat(txt, "</color> ", Environment.NewLine, stack).FastConcat(Environment.NewLine, dataString));
                break;
            }
        }
Example #5
0
        public void Log(string txt, LogType type         = LogType.Log, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            string stack;

            switch (type)
            {
            case LogType.Log:
            {
#if !(!UNITY_EDITOR || PROFILER)
                stack = ExtractFormattedStackTrace();

                Debug.Log("<b><color=teal>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                          .FastConcat(Environment.NewLine, dataString));
#else
                Debug.Log(txt);
#endif
                break;
            }

            case LogType.Warning:
            {
#if !(!UNITY_EDITOR || PROFILER)
                stack = ExtractFormattedStackTrace();

                Debug.LogWarning("<b><color=teal>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                                 .FastConcat(Environment.NewLine, dataString));
#else
                Debug.LogWarning(txt);
#endif
                break;
            }

            case LogType.Error:
            case LogType.Exception:
            {
                if (e != null)
                {
                    txt   = txt.FastConcat(e.Message);
                    stack = ExtractFormattedStackTrace(new StackTrace(e, true));
                }
                else
                {
                    stack = ExtractFormattedStackTrace();
                }

                Debug.LogError("<b><color=red> ".FastConcat(txt, "</color><b> ", Environment.NewLine, stack)
                               .FastConcat(Environment.NewLine, dataString));
                break;
            }
            }
        }
Example #6
0
        public void Log(string txt, LogType type         = LogType.Log, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            string stack;

#if UNITY_EDITOR
            string frame = $"thread: {Environment.CurrentManagedThreadId}";
            try
            {
                if (MAINTHREADID == Environment.CurrentManagedThreadId)
                {
                    frame += $" frame: {Time.frameCount}";
                }
            }
            catch
            {
                //there is something wrong with  Environment.CurrentManagedThreadId
            }
#endif

            switch (type)
            {
            case LogType.Log:
            {
#if UNITY_EDITOR
                stack = ExtractFormattedStackTrace();

                Debug.Log($"{frame} <b><color=teal>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                          .FastConcat(Environment.NewLine, dataString));
#else
                Debug.Log(txt);
#endif
                break;
            }

            case LogType.LogDebug:
            {
#if UNITY_EDITOR
                stack = ExtractFormattedStackTrace();

                Debug.Log($"{frame} <b><color=orange>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                          .FastConcat(Environment.NewLine, dataString));
#else
                Debug.Log(txt);
#endif
                break;
            }

            case LogType.Warning:
            {
#if UNITY_EDITOR
                stack = ExtractFormattedStackTrace();

                Debug.LogWarning($"{frame} <b><color=yellow>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                                 .FastConcat(Environment.NewLine, dataString));
#else
                Debug.LogWarning(txt);
#endif
                break;
            }

            case LogType.Error:
            case LogType.Exception:
            {
                if (e != null)
                {
                    txt   = txt.FastConcat(e.Message);
                    stack = ExtractFormattedStackTrace(new StackTrace(e, true));
                }
                else
                {
                    stack = ExtractFormattedStackTrace();
                }

#if UNITY_EDITOR
                var fastConcat = $"{frame} <b><color=red>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                                 .FastConcat(Environment.NewLine, dataString);

                if (MAINTHREADID == Environment.CurrentManagedThreadId)
                {
                    var error = Application.GetStackTraceLogType(UnityEngine.LogType.Error);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Error, StackTraceLogType.None);
                    Debug.LogError(fastConcat);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Error, error);
                }
                else
                {
                    Debug.LogError(txt);
                }
#else
                if (type == LogType.Error)
                {
                    Debug.LogError(txt);
                }
                else
                if (e != null)
                {
                    Debug.LogException(e);
                }
#endif
                break;
            }
            }
        }
Example #7
0
        public void Log(string txt, LogType type         = LogType.Log, bool showLogStack = true, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            var frame = $"[{DateTime.UtcNow.ToString("HH:mm:ss.fff")}] thread: {Environment.CurrentManagedThreadId}";

            try
            {
                if (MAINTHREADID == Environment.CurrentManagedThreadId)
                {
                    frame += $" frame: {Time.frameCount}";
                }
            }
            catch
            {
                //there is something wrong with  Environment.CurrentManagedThreadId
            }

            StackTrace stack = null;

#if UNITY_EDITOR
            stack = new StackTrace(3, true);
#else
            if (type == LogType.Error || type == LogType.Exception)
            {
                stack = new StackTrace(3, true);
            }
#endif

            if (Volatile.Read(ref Console.batchLog) == true)
            {
                var stackString = stack == null ? string.Empty : stack.GetFrame(0).ToString();
                var strArray    = Encoding.UTF8.GetBytes(txt.FastConcat(stackString));
                var logHash     = Murmur3.MurmurHash3_x86_32(strArray, SEED);

                if (_batchedErrorLogs.ContainsKey(logHash))
                {
                    _batchedErrorLogs[logHash] = new ErrorLogObject(_batchedErrorLogs[logHash]);
                }
                else
                {
#if !UNITY_EDITOR
                    if (type == LogType.Error)
                    {
                        stack = new StackTrace(3, true);
                    }
#endif

                    _batchedErrorLogs[logHash] =
                        new ErrorLogObject(txt, stack, type, e, frame, showLogStack, dataString);
                }
            }
            else
            {
#if !UNITY_EDITOR
                if (type == LogType.Error)
                {
                    stack = new StackTrace(3, true);
                }
#endif

                _notBatchedQueue.Enqueue(new ErrorLogObject(txt, stack, type, e, frame, showLogStack, dataString,
                                                            0));
            }
        }
Example #8
0
        public void Log(string txt, LogType type         = LogType.Log, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            string stack;

            switch (type)
            {
            case LogType.Log:
            {
#if UNITY_EDITOR
                stack = ExtractFormattedStackTrace();

                Debug.Log("<b><color=teal>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                          .FastConcat(Environment.NewLine, dataString));
#else
                Debug.Log(txt);
#endif
                break;
            }

            case LogType.Warning:
            {
#if UNITY_EDITOR
                stack = ExtractFormattedStackTrace();

                Debug.LogWarning("<b><color=yellow>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                                 .FastConcat(Environment.NewLine, dataString));
#else
                Debug.LogWarning(txt);
#endif
                break;
            }

            case LogType.Error:
            case LogType.Exception:
            {
                if (e != null)
                {
                    txt   = txt.FastConcat(e.Message);
                    stack = ExtractFormattedStackTrace(new StackTrace(e, true));
                }
                else
                {
                    stack = ExtractFormattedStackTrace();
                }

#if UNITY_EDITOR
                var fastConcat = "<b><color=red>".FastConcat(txt, "</color></b> ", Environment.NewLine, stack)
                                 .FastConcat(Environment.NewLine, dataString);

                var error = Application.GetStackTraceLogType(UnityEngine.LogType.Error);
                Application.SetStackTraceLogType(UnityEngine.LogType.Error, StackTraceLogType.None);
                Debug.LogError(fastConcat);
                Application.SetStackTraceLogType(UnityEngine.LogType.Error, error);
#else
                if (type == LogType.Error)
                {
                    Debug.LogError(txt);
                }
                else
                if (e != null)
                {
                    Debug.LogException(e);
                }
#endif
                break;
            }
            }
        }
        public void Log(string txt, LogType type         = LogType.Log, bool showLogStack = true, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            var currentManagedThreadId = Environment.CurrentManagedThreadId;
            var frame = $"[{DateTime.UtcNow.ToString("HH:mm:ss.fff")}] thread: {Environment.CurrentManagedThreadId}";

            try
            {
                if (MAINTHREADID == currentManagedThreadId)
                {
                    frame += $" frame: {Time.frameCount}";
                }
            }
            catch
            {
                //there is something wrong with  Environment.CurrentManagedThreadId
            }
#if UNITY_EDITOR
            var stackTrace = new StackTrace(3, true);
#else
            StackTrace stackTrace = null;

            if (type == LogType.Error || type == LogType.Exception)
            {
                stackTrace = new StackTrace(3, true);
            }
#endif

            switch (type)
            {
            case LogType.Log:
            {
                if (MAINTHREADID == currentManagedThreadId)
                {
                    //SetStacktrace can be called only in the editor and it's enable for LOG only in the editor
                    var log = Application.GetStackTraceLogType(UnityEngine.LogType.Log);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Log, StackTraceLogType.None);

                    Debug.Log(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));

                    Application.SetStackTraceLogType(UnityEngine.LogType.Log, log);
                }
                else
                {
                    Debug.Log(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));
                }
                break;
            }

            case LogType.LogDebug:
            {
#if UNITY_EDITOR
                if (MAINTHREADID == currentManagedThreadId)
                {
                    //SetStacktrace can be called only in the editor and it's enable for LOG only in the editor
                    var log = Application.GetStackTraceLogType(UnityEngine.LogType.Log);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Log, StackTraceLogType.None);

                    Debug.Log(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));

                    Application.SetStackTraceLogType(UnityEngine.LogType.Log, log);
                }
                else
                {
                    Debug.Log(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));
                }
#endif
                break;
            }

            case LogType.Warning:
            {
                if (MAINTHREADID == currentManagedThreadId)
                {
                    //SetStacktrace can be called only in the editor and it's enable for LOG only in the editor
                    var log = Application.GetStackTraceLogType(UnityEngine.LogType.Log);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Warning, StackTraceLogType.None);

                    Debug.LogWarning(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));

                    Application.SetStackTraceLogType(UnityEngine.LogType.Warning, log);
                }
                else
                {
                    Debug.LogWarning(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));
                }
                break;
            }

            case LogType.Error:
            case LogType.Exception:
            {
                if (MAINTHREADID == currentManagedThreadId)
                {
                    //SetStacktrace can be called only in the editor and it's enable for LOG only in the editor
                    var log = Application.GetStackTraceLogType(UnityEngine.LogType.Log);
                    Application.SetStackTraceLogType(UnityEngine.LogType.Error, StackTraceLogType.None);

                    UnityEngine.Debug.LogError(LogFormatter(txt, type, showLogStack, e, frame, dataString, stackTrace));

                    Application.SetStackTraceLogType(UnityEngine.LogType.Error, log);
                }
                else
                {
                    Debug.LogError($"{frame} <b><color=teal>".FastConcat(txt, "</color></b> ", Environment.NewLine)
                                   .FastConcat(dataString));
                }
                break;
            }
            }
        }