Tanoda
Logger.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using System.Reflection;
11
12namespace LeapInternal {
13 public static class Logger {
14
18 public static void Log(object message) {
19 UnityEngine.Debug.Log(message);
20 }
21
22 public static void LogStruct(object thisObject, string title = "") {
23 try {
24 if (!thisObject.GetType().IsValueType) {
25 Log(title + " ---- Trying to log non-struct with struct logger");
26 return;
27 }
28 Log(title + " ---- " + thisObject.GetType().ToString());
29 FieldInfo[] fieldInfos;
30 fieldInfos = thisObject.GetType().GetFields(
31 BindingFlags.Public | BindingFlags.NonPublic // Get public and non-public
32 | BindingFlags.Static | BindingFlags.Instance // Get instance + static
33 | BindingFlags.FlattenHierarchy); // Search up the hierarchy
34
35 // write member names
36 foreach (FieldInfo fieldInfo in fieldInfos) {
37 object obj = fieldInfo.GetValue(thisObject);
38 string value = obj == null ? "null" : obj.ToString();
39 Log(" -------- Name: " + fieldInfo.Name + ", Value = " + value);
40 }
41 } catch (Exception exception) {
42 Log(exception.Message);
43 }
44 }
45 }
46}