Log.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using UnityEngine;
  5. namespace Base
  6. {
  7. public static class Log
  8. {
  9. #if !UNITY_EDITOR
  10. public static readonly StreamWriter sw;
  11. static Log()
  12. {
  13. sw = new StreamWriter($"./Game_Data/log-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}.txt", false, Encoding.Unicode, 1024);
  14. }
  15. #endif
  16. public static void Warning(string msg)
  17. {
  18. DateTime dateTime = DateTime.Now;
  19. string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
  20. #if !UNITY_EDITOR
  21. sw.WriteLine(s);
  22. #endif
  23. UnityEngine.Debug.LogWarning(s);
  24. }
  25. public static void Info(string msg)
  26. {
  27. DateTime dateTime = DateTime.Now;
  28. string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
  29. #if !UNITY_EDITOR
  30. sw.WriteLine(s);
  31. #else
  32. UnityEngine.Debug.Log(s);
  33. #endif
  34. }
  35. public static void Error(string msg)
  36. {
  37. DateTime dateTime = DateTime.Now;
  38. string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
  39. UnityEngine.Debug.LogError(s);
  40. }
  41. public static void Debug(string msg)
  42. {
  43. #if UNITY_EDITOR
  44. DateTime dateTime = DateTime.Now;
  45. string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
  46. UnityEngine.Debug.Log(s);
  47. #endif
  48. }
  49. }
  50. }