예제 #1
0
	void Awake ()
	{
		instance = this;
		Lumos.OnReady += Ready;
	}
예제 #2
0
    /// <summary>
    /// Records a log message.
    /// </summary>
    /// <param name="message">The message.</param>
    /// <param name="trace">Details of the log's origin.</param>
    /// <param name="type">Message type (debug, warning, error, etc.).</param>
    public static void Record(string message, string trace, LogType type)
    {
        // Checks if Lumos and LumosDiagnostics is installed correctly
        if (!LumosDiagnostics.IsInitialized())
        {
            return;
        }

        // Ignore logs in editor is the option is selected.
        if (Application.isEditor && !Lumos.runInEditor)
        {
            return;
        }

        // Ignore messages logged by Lumos.
        if (message.StartsWith(LumosUnity.Debug.prefix))
        {
            return;
        }

        // Don't record empty messages
        if (message == null || message == "")
        {
            return;
        }

        // Only log message types that the user specifies.
        if (type == LogType.Assert ||
            (type == LogType.Log && !LumosDiagnostics.recordDebugLogs) ||
            (type == LogType.Warning && !LumosDiagnostics.recordDebugWarnings) ||
            (type == LogType.Error && !LumosDiagnostics.recordDebugErrors) ||
            (type == LogType.Exception && !LumosDiagnostics.recordDebugErrors))
        {
            return;
        }

        // Skip messages that the user explicitly wishes to ignore.
        foreach (var ignoreMessage in toIgnore)
        {
            if (message.StartsWith(ignoreMessage))
            {
                return;
            }
        }

        var hash = LumosUnity.Util.MD5Hash(typeLabels[type], message, trace);

        if (logs.ContainsKey(hash))
        {
            // Increment an identical log's total.
            logs[hash]["total"] = (int)logs[hash]["total"] + 1;
        }
        else
        {
            // Otherwise create a new one.
            logs[hash] = new Dictionary <string, object>()
            {
                { "log_id", hash },
                { "type", typeLabels[type] },
                { "message", message },
                { "level", Application.loadedLevelName },
                { "total", 1 }
            };

            LumosUnity.Util.AddToDictionaryIfNonempty(logs[hash], "trace", trace);
        }
    }