// MIT License - Copyright (c) 2023 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
#if !ENABLE_UBERLOGGING && (DEVELOPMENT_BUILD || DEBUG || UNITY_EDITOR)
#define ENABLE_UBERLOGGING
#endif
namespace WallstopStudios.UnityHelpers.Core.Extension
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using Helper;
using Helper.Logging;
using UnityEngine;
using Utils;
using Object = UnityEngine.Object;
///
/// Provides advanced logging extensions for Unity Objects with metadata extraction, thread-aware logging,
/// and per-object logging control. Enabled in development builds, debug builds, and Unity Editor.
///
///
/// Thread Safety: Thread-safe. Automatically routes logs to Unity main thread when necessary.
/// Performance: Uses reflection-based metadata caching with periodic cleanup. Metadata is cached per type.
/// Allocations: Uses metadata cache and pooled dictionary resources to minimize allocations.
/// Configuration: Define ENABLE_UBERLOGGING to enable logging in non-development builds.
///
public static class WallstopStudiosLogger
{
public static readonly UnityLogTagFormatter LogInstance = new(
createDefaultDecorators: true
);
private static bool ShouldLogOnMainThread =>
Equals(Thread.CurrentThread, UnityMainThread)
|| (UnityMainThread == null && !Application.isPlaying);
private static Thread UnityMainThread;
private const int LogsPerCacheClean = 5;
private static bool LoggingEnabled = true;
private static long _cacheAccessCount;
private static readonly HashSet