지난 포스팅에서 Debug.Log에 이어서 로그 콜백을 한 번 더 써보려고한다.
Unity에서는 로그를 전송한 후에 콜백이 이루어진다.
공식문서를 살펴보자.
public delegate void LogCallback(string condition, string stackTrace, LogType type);
Description
Use this delegate type with Application.logMessageReceived or Application.logMessageReceivedThreaded to monitor what gets logged.
See Also: Application.logMessageReceived, Application.logMessageReceivedThreaded, LogType.
별 내용 없다.
맞다. 사실 별 내용 아니다.
빠르게 사용법을 알아보자.
일단 Application.logMessageReceived 혹은 Application.logMessageReceivedThreaded
Unity - Scripting API: Application.logMessageReceivedThreaded
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
위 두가지의 이벤트를 통해 얻을 수 있다고 한다.
private void Awake()
{
Application.logMessageReceived += Application_logMessageReceived;
}
private void OnDestroy()
{
Application.logMessageReceived -= Application_logMessageReceived;
}
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
{
Debug.Log(type + "\ncondition => " + condition + "\nstackTrace => " + stackTrace);
}
이벤트 등록과 콜백 함수를 등록한 후 확인해보자.
public void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("Input Key 'A' Log");
}
if(Input.GetKeyDown(KeyCode.S))
{
Debug.LogException(new System.Exception("Input Key 'S' Exception"));
}
if (Input.GetKeyDown(KeyCode.D))
{
Debug.LogError("Input Key 'D' Error");
}
if (Input.GetKeyDown(KeyCode.F))
{
Debug.Assert(false, "Input Key 'F' Assert");
}
}
간단하게 테스트 코드를 작성 후 플레이를 해본다.
로그가 잘 찍혔다.
알아야 할 것은
'콜백 (Application_logMessageReceived) 내에서 LogType의 로그는 총 5종류 라는것'
public enum LogType
{
Error = 0,
Assert = 1,
Warning = 2,
Log = 3,
Exception = 4
}
잘 봐야 할 것은
'콜백 (Application_logMessageReceived) 함수 내에서 작성된 Log가 먼저 찍힌 후 'Update()'문에 작성된 Log가 찍혔다는 것.
이를 통해 완벽하진 않지만 그래도 클라이언트 내에서 자체적으로 간단한 StackTrace 파일을
만들어서 확인 할 수 있는 방법을 생각해 낼 수 있을 것이다.
'프로그래밍 > Unity3D' 카테고리의 다른 글
Rider를 소개합니다 (0) | 2022.08.21 |
---|---|
Unity Cache Server (유니티 캐시서버) (0) | 2021.12.24 |
유니티 콘솔 로그를 이쁘게 만들자 (5) | 2020.06.02 |
Unity Spine 애니메이션 속도 1배속 고정 (0) | 2020.05.26 |
Firebase Cloud Messaging (FCM) 파이어베이스 클라우드 메시징 (1) | 2020.05.25 |