-
[Unity] ์กฐ๊ฑด๋ถ ๋ก๊น ์ผ๋ก ์ฑ๋ฅ ์ต์ ํํ๊ธฐ - CustomLogger ํด๋์ค ๋ง๋ค์ด๋ณด๊ธฐUnity 2025. 5. 30. 12:26
๐งญ ๊ฐ์
Unity ๊ฐ๋ฐํ๋ค ๋ณด๋ฉด Debug.Log๋ฅผ ์ฌ์ฉํ ์ผ์ด ๋ง๋ค.
Debug๋ ์๊ฐ๋ณด๋ค ์ฑ๋ฅ์ ์ํฅ์ ๋ง์ด ๋ผ์น๋๋ฐ, ๋ฆด๋ฆฌ์ฆ ๋น๋์ ๋ก๊ทธ๊ฐ ํฌํจ๋๊ฒ ๋๋ค๋ฉด ์ฑ๋ฅ์ ์ํฅ์ ๋ง์ด ๋ผ์น๊ฒ ๋๋ค.
๊ทธ๋์ ๋น๋๋๋ง๋ค ์ฝ๋์ ์๋ ๋ชจ๋ Debug๋ฌธ์ ์ง์์ฃผ๊ฑฐ๋ ํด์ผ ํ๋๋ฐ, ํด๋น ์์ ์ ๋๋ฌด ๊ท์ฐฎ๋ค...์ด๋ฒ์๋ ํด๋น ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋๋ก ์กฐ๊ฑด๋ถ ์ปดํ์ผ์ ํ์ฉํ CustomLogger ํด๋์ค๋ฅผ ๋ง๋ค์ด๋ณผ ์์ ์ด๋ค.
- โ Conditional ์์ฑ์ ํ์ฉํ CustomLogger ํด๋์ค ๊ตฌํํ๊ธฐ
- โ ๋น๋ ํ๊ฒฝ์ ๋ฐ๋ผ ์๋์ผ๋ก ๋ก๊ทธ ์ ๊ฑฐํ๋ ์์คํ ๋ง๋ค๊ธฐ
- โ ๊ฐ๋ฐ/๋ฆด๋ฆฌ์ฆ ๋น๋๋ณ ๋ก๊ทธ ๊ด๋ฆฌ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
๐ง Step 1. CustomLogger ํด๋์ค ๊ธฐ๋ณธ ๊ตฌ์กฐ ์ดํดํ๊ธฐ
๋จผ์ ์ฌ์ฉํ ํต์ฌ ๊ฐ๋ ์ ์ดํดํด๋ณด์.
์ผ๋จ Unity์์ Debug.Log๋ ๋ฆด๋ฆฌ์ฆ ๋น๋์์๋ ํธ์ถ๋์ด ์ฑ๋ฅ ์ด์๋ฅผ ์ผ์ผํฌ ์ ์๊ธฐ ๋๋ฌธ์, ๋ค์๊ณผ ๊ฐ์ ์กฐ๊ฑด์ ๋ง์ถฐ CustomLogger๋ฅผ ๊ตฌ์ฑํ์.- ํต์ฌ ์๋ฆฌ:
[Conditional("ENABLE_LOG")]
์์ฑ์ ์ฌ์ฉํด์ ์ปดํ์ผ ์์ ์ ๋ก๊ทธ ์ฝ๋๋ฅผ ์์ ํ ์ ๊ฑฐ - ์ฑ๋ฅ ์ต์ ํ: ๋ฆด๋ฆฌ์ฆ ๋น๋์์๋ ๋ก๊ทธ ๊ด๋ จ ์ฝ๋๊ฐ ์์ ์กด์ฌํ์ง ์์
ํต์ฌ์ด ๋๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค:
using System.Diagnostics; public static class CustomLogger { [Conditional("ENABLE_LOG")] public static void Log(object message) { UnityEngine.Debug.Log(message); } }
ํด๋น ์์ฑ์ ์ฌ์ฉํ ๋ ์ฃผ์์ฌํญ
- ๋ฉ์๋๋ ๋ฐ๋์
static
์ด์ด์ผ ํจ - ๋ฐํํ์ด
void
์ฌ์ผ ํจ
โ๏ธ Step 2. ์ ์ฒด Debug ๋ฉ์๋ ๋ํํ๊ธฐ
๊ธฐ์กด Debug ํด๋์ค์์ ์ฌ์ฉ๋๋ ๋ฉ์๋๋ฅผ Custom Logger์์ ๋งคํํด์ค ํ์๊ฐ ์๋ค.
- ๊ธฐ๋ณธ ๋ก๊น ๋ฉ์๋: Log, LogWarning, LogError
- ํฌ๋งท ๋ก๊น ๋ฉ์๋: LogFormat, LogWarningFormat, LogErrorFormat
- ์์ธ/์ด์ค์ ๋ฉ์๋: LogException, LogAssertion, Assert
- ์๊ฐ์ ๋๋ฒ๊น ๋ฉ์๋: DrawLine, DrawRay
- ์ ํธ๋ฆฌํฐ ๋ฉ์๋: Break, ClearDeveloperConsole
์ฐ๋ฆฌ๋ ๊ธฐ๋ณธ์ Unity Debug API์ ๋์ผํ ์ธํฐํ์ด์ค๋ก ์ก๊ณ , ๋ชจ๋ ๋ฉ์๋๋ฅผ ๋ํํ ๊ฒ์ด๋ค.
โ ์ ๋ชจ๋ ๋ฉ์๋๋ฅผ ๋ํํด์ผ ํ ๊น?
- ์ผ๊ด์ฑ ๋ณด์ฅ: ํ๋ก์ ํธ ์ ์ฒด์์ ๋์ผํ ๋ก๊น ์์คํ ์ฌ์ฉ
- ์ฌ์ด ๋ง์ด๊ทธ๋ ์ด์ : ๊ธฐ์กด Debug.Log ์ฝ๋๋ฅผ ์ฝ๊ฒ ๊ต์ฒด ๊ฐ๋ฅ
- ํ์ฅ์ฑ: ๋์ค์ ํ์ผ ๋ก๊น ์ด๋ ์๊ฒฉ ๋ก๊น ๊ธฐ๋ฅ ์ถ๊ฐ ์ ์ ๋ฆฌ
์ ๋ํฐ Debug Methods๋ ๊ณต์๋ฌธ์์์ ํ์ธํ ์ ์๋ค.
[Debug - Unity ์คํฌ๋ฆฝํ API
Class containing methods to ease debugging while developing a game.
docs.unity3d.com](https://docs.unity3d.com/kr/2021.3/ScriptReference/Debug.html)
์ ์ฉ๋ฐฉ๋ฒ
[Conditional("ENABLE_LOG")] public static void LogWarning(object message, Object context) { UnityEngine.Debug.LogWarning(message, context); } [Conditional("ENABLE_LOG")] public static void DrawLine(Vector3 start, Vector3 end, Color color = default(Color), float duration = 0.0f, bool depthTest = true) { UnityEngine.Debug.DrawLine(start, end, color == default(Color) ? Color.white : color, duration, depthTest); }
๐ Step 3. ํ๋ก์ ํธ์ ์ ์ฉ ๋ฐ ์ฌ๋ณผ ์ ์ํ๊ธฐ
ํ๋ก์ ํธ ์ค์ ๋ฐฉ๋ฒ
- ์คํฌ๋ฆฝํธ ์ถ๊ฐ: CustomLogger.cs ํ์ผ์ ํ๋ก์ ํธ์ ์ถ๊ฐ
- ์ฌ๋ณผ ์ ์: Player Settings โ Other Settings โ Scripting Define Symbols์
ENABLE_LOG
์ถ๊ฐ (๊ฐ๋ฐ์ฉ) - ๊ธฐ์กด ์ฝ๋ ๊ต์ฒด:
Debug.Log
โCustomLogger.Log
๋ก ๋ณ๊ฒฝ
Scripting Define Symbols์ ENABLE_LOG ์ถ๊ฐ ๋ฆด๋ฆฌ์ฆ ๋น๋ ์ค์
- ๋ฆด๋ฆฌ์ฆ์ฉ ๋น๋ ์ค์ ์์๋
ENABLE_LOG
์ฌ๋ณผ์ ์ ๊ฑฐ - ๋ชจ๋ CustomLogger ํธ์ถ์ด ์ปดํ์ผ ์์ ์ ์์ ํ ์ ๊ฑฐ๋จ
Unity 6 ๋ถํฐ๋ ๋น๋ ์ฐฝ์์ ๋น๋ ํ๋กํ์ ์ฌ๋ฌ๊ฐ๋ก ๊ตฌ์ฑํ๋ ๊ฒ์ ์ง์ํ๋ค.
ํ ์คํธ ๋น๋ ํ๋กํ / ๋ฆด๋ฆฌ์ฆ ๋น๋ ํ๋กํ์ ๊ตฌ๋ถํ์ฌ ์ฌ์ฉํ๋ฉด ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.๋ฆด๋ฆฌ์ฆ ๋น๋ ์ค์ ์ด์ ํ ์คํธ๋ฅผ ์งํํด๋ณด์.
์ฌ์์ ๊ฐ๋จํ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ค๊ณ , CustomLogger๋ฅผ ์ฌ์ฉํด๋ณด์using UnityEngine; public class TestC : MonoBehaviour { private int playerHealth = 100; void Start() { // ๊ธฐ์กด ์ฝ๋ Debug.Log("[Debug]ํ๋ ์ด์ด HP: " + playerHealth); // CustomLogger ์ฌ์ฉ CustomLogger.Log("[CustomLogger]ํ๋ ์ด์ด HP: " + playerHealth); } }
์ฝ์ ์ฐฝ ๋ค์๊ณผ ๊ฐ์ด ์ ์ ์ฉ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค!
โ ๏ธ์ฃผ์์ฌํญ
----Logger ํด๋์ค๋ก ์ ์ํ๊ณ , ๋ฉ์๋๋ Log๋ก ์์ํด์ผ ์ฝ์ ์ฐฝ์์ ์ฝ๋๋ก ๋ฐ๋ก ์ ๊ทผ ๊ฐ๋ฅํ๋ค.
Logging ๊ณผ ๊ฐ์ด ์ ์ํ๋ฉด ์ฝ์์์ ๋๋ธ ํด๋ฆญ ์ Logging ํด๋์ค๋ก ๋์ด๊ฐ๋ ์ํฉ์ด ๋ฐ์ํ๋ค.
**๊ณต์ ๋ด์ฉ์ ์๋์ง๋ง, Logging ํด๋์ค๋ก ํ ์คํธ ํด๋ดค์ ๋ ํด๋น ํ์์ด ๋ฐ์ํ์๋ค.
https://www.reddit.com/r/Unity3D/comments/17eikh0/i_found_a_way_to_go_to_the_right_line_in_your/
From the Unity3D community on Reddit: I found a way to go to the "right line in your code" when double-clicking a custom log mes
Explore this post and more from the Unity3D community
www.reddit.com
โ ๊ฒฐ๊ณผ ์์ฝ
- ๊ฐ๋ฐ ํ๊ฒฝ: ENABLE_LOG ์ฌ๋ณผ ์ ์ ์ ๋ชจ๋ ๋ก๊ทธ๊ฐ ์ ์ ์ถ๋ ฅ
- ๋ฆด๋ฆฌ์ฆ ๋น๋: ์ฌ๋ณผ ๋ฏธ์ ์ ์ ๋ก๊ทธ ์ฝ๋๊ฐ ์์ ํ ์ ๊ฑฐ๋์ด ์ฑ๋ฅ ํฅ์
- ์ฝ๋ ์ผ๊ด์ฑ: ๊ธฐ์กด Debug API์ ๋์ผํ ์ธํฐํ์ด์ค๋ก ์ฌ์ด ๋ง์ด๊ทธ๋ ์ด์ ๊ฐ๋ฅ
๐ ๋ง๋ฌด๋ฆฌ
์ฌ๊ธฐ๊น์ง ์กฐ๊ฑด๋ถ ์ปดํ์ผ์ ํ์ฉํ CustomLogger ํด๋์ค ๊ตฌํ ๋ฐฉ๋ฒ์ ์์๋ณด์๋ค.
์ด ๊ณผ์ ์ ํตํด, ๊ฐ๋ฐ ์์๋ ํ๋ถํ ๋ก๊ทธ ์ ๋ณด๋ฅผ ํ์ธํ๋ฉด์๋, ๋ฆด๋ฆฌ์ฆ ๋น๋์์๋ ์ฑ๋ฅ ์ ํ ์์ด ๊น๋ํ ์ฝ๋๋ฅผ ์ ์งํ ์ ์๊ฒ ๋์๊ณ , Unity ํ๋ก์ ํธ ์ต์ ํ๋ฅผ ์ํ ๊ธฐ๋ฐ์ ๋ค์ก๋ค๊ณ ๋ณผ ์ ์๋ค.๐ฑ ์ถ๊ฐ์ ์ผ๋ก ํด๋ณผ๋งํ ํ์ฅ
- CustomLogger๋ฅผ ํ์ฅํ์ฌ ํ์ผ ๋ก๊น ๊ธฐ๋ฅ ์ถ๊ฐํ๋ ๋ฐฉ์์ผ๋ก ๋๋ฒ๊น ๊ณ ๋ํ
- ์๊ฒฉ ๋ก๊น ์์คํ ๊ตฌํ์ผ๋ก ์ค์ ์ฌ์ฉ์ ํ๊ฒฝ์์์ ๋ก๊ทธ ์์ง
- ๋ก๊ทธ ๋ ๋ฒจ๋ณ ํํฐ๋ง ์์คํ ์ผ๋ก ๋ ์ธ๋ฐํ ๋ก๊ทธ ๊ด๋ฆฌ
- ๋ก๊ทธ ์ถ๋ ฅ ํฌ๋งท ์ปค์คํฐ๋ง์ด์ง์ผ๋ก ๊ฐ๋ ์ฑ ํฅ์
์ด ๊ธ์ด, Unity ์ฑ๋ฅ ์ต์ ํ๋ก ๊ณ ํต๋ฐ๋ ๊ฐ๋ฐ์๋ค์๊ฒ ๋์์ด ๋๊ธธ ๋ฐ๋ผ๋ฉด์,
๐ ์ฆ์ฝ(์ฆ๊ฑฐ์ด ์ฝ๋ฉ ๋์ธ์)!
๐ CustomLogger.cs ์ ์ฒด ์์ค์ฝ๋ ๋ณด๊ธฐ
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Diagnostics; public static class CustomLogger { [Conditional("ENABLE_LOG")] public static void Log(object message) { UnityEngine.Debug.Log(message); } [Conditional("ENABLE_LOG")] public static void Log(object message, Object context) { UnityEngine.Debug.Log(message, context); } [Conditional("ENABLE_LOG")] public static void LogFormat(string format, params object[] args) { UnityEngine.Debug.LogFormat(format, args); } [Conditional("ENABLE_LOG")] public static void LogFormat(Object context, string format, params object[] args) { UnityEngine.Debug.LogFormat(context, format, args); } [Conditional("ENABLE_LOG")] public static void LogWarning(object message) { UnityEngine.Debug.LogWarning(message); } [Conditional("ENABLE_LOG")] public static void LogWarning(object message, Object context) { UnityEngine.Debug.LogWarning(message, context); } [Conditional("ENABLE_LOG")] public static void LogWarningFormat(string format, params object[] args) { UnityEngine.Debug.LogWarningFormat(format, args); } [Conditional("ENABLE_LOG")] public static void LogWarningFormat(Object context, string format, params object[] args) { UnityEngine.Debug.LogWarningFormat(context, format, args); } [Conditional("ENABLE_LOG")] public static void LogError(object message) { UnityEngine.Debug.LogError(message); } [Conditional("ENABLE_LOG")] public static void LogError(object message, Object context) { UnityEngine.Debug.LogError(message, context); } [Conditional("ENABLE_LOG")] public static void LogErrorFormat(string format, params object[] args) { UnityEngine.Debug.LogErrorFormat(format, args); } [Conditional("ENABLE_LOG")] public static void LogErrorFormat(Object context, string format, params object[] args) { UnityEngine.Debug.LogErrorFormat(context, format, args); } [Conditional("ENABLE_LOG")] public static void LogException(System.Exception exception) { UnityEngine.Debug.LogException(exception); } [Conditional("ENABLE_LOG")] public static void LogException(System.Exception exception, Object context) { UnityEngine.Debug.LogException(exception, context); } [Conditional("ENABLE_LOG")] public static void LogAssertion(object message) { UnityEngine.Debug.LogAssertion(message); } [Conditional("ENABLE_LOG")] public static void LogAssertion(object message, Object context) { UnityEngine.Debug.LogAssertion(message, context); } [Conditional("ENABLE_LOG")] public static void LogAssertionFormat(string format, params object[] args) { UnityEngine.Debug.LogAssertionFormat(format, args); } [Conditional("ENABLE_LOG")] public static void LogAssertionFormat(Object context, string format, params object[] args) { UnityEngine.Debug.LogAssertionFormat(context, format, args); } [Conditional("ENABLE_LOG")] public static void Assert(bool condition) { UnityEngine.Debug.Assert(condition); } [Conditional("ENABLE_LOG")] public static void Assert(bool condition, object message) { UnityEngine.Debug.Assert(condition, message); } [Conditional("ENABLE_LOG")] public static void Assert(bool condition, object message, Object context) { UnityEngine.Debug.Assert(condition, message, context); } [Conditional("ENABLE_LOG")] public static void AssertFormat(bool condition, string format, params object[] args) { UnityEngine.Debug.AssertFormat(condition, format, args); } [Conditional("ENABLE_LOG")] public static void AssertFormat(bool condition, Object context, string format, params object[] args) { UnityEngine.Debug.AssertFormat(condition, context, format, args); } [Conditional("ENABLE_LOG")] public static void DrawLine(Vector3 start, Vector3 end, Color color = default(Color), float duration = 0.0f, bool depthTest = true) { UnityEngine.Debug.DrawLine(start, end, color == default(Color) ? Color.white : color, duration, depthTest); } [Conditional("ENABLE_LOG")] public static void DrawRay(Vector3 start, Vector3 dir, Color color = default(Color), float duration = 0.0f, bool depthTest = true) { UnityEngine.Debug.DrawRay(start, dir, color == default(Color) ? Color.white : color, duration, depthTest); } [Conditional("ENABLE_LOG")] public static void Break() { UnityEngine.Debug.Break(); } [Conditional("ENABLE_LOG")] public static void ClearDeveloperConsole() { UnityEngine.Debug.ClearDeveloperConsole(); } }
'Unity' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ