示例#1
0
    /// <summary>
    ///     Update is called once per frame
    /// </summary>

    #region Update

    // ReSharper disable once UnusedMember.Local
    private void Update()
    {
        _staticIsEnableExceptionLogging   = IsEnableExceptionLogging;
        _staticIsEnableErrorLogging       = IsEnableErrorLogging;
        _staticIsEnableWarningLogging     = IsEnableWarningLogging;
        _staticIsEnableInformationLogging = IsEnableInformationLogging;
        _staticIsEnableEventLogging       = IsEnableEventLogging;

        if (LogQueueForShow.Any() && LogQueueForShow.Count > NumberOfLogIgnore)
        {
            // Enable ignore log and save count
            _numberOfIgnoreInPrintTime = 0;

            // Save current log count
            var currentLogCount = LogQueueForShow.Count;

            // Remove logs
            ConsoleLogging(LogQueueForShow.Dequeue());

            // Clear other logs
            LogQueueForShow.Clear();

            // Save log item for count of ignore
            var logForCountOfIgnore = new G9LogItem(LogsType.WARN, "IGNORE-LOG", "IGNORE-LOG",
                                                    "The number of logs is too high, not all of them can be displayed.\n" +
                                                    $"Ignore {currentLogCount + _numberOfIgnoreInPrintTime} +  Logs! ",
                                                    nameof(G9Logging4Unity),
                                                    $"{nameof(G9Logging4Unity)}.{nameof(Update)}", "0", DateTime.Now);

            // Reset ignore log
            _numberOfIgnoreInPrintTime = -1;

            // Print log ignore
            ConsoleLogging(logForCountOfIgnore);
        }
        else
        {
            if (!LogQueueForShow.Any())
            {
                return;
            }
            var countOfLogs = LogQueueForShow.Count;
            // Print logs
            while (countOfLogs-- > 0)
            {
                ConsoleLogging(LogQueueForShow.Dequeue());
            }
        }
    }
示例#2
0
    /// <summary>
    ///     Ready log data for show in the console
    /// </summary>
    /// <param name="logItem">Specify log item for show</param>

    #region ConsoleLogging

    private void ConsoleLogging(G9LogItem logItem)
    {
        // Set Log type number
        var logTypeNumber = (byte)logItem.LogType;

        try
        {
            // Ignore if null
            if (string.IsNullOrEmpty(logItem.Body))
            {
                return;
            }

            // Set log data
            var log =
                $"[### Log Type: {logItem.LogType} ###]\nDate & Time: {logItem.LogDateTime:yyyy/MM/ss HH:mm:ss.fff}\nIdentity: {logItem.Identity}\tTitle: {logItem.Title}\nBody: {new Regex("[^a-zA-Z0-9 -]").Replace(logItem.Body, string.Empty)}\nPath: {logItem.FileName}\nMethod: {logItem.MethodBase}\tLine: {logItem.LineNumber}\n\n";

            // Set debug ui log if exists
            if (TextForDebug != null)
            {
                var newLog = log + TextForDebug.text;
                TextForDebug.text = newLog.Substring(0, Mathf.Clamp(newLog.Length, 0, 6000));
            }

            // Show console log
            Debug.LogFormat(UnityLogTypes[logTypeNumber],
                            LogOption.NoStacktrace,
                            null,
                            $"<color=#{0:X2}{LoggingColors[logTypeNumber].g:X2}{LoggingColors[logTypeNumber].b:X2}>{log}</color>"
                            );
        }
        catch (Exception ex)
        {
            // Ignore
            Debug.LogWarning(ex.StackTrace);
        }
    }