Tilt Five™ Unity API  1.4.1
Log.cs
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020-2023 Tilt Five, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 using System.Collections;
17 using System.Collections.Generic;
18 using UnityEngine;
19 
21 {
22 
23  [System.Serializable]
24  public class LogSettings
25  {
26  [Range(0, 5)]
27  public int level = Log.VERBOSE_LEVEL;
28  public string TAG = "TFI";
29 
30 #if UNITY_EDITOR
31  internal LogSettings Copy()
32  {
33  return (LogSettings)MemberwiseClone();
34  }
35 #endif
36  }
37 
41  public class Log : Singleton<Log>
42  {
43 
45  private ILogger logger = UnityEngine.Debug.unityLogger;
46 
48  private string tag = "Tilt Five, Inc.";
49 
51  private int level = VERBOSE_LEVEL;
52 
57  public static string TAG
58  {
59  get => Instance.tag;
60  set => Instance.tag = value;
61  }
62 
67  public static int LogLevel
68  {
69  get => Instance.level;
70  set
71  {
72  Instance.level = value;
73 
74  if (INFO_LEVEL <= value)
75  Instance.logger.filterLogType = LogType.Log;
76  else if (WARN_LEVEL == value)
77  Instance.logger.filterLogType = LogType.Warning;
78  else if (ERROR_LEVEL == value)
79  Instance.logger.filterLogType = LogType.Error;
80  else
81  Instance.logger.filterLogType = LogType.Log;
82  }
83  }
85  private const string DEBUG = "DEBUG";
87  private const string ERROR = "ERROR";
89  private const string INFO = "INFO";
91  private const string VERBOSE = "VERBOSE";
93  private const string WARN = "WARN";
94 
96  public const int DEBUG_LEVEL = 1;
98  public const int ERROR_LEVEL = 4;
100  public const int INFO_LEVEL = 2;
102  public const int VERBOSE_LEVEL = 0;
104  public const int WARN_LEVEL = 3;
106  public const int DISABLED = 5;
107 
113  public static void Debug(string m, params object[] list)
114  {
115  if (DEBUG_LEVEL >= LogLevel)
116  {
117  log(LogType.Log, DEBUG, m, list);
118  }
119  }
120 
126 
127  public static void Error(string m, params object[] list)
128  {
129  if (ERROR_LEVEL >= LogLevel)
130  {
131  log(LogType.Error, ERROR, m, list);
132  }
133  }
134 
140  public static void Info(string m, params object[] list)
141  {
142  if (INFO_LEVEL >= LogLevel)
143  {
144  log(LogType.Log, INFO, m, list);
145  }
146  }
147 
153  public static void Verbose(string m, params object[] list)
154  {
155  if (VERBOSE_LEVEL >= LogLevel)
156  {
157  log(LogType.Log, VERBOSE, m, list);
158  }
159  }
160 
166  public static void Warn(string m, params object[] list)
167  {
168  if (WARN_LEVEL >= LogLevel)
169  {
170  log(LogType.Warning, WARN, m, list);
171  }
172  }
173 
181  private static void log(LogType logType, string tag, string m, params object[] list)
182  {
183  Instance.logger.Log(logType, tag, string.Format("[{0}]\n{1}", TAG, string.Format(m, list)));
184  }
185  }
186 }
The Logger.
Definition: Log.cs:42
static void Debug(string m, params object[] list)
DEBUG logging function call.
Definition: Log.cs:113
int level
The logging level.
Definition: Log.cs:51
static void log(LogType logType, string tag, string m, params object[] list)
Universal log write function.
Definition: Log.cs:181
const string INFO
INFO logging level as a string.
Definition: Log.cs:89
static void Warn(string m, params object[] list)
WARN logging function call.
Definition: Log.cs:166
static void Verbose(string m, params object[] list)
VERBOSE logging function call.
Definition: Log.cs:153
static void Info(string m, params object[] list)
INFO logging function call.
Definition: Log.cs:140
const int DISABLED
DISABLED logging level as an int.
Definition: Log.cs:106
const int ERROR_LEVEL
ERROR logging level as an int.
Definition: Log.cs:98
const string WARN
WARN logging level as a string.
Definition: Log.cs:93
const string ERROR
ERROR logging level as a string.
Definition: Log.cs:87
const int INFO_LEVEL
INFO logging level as an int.
Definition: Log.cs:100
const string DEBUG
DEBUG logging level as a string.
Definition: Log.cs:85
ILogger logger
The logger instance.
Definition: Log.cs:45
static void Error(string m, params object[] list)
ERROR logging function call.
Definition: Log.cs:127
string tag
The logging tag.
Definition: Log.cs:48
const int WARN_LEVEL
WARN logging level as an int.
Definition: Log.cs:104
const int VERBOSE_LEVEL
VERBOSE logging level as an int.
Definition: Log.cs:102
static int LogLevel
Gets or sets the logging level.
Definition: Log.cs:68
const string VERBOSE
VERBOSE logging level as a string.
Definition: Log.cs:91
const int DEBUG_LEVEL
DEBUG logging level as an int.
Definition: Log.cs:96
static string TAG
Gets or sets the logging tag.
Definition: Log.cs:58