< Summary

Class:GDX.Trace
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Trace.cs
Covered lines:0
Uncovered lines:29
Coverable lines:29
Total lines:152
Line coverage:0% (0 of 29)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:1
Method coverage:0% (0 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Output(...)0%1321100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Trace.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using Object = UnityEngine.Object;
 7
 8namespace GDX
 9{
 10    /// <summary>
 11    ///     Trace logging functionality.
 12    /// </summary>
 13    [VisualScriptingCompatible(8)]
 14    public static class Trace
 15    {
 16        // TODO: Create trace levels output methods which can be compiled out?
 17
 18        /// <summary>
 19        /// Trace Levels
 20        /// </summary>
 21        [Flags]
 22        public enum TraceLevel : ushort
 23        {
 24            /// <summary>
 25            ///     A trivial informational entry.
 26            /// </summary>
 27            Info = 0,
 28
 29            /// <summary>
 30            ///     An entry indicating something which might be useful to provide context.
 31            /// </summary>
 32            Log = 1,
 33
 34            /// <summary>
 35            ///     An issue has been found but handled.
 36            /// </summary>
 37            Warning = 2,
 38
 39            /// <summary>
 40            ///     An error has occurred which may be recoverable, but notification is required.
 41            /// </summary>
 42            Error = 4,
 43
 44            /// <summary>
 45            ///     An exception has occured and needs to be flagged up for resolution. The should never happen in a rel
 46            ///     environment.
 47            /// </summary>
 48            Exception = 8,
 49
 50            /// <summary>
 51            ///     An assertion based event has occured and has some sort of messaging to be recorded.
 52            /// </summary>
 53            Assertion = 16,
 54
 55            /// <summary>
 56            ///     A fatal error has occured which needs to be logged, and the program will subsequently crash.
 57            /// </summary>
 58            Fatal = 32
 59        }
 60
 61        /// <summary>
 62        ///     Log a trace message to the appropriate subscribers and the Unity console where applicable with additiona
 63        /// </summary>
 64        /// <param name="level">The <see cref="TraceLevel" /> of the particular message.</param>
 65        /// <param name="traceObject">An <see cref="object" /> representing the message to be recorded.</param>
 66        /// <param name="contextObject">An <see cref="UnityEngine.Object" /> indicating context for the given message.</
 67        /// <param name="memberName">Automatically filled out member name which invoked this method.</param>
 68        /// <param name="sourceFilePath">Automatically filled out source code path of the invoking method.</param>
 69        /// <param name="sourceLineNumber">Automatically filled out line number of the invoking method.</param>
 70        public static void Output(TraceLevel level, object traceObject,
 71            Object contextObject = null,
 72            [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
 73            [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
 74            [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
 075        {
 76#if UNITY_EDITOR || DEVELOPMENT_BUILD
 077            if (!Config.TraceDevelopmentLevels.HasFlags(level))
 078            {
 079                return;
 80            }
 81#elif DEBUG
 82            if (!Config.traceDebugLevels.HasFlags(level))
 83            {
 84                return;
 85            }
 86#else
 87            if (!Config.TraceReleaseLevels.HasFlags(level))
 88            {
 89                return;
 90            }
 91#endif
 92
 93            // Build output content
 094            if (traceObject is Exception traceException)
 095            {
 096                Console.WriteLine(
 97                    $"{traceException.Message}\n{traceException.StackTrace}\n{memberName}\n{sourceFilePath}:{sourceLineN
 098            }
 99            else
 0100            {
 0101                Console.WriteLine($"{traceObject}\n{memberName}\n{sourceFilePath}:{sourceLineNumber.ToString()}");
 0102            }
 103
 104            // Is outputting to the Unity console enabled?
 105#if UNITY_EDITOR || DEVELOPMENT_BUILD
 0106            if (!Config.TraceDevelopmentOutputToUnityConsole)
 0107            {
 0108                return;
 109            }
 110#elif DEBUG
 111            if (!Config.traceDebugOutputToUnityConsole)
 112            {
 113                return;
 114            }
 115#endif
 116
 117#if UNITY_EDITOR || DEVELOPMENT_BUILD || DEBUG
 118            // Figure out what path to take based on the level
 0119            switch (level)
 120            {
 121                case TraceLevel.Assertion:
 0122                    UnityEngine.Debug.LogAssertion(traceObject, contextObject);
 0123                    break;
 124
 125                case TraceLevel.Warning:
 0126                    UnityEngine.Debug.LogWarning(traceObject, contextObject);
 0127                    break;
 128
 129                case TraceLevel.Error:
 0130                    UnityEngine.Debug.LogError(traceObject, contextObject);
 0131                    break;
 132
 133                case TraceLevel.Exception:
 0134                    UnityEngine.Debug.LogException((Exception)traceObject, contextObject);
 0135                    break;
 136
 137                case TraceLevel.Fatal:
 0138                    UnityEngine.Debug.LogError(traceObject, contextObject);
 0139                    UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.FatalError);
 0140                    break;
 141
 142                case TraceLevel.Info:
 143                case TraceLevel.Log:
 144                default:
 0145                    UnityEngine.Debug.Log(traceObject, contextObject);
 0146                    break;
 147
 148            }
 149#endif
 0150        }
 151    }
 152}