Logger.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // <copyright file="Logger.cs" company="Google Inc.">
  2. // Copyright (C) 2014 Google 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. // </copyright>
  16. namespace GooglePlayGames.OurUtils
  17. {
  18. using System;
  19. using UnityEngine;
  20. public class Logger
  21. {
  22. private static bool debugLogEnabled = false;
  23. public static bool DebugLogEnabled
  24. {
  25. get
  26. {
  27. return debugLogEnabled;
  28. }
  29. set
  30. {
  31. debugLogEnabled = value;
  32. }
  33. }
  34. private static bool warningLogEnabled = true;
  35. public static bool WarningLogEnabled
  36. {
  37. get
  38. {
  39. return warningLogEnabled;
  40. }
  41. set
  42. {
  43. warningLogEnabled = value;
  44. }
  45. }
  46. public static void d(string msg)
  47. {
  48. if (debugLogEnabled)
  49. {
  50. PlayGamesHelperObject.RunOnGameThread(()=>
  51. Debug.Log(ToLogMessage(string.Empty, "DEBUG", msg)));
  52. }
  53. }
  54. public static void w(string msg)
  55. {
  56. if (warningLogEnabled)
  57. {
  58. PlayGamesHelperObject.RunOnGameThread(()=>
  59. Debug.LogWarning(ToLogMessage("!!!", "WARNING", msg)));
  60. }
  61. }
  62. public static void e(string msg)
  63. {
  64. if (warningLogEnabled)
  65. {
  66. PlayGamesHelperObject.RunOnGameThread(() =>
  67. Debug.LogWarning(ToLogMessage("***", "ERROR", msg)));
  68. }
  69. }
  70. public static string describe(byte[] b)
  71. {
  72. return b == null ? "(null)" : "byte[" + b.Length + "]";
  73. }
  74. private static string ToLogMessage(string prefix, string logType, string msg)
  75. {
  76. return string.Format("{0} [Play Games Plugin DLL] {1} {2}: {3}",
  77. prefix, DateTime.Now.ToString("MM/dd/yy H:mm:ss zzz"), logType, msg);
  78. }
  79. }
  80. }