53 lines
2.1 KiB
C#
53 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Debug.Log을 좀 더 편하게 사용하기 위한 헬퍼 클래스입니다.
|
|
/// </summary>
|
|
public static class Logger
|
|
{
|
|
public enum Level { Debug, Info, Warning, Error }
|
|
|
|
// 릴리즈 빌드에서 불필요한 스택트레이스 끄기
|
|
static Logger()
|
|
{
|
|
#if !UNITY_EDITOR && !DEVELOPMENT_BUILD
|
|
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
|
|
Application.SetStackTraceLogType(LogType.Warning,StackTraceLogType.None);
|
|
Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.ScriptOnly);
|
|
#endif
|
|
}
|
|
|
|
// 에디터/개발 빌드에서만 컴파일됨 → 릴리즈에선 이 호출 자체가 사라집니다
|
|
[Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
|
|
public static void LogDebug(object message, UnityEngine.Object context = null) => LogInternal(Level.Debug, message, context);
|
|
|
|
[Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
|
|
public static void LogInfo(object message, UnityEngine.Object context = null) => LogInternal(Level.Info, message, context);
|
|
|
|
[Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
|
|
public static void LogWarning(object message, UnityEngine.Object context = null) => LogInternal(Level.Warning, message, context);
|
|
|
|
// 에러는 항상 남겨둡니다
|
|
public static void LogError(object message, UnityEngine.Object context = null) => LogInternal(Level.Error, message, context);
|
|
|
|
static void LogInternal(Level level, object message, UnityEngine.Object context = null)
|
|
{
|
|
switch (level)
|
|
{
|
|
case Level.Debug:
|
|
case Level.Info:
|
|
UnityEngine.Debug.Log(message, context);
|
|
break;
|
|
case Level.Warning:
|
|
UnityEngine.Debug.LogWarning(message, context);
|
|
break;
|
|
case Level.Error:
|
|
UnityEngine.Debug.LogError(message, context);
|
|
break;
|
|
}
|
|
}
|
|
} |