示例#1
0
        static Logs()
        {
            AppDomain.CurrentDomain.ProcessExit  += AppDomain_ProcessExit;
            AppDomain.CurrentDomain.DomainUnload += AppDomain_DomainUnload;
            AppDomain.CurrentDomain.AssemblyLoad += AppDomain_AssemblyLoad;

            // Normally, we'd use this hook to log all exceptions that end up uncaught, but
            // in testing, this never triggered. It is likely that Unity simply catches all
            // exceptions already, so this would be redundant with regular unity error log
            // forwarding, which is already in place.
            // AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;

            _systemLog  = new Log("System");
            _defaultLog = new Log("Default");
            _unityLog   = new Log("Unity");

            // Install a forwarder from Unity to our custom logs
            UnityLogIntegration.Init();

            // Add a global log output that forwards to the regular Unity log
            try
            {
                UnityDebugLogOutput forwardToUnity = new UnityDebugLogOutput();
                Logs.AddGlobalOutput(forwardToUnity);
            }
            catch (Exception e)
            {
                Logs.System.WriteWarning("Rerouting Logs to Unity Debug Logs failed: {0}", LogFormat.Exception(e));
            }
        }
示例#2
0
        public void Write(Log source, LogEntry entry, object context)
        {
            // Note that now that we've transitioned towards a Managed Plugin, we can't
            // rely on preprocessor directives anymore. We're only compiling once, here.
            // All else has to be decided at runtime. The old preprocessor-driven editor
            // enhancements are only here for reference. As soon as we found out how to
            // safely access editor classes only in an editor context, they can be replaced
            // with runtime checks.

            // Are we in the editor?
            if (UnityLogIntegration.IsUnityMainThread)
            {
                _isEditor = UnityEngine.Application.isEditor;

                // Determine if we're using the pro skin, so we can adapt our rich
                // text colors to fit the color scheme.
                #if UNITY_EDITOR
                _isEditorProSkin = UnityEditor.EditorGUIUtility.isProSkin;
                #endif
            }

            // If we're in the editor, don't clutter the regular console with system logs.
            if (_isEditor && source == Logs.System)
            {
                return;
            }

            string   indentString;
            string[] lines = FormatMultiLineText(
                entry,
                (source.FormattedPrefix ?? ""),
                _indent,
                _isEditorProSkin,
                _allowColors,
                out indentString);
            string fullText = string.Join(Environment.NewLine, lines);

#if UNITY_EDITOR
            // If we only have a single line, use the remaining line for displaying
            // the local stack frame or context object, if it's a unity object.
            if (lines.Length == 1)
            {
                fullText = AppendEditorContextInfo(fullText, indentString, context);
            }

            // Add a separator to avoid confusion when viewing the full log
            // in the Unity Log Console and provide a nicer overview.
            fullText += Environment.NewLine;
#endif

            entry.Message = fullText;
            UnityLogIntegration.ForwardToUnity(entry, context);
        }
示例#3
0
        private static void Shutdown()
        {
            // Note: Shutdown should NOT do anything besides shutting down.
            // No logs, no anything. Unity doesn't like to be bothered during
            // shutdown.

            AppDomain.CurrentDomain.AssemblyLoad -= AppDomain_AssemblyLoad;
            AppDomain.CurrentDomain.ProcessExit  -= AppDomain_ProcessExit;

            UnityLogIntegration.Shutdown();
            ShutdownTextLog();
        }