Log.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // -----------------------------------------------------------------------
  2. // <copyright file="Log.cs" company="">
  3. // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace UnityEngine.U2D.Animation.TriangleNet
  7. {
  8. using System.Collections.Generic;
  9. using Animation.TriangleNet.Logging;
  10. /// <summary>
  11. /// A simple logger, which logs messages to a List.
  12. /// </summary>
  13. /// <remarks>Using singleton pattern as proposed by Jon Skeet.
  14. /// http://csharpindepth.com/Articles/General/Singleton.aspx
  15. /// </remarks>
  16. internal sealed class Log : ILog<LogItem>
  17. {
  18. /// <summary>
  19. /// Log detailed information.
  20. /// </summary>
  21. internal static bool Verbose { get; set; }
  22. private List<LogItem> log = new List<LogItem>();
  23. private LogLevel level = LogLevel.Info;
  24. #region Singleton pattern
  25. private static readonly Log instance = new Log();
  26. // Explicit static constructor to tell C# compiler
  27. // not to mark type as beforefieldinit
  28. static Log() {}
  29. private Log() {}
  30. internal static ILog<LogItem> Instance
  31. {
  32. get
  33. {
  34. return instance;
  35. }
  36. }
  37. #endregion
  38. public void Add(LogItem item)
  39. {
  40. log.Add(item);
  41. }
  42. public void Clear()
  43. {
  44. log.Clear();
  45. }
  46. public void Info(string message)
  47. {
  48. log.Add(new LogItem(LogLevel.Info, message));
  49. }
  50. public void Warning(string message, string location)
  51. {
  52. log.Add(new LogItem(LogLevel.Warning, message, location));
  53. }
  54. public void Error(string message, string location)
  55. {
  56. log.Add(new LogItem(LogLevel.Error, message, location));
  57. }
  58. public IList<LogItem> Data
  59. {
  60. get { return log; }
  61. }
  62. public LogLevel Level
  63. {
  64. get { return level; }
  65. }
  66. }
  67. }