forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLogLine.cs
More file actions
75 lines (67 loc) · 1.8 KB
/
Copy pathLogLine.cs
File metadata and controls
75 lines (67 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Mediapipe.Unity
{
#pragma warning disable IDE0065
using Color = UnityEngine.Color;
#pragma warning restore IDE0065
public class LogLine : MonoBehaviour
{
[SerializeField] private Text _utcTimeArea;
[SerializeField] private Text _tagArea;
[SerializeField] private Text _messageArea;
public void SetLog(MemoizedLogger.LogStruct logStruct)
{
_utcTimeArea.text = FormatUtcTime(logStruct.utcTime);
_tagArea.text = FormatTag(logStruct.tag);
_messageArea.text = FormatMessage(logStruct.message);
_messageArea.color = GetMessageColor(logStruct.logLevel);
}
private string FormatUtcTime(DateTime utcTime)
{
return utcTime.ToString("MMM dd hh:mm:ss.fff");
}
private string FormatTag(string tag)
{
return (tag == null || tag.Length == 0) ? null : $"{tag}:";
}
private string FormatMessage(object message)
{
return message == null ? "Null" : message.ToString();
}
private Color GetMessageColor(Logger.LogLevel logLevel)
{
switch (logLevel)
{
case Logger.LogLevel.Fatal:
case Logger.LogLevel.Error:
{
return Color.red;
}
case Logger.LogLevel.Warn:
{
return Color.yellow;
}
case Logger.LogLevel.Info:
{
return Color.green;
}
case Logger.LogLevel.Debug:
{
return Color.gray;
}
case Logger.LogLevel.Verbose:
default:
{
return Color.white;
}
}
}
}
}