logtemplates.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. typedef Param3<string, string, string> LogTemplate;
  2. typedef int LogTemplateID;
  3. /*
  4. * OBSOLETE: kept for possible backward compatibility only
  5. */
  6. class LogTemplates
  7. {
  8. static private ref map<LogTemplateID, ref LogTemplate> m_LogTemplates;
  9. static private void RegisterLogTamplate(LogTemplateID template_id, string author, string plugin, string label)
  10. {
  11. if ( m_LogTemplates == NULL )
  12. {
  13. m_LogTemplates = new map<LogTemplateID, ref LogTemplate>;
  14. }
  15. if ( m_LogTemplates.Contains(template_id) )
  16. {
  17. Debug.Log("Template ID: "+string.ToString(template_id)+" is alredy exist!", "LogTemplate.h -> OnInit()", "System", "Template Registration", "None");
  18. }
  19. else
  20. {
  21. LogTemplate params = new LogTemplate(author, plugin, label);
  22. m_LogTemplates.Set(template_id, params);
  23. }
  24. }
  25. // Steps to register of new log template:
  26. // 1.) Crete new LogTemplateID in below of this comment.
  27. // 2.) Set Template Name in format TEMPLATE_[CUSTOM NAME] => TEMPLATE_MY_LOG
  28. // 3.) Set Template ID which is your id + your custom id => + CustomID(0) = 50190
  29. //////////////////////////////////////////////////////////////
  30. // Template Name Template ID
  31. static LogTemplateID TEMPLATE_UNKNOWN = 0;
  32. static LogTemplateID TEMPLATE_JANOSIK = 1;
  33. static LogTemplateID TEMPLATE_PLAYER_WEIGHT = 2;
  34. static LogTemplateID TEMPLATE_BROADCAST = 3;
  35. static void Init()
  36. {
  37. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. ////////Register Log templates//////////////////////////////////////////////////////////////////////////////////////
  39. // | Template Name | author | plugin | label ////
  40. RegisterLogTamplate( TEMPLATE_UNKNOWN ,"Unknown" ,"Unknown" ,"Unknown" );//
  41. RegisterLogTamplate( TEMPLATE_JANOSIK ,"Janosik" ,"GUI" ,"None" );//
  42. RegisterLogTamplate( TEMPLATE_PLAYER_WEIGHT ,"Unknown" ,"PlayerBase" ,"Weight" );//
  43. RegisterLogTamplate( TEMPLATE_BROADCAST ,"Unknown" ,"PluginMessageManager" ,"Broadcast" );//
  44. }
  45. static LogTemplate GetTemplate(LogTemplateID template_id)
  46. {
  47. if ( m_LogTemplates && m_LogTemplates.Contains(template_id) )
  48. {
  49. return m_LogTemplates.Get(template_id);
  50. }
  51. Debug.Log("Template ID: "+string.ToString(template_id)+" does not exist!", "LogTemplate.h -> GetTemplate()", "System", "Get Log Template", "None");
  52. return NULL;
  53. }
  54. }
  55. /**
  56. \brief Creates debug log (optional) from LogTemplate which are registred
  57. \param template_id \p LogTemplateID ID of LogTemplate which was registred in proto/Logtemplate.h -> "class LogTemplates"
  58. \param message \p string Debug message for log
  59. \return \p void
  60. @code
  61. Log("This is some debug log message", TEMPLATE_JINDRICH);
  62. >> output to scriptExt.log (for GamutLogViewer)
  63. @endcode
  64. */
  65. void Log(string message, LogTemplateID template_id = 0)
  66. {
  67. LogTemplate log_template = LogTemplates.GetTemplate(template_id);
  68. Debug.Log(message, log_template.param2, log_template.param1, log_template.param3);
  69. }
  70. /**
  71. \brief Creates info log (optional) from LogTemplate which are registred
  72. \param template_id \p LogTemplateID ID of LogTemplate which was registred in proto/Logtemplate.h -> "class LogTemplates"
  73. \param message \p string Info message for log
  74. \return \p void
  75. @code
  76. LogInfo("This is some info log message", TEMPLATE_JINDRICH);
  77. >> output to scriptExt.log (for GamutLogViewer)
  78. @endcode
  79. */
  80. void LogInfo(string message, LogTemplateID template_id = 0)
  81. {
  82. LogTemplate log_template = LogTemplates.GetTemplate(template_id);
  83. Debug.LogInfo(message, log_template.param2, log_template.param1, log_template.param3);
  84. }
  85. /**
  86. \brief Creates warning log (optional) from LogTemplate which are registred
  87. \param template_id \p LogTemplateID ID of LogTemplate which was registred in proto/Logtemplate.h -> "class LogTemplates"
  88. \param message \p string Warning message for log
  89. \return \p void
  90. @code
  91. LogT(TEMPLATE_JINDRICH, "This is some warning log message");
  92. >> output to scriptExt.log (for GamutLogViewer)
  93. @endcode
  94. */
  95. void LogWarning(string message, LogTemplateID template_id = 0)
  96. {
  97. LogTemplate log_template = LogTemplates.GetTemplate(template_id);
  98. Debug.LogWarning(message, log_template.param2, log_template.param1, log_template.param3);
  99. }
  100. /**
  101. \brief Creates error log (optional) from LogTemplate which are registred
  102. \param template_id \p LogTemplateID ID of LogTemplate which was registred in proto/Logtemplate.h -> "class LogTemplates"
  103. \param message \p string Error message for log
  104. \return \p void
  105. @code
  106. LogT(TEMPLATE_JINDRICH, "This is some error log message");
  107. >> output to scriptExt.log (for GamutLogViewer)
  108. @endcode
  109. */
  110. void LogError(string message, LogTemplateID template_id = 0)
  111. {
  112. LogTemplate log_template = LogTemplates.GetTemplate(template_id);
  113. Debug.LogError(message, log_template.param2, log_template.param1, log_template.param3);
  114. }
  115. void SQFPrint(string sqf_msg)
  116. {
  117. Print(sqf_msg);
  118. }
  119. void SQFLog(string sqf_msg)
  120. {
  121. Log(sqf_msg);
  122. }