SBLogger.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class SBLogger
  6. {
  7. private static bool debug = false;
  8. private string tag;
  9. public SBLogger(string tag)
  10. {
  11. this.tag = "[" + tag + "]";
  12. }
  13. public void Log(object info)
  14. {
  15. if (!debug) return;
  16. JCUnityLib.CoroutineStarter.Start(SendToServer(0, info));
  17. }
  18. public void Warn(object info)
  19. {
  20. if (!debug) return;
  21. JCUnityLib.CoroutineStarter.Start(SendToServer(1, info));
  22. }
  23. public void Error(object info)
  24. {
  25. if (!debug) return;
  26. JCUnityLib.CoroutineStarter.Start(SendToServer(2, info));
  27. }
  28. IEnumerator SendToServer(int level, object info)
  29. {
  30. long time = JCUnityLib.TimeUtils.GetTimestamp();
  31. string txt = this.tag + " " + info;
  32. yield return null;
  33. if (level == 0) Debug.Log(txt);
  34. else if (level == 1) Debug.LogWarning(txt);
  35. else if (level == 2) Debug.LogError(txt);
  36. int uid = LoginMgr.myUserInfo.id;
  37. if (uid > 0) {
  38. UserPlayer.ins?.call("sbLog", uid, time, tag, info.ToString());
  39. }
  40. }
  41. }