Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
7.4 KiB

  1. //========= Copyright (c), Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "stdafx.h"
  8. #include "steamextra/gamecoordinator/igamecoordinatorhost.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //-----------------------------------------------------------------------------
  12. // Maximum length of a sprintf'ed logging message.
  13. //-----------------------------------------------------------------------------
  14. const int MAX_LOGGING_MESSAGE_LENGTH = 2048;
  15. namespace GCSDK
  16. {
  17. int g_nMaxSpewLevel = 4;
  18. int g_nMaxLogLevel = 4;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Sends an event back to the GC host for logging
  21. // Input: pchGroupName - group to log to
  22. // spewType - the type of the message
  23. // iLevel - level of spew ( 0..4 )
  24. // iLevelLog - level for logging
  25. // pchMsg - printf format
  26. //-----------------------------------------------------------------------------
  27. void EmitBaseMessageV( const char *pchGroupName, SpewType_t spewType, int iSpewLevel, int iLevelLog, const char *pchMsg, va_list vaArgs )
  28. {
  29. VPROF_BUDGET( "GCHost", VPROF_BUDGETGROUP_STEAM );
  30. char pchBuf[ MAX_LOGGING_MESSAGE_LENGTH ];
  31. Q_vsnprintf( pchBuf, MAX_LOGGING_MESSAGE_LENGTH, pchMsg, vaArgs );
  32. #ifdef GC
  33. // !FIXME! DOTAMERGE
  34. // // If this is coming from the context of a job, then allow that job to
  35. // // override our emit via a specified handler.
  36. // if ( g_pJobCur )
  37. // {
  38. // IJobEmitSpewHandler *pHandler = g_pJobCur->GetEmitSpewHandler();
  39. // if ( pHandler )
  40. // {
  41. // bool bOutputSpew = pHandler->OnEmitSpew( pchGroupName, spewType, iSpewLevel, iLevelLog, pchBuf );
  42. // if ( !bOutputSpew )
  43. // {
  44. // return;
  45. // }
  46. // }
  47. // }
  48. {
  49. VPROF_BUDGET( "GCHost - EmitMessage", VPROF_BUDGETGROUP_STEAM );
  50. // !FIXME! DOTAMERGE
  51. //GGCInterface()->EmitSpew( pchGroupName, spewType, iSpewLevel, iLevelLog, pchBuf );
  52. GGCHost()->EmitMessage( pchGroupName, spewType, iSpewLevel, iLevelLog, pchBuf );
  53. }
  54. #else
  55. // TODO: Actually log it
  56. DevMsg( "%s", pchBuf );
  57. #endif
  58. }
  59. //similar to the above, but takes in a group, and handles filtering messages out that are disabled, and extracting other info from the group
  60. void EmitBaseMessageV( const CGCEmitGroup& Group, SpewType_t spewType, int iConsoleLevel, int iLogLevel, const char *pchMsg, va_list vaArgs )
  61. {
  62. int iClampConsoleLevel = ( iConsoleLevel <= MIN( Group.GetConsoleLevel(), g_nMaxSpewLevel ) ) ? SPEW_ALWAYS : SPEW_NEVER;
  63. int iClampLogLevel = ( iLogLevel <= MIN( Group.GetLogLevel(), g_nMaxLogLevel ) ) ? LOG_ALWAYS : LOG_NEVER;
  64. if( ( iClampConsoleLevel != SPEW_NEVER ) || ( iClampLogLevel != LOG_NEVER ) )
  65. EmitBaseMessageV( Group.GetName(), spewType, iClampConsoleLevel, iClampLogLevel, pchMsg, vaArgs );
  66. }
  67. //------------------------------
  68. // AssertError
  69. void CGCEmitGroup::Internal_AssertError( const char *pchMsg, ... ) const
  70. {
  71. va_list args;
  72. va_start( args, pchMsg );
  73. AssertErrorV( pchMsg, args );
  74. va_end( args );
  75. }
  76. void CGCEmitGroup::AssertErrorV( const char *pchMsg, va_list vaArgs ) const
  77. {
  78. EmitBaseMessageV( *this, SPEW_ASSERT, 1, 1, pchMsg, vaArgs );
  79. }
  80. //------------------------------
  81. // Error
  82. void CGCEmitGroup::Internal_Error( const char *pchMsg, ... ) const
  83. {
  84. va_list args;
  85. va_start( args, pchMsg );
  86. ErrorV( pchMsg, args );
  87. va_end( args );
  88. }
  89. void CGCEmitGroup::ErrorV( const char *pchMsg, va_list vaArgs ) const
  90. {
  91. EmitBaseMessageV( *this, SPEW_ERROR, 1, 1, pchMsg, vaArgs );
  92. }
  93. //------------------------------
  94. // Warning
  95. void CGCEmitGroup::Internal_Warning( const char *pchMsg, ... ) const
  96. {
  97. va_list args;
  98. va_start( args, pchMsg );
  99. WarningV( pchMsg, args );
  100. va_end( args );
  101. }
  102. void CGCEmitGroup::WarningV( const char *pchMsg, va_list vaArgs ) const
  103. {
  104. EmitBaseMessageV( *this, SPEW_WARNING, 2, 2, pchMsg, vaArgs );
  105. }
  106. //------------------------------
  107. // Msg
  108. void CGCEmitGroup::Internal_Msg( const char *pchMsg, ... ) const
  109. {
  110. va_list args;
  111. va_start( args, pchMsg );
  112. MsgV( pchMsg, args );
  113. va_end( args );
  114. }
  115. void CGCEmitGroup::MsgV( const char *pchMsg, va_list vaArgs ) const
  116. {
  117. EmitBaseMessageV( *this, SPEW_MESSAGE, 3, 3, pchMsg, vaArgs );
  118. }
  119. //------------------------------
  120. // Verbose
  121. void CGCEmitGroup::Internal_Verbose( const char *pchMsg, ... ) const
  122. {
  123. va_list args;
  124. va_start( args, pchMsg );
  125. VerboseV( pchMsg, args );
  126. va_end( args );
  127. }
  128. void CGCEmitGroup::VerboseV( const char *pchMsg, va_list vaArgs ) const
  129. {
  130. EmitBaseMessageV( *this, SPEW_MESSAGE, 4, 4, pchMsg, vaArgs );
  131. }
  132. //------------------------------
  133. // Verbose
  134. void CGCEmitGroup::Internal_BoldMsg( const char *pchMsg, ... ) const
  135. {
  136. va_list args;
  137. va_start( args, pchMsg );
  138. BoldMsgV( pchMsg, args );
  139. va_end( args );
  140. }
  141. void CGCEmitGroup::BoldMsgV( const char *pchMsg, va_list vaArgs ) const
  142. {
  143. // !FIXME! DOTAMERGE
  144. //EmitBaseMessageV( *this, SPEW_BOLD_MESSAGE, 1, 1, pchMsg, vaArgs );
  145. EmitBaseMessageV( *this, SPEW_MESSAGE, 1, 1, pchMsg, vaArgs );
  146. }
  147. //------------------------------
  148. // General Emit
  149. void CGCEmitGroup::Internal_Emit( EMsgLevel eLvl, PRINTF_FORMAT_STRING const char *pchMsg, ... ) const
  150. {
  151. va_list args;
  152. va_start( args, pchMsg );
  153. EmitV( eLvl, pchMsg, args );
  154. va_end( args );
  155. }
  156. void CGCEmitGroup::EmitV( EMsgLevel eLvl, PRINTF_FORMAT_STRING const char *pchMsg, va_list vaArgs ) const
  157. {
  158. switch( eLvl )
  159. {
  160. case kMsg_Error: ErrorV( pchMsg, vaArgs ); break;
  161. case kMsg_Warning: WarningV( pchMsg, vaArgs ); break;
  162. case kMsg_Msg: MsgV( pchMsg, vaArgs ); break;
  163. case kMsg_Verbose: VerboseV( pchMsg, vaArgs ); break;
  164. default:
  165. AssertMsg1( false, "Unexpected error level of %d provided to GCEmitGroup::Emit", eLvl );
  166. break;
  167. }
  168. }
  169. //---------------------------------------------------------------------
  170. // Legacy Interface
  171. //---------------------------------------------------------------------
  172. void EGInternal_EmitInfo( const CGCEmitGroup& Group, int iLevel, int iLevelLog, const char *pchMsg, ... )
  173. {
  174. va_list args;
  175. va_start( args, pchMsg );
  176. EmitBaseMessageV( Group, SPEW_MESSAGE, iLevel, iLevelLog, pchMsg, args );
  177. va_end( args );
  178. }
  179. void EmitInfoV( const CGCEmitGroup& Group, int iLevel, int iLevelLog, const char *pchMsg, va_list vaArgs )
  180. {
  181. EmitBaseMessageV( Group, SPEW_MESSAGE, iLevel, iLevelLog, pchMsg, vaArgs );
  182. }
  183. void EmitWarning( const CGCEmitGroup& Group, int iLevel, const char *pchMsg, ... )
  184. {
  185. va_list args;
  186. va_start( args, pchMsg );
  187. EmitBaseMessageV( Group, SPEW_WARNING, iLevel, iLevel, pchMsg, args );
  188. va_end( args );
  189. }
  190. void EmitError( const CGCEmitGroup& Group, const char *pchMsg, ... )
  191. {
  192. va_list args;
  193. va_start( args, pchMsg );
  194. EmitBaseMessageV( Group, SPEW_ERROR, 1, 1, pchMsg, args );
  195. va_end( args );
  196. }
  197. // Emit an assert-like error, generating a minidump
  198. void EmitAssertError( const CGCEmitGroup& Group, const char *pchMsg, ... )
  199. {
  200. va_list args;
  201. va_start( args, pchMsg );
  202. EmitBaseMessageV( Group, SPEW_ASSERT, 1, 1, pchMsg, args );
  203. va_end( args );
  204. }
  205. //legacy group types
  206. DECLARE_GC_EMIT_GROUP( SPEW_SYSTEM_MISC, system );
  207. DECLARE_GC_EMIT_GROUP( SPEW_JOB, job );
  208. DECLARE_GC_EMIT_GROUP( SPEW_CONSOLE, console );
  209. DECLARE_GC_EMIT_GROUP( SPEW_GC, gc );
  210. DECLARE_GC_EMIT_GROUP( SPEW_SQL, sql );
  211. DECLARE_GC_EMIT_GROUP( SPEW_NETWORK, network );
  212. DECLARE_GC_EMIT_GROUP( SPEW_SHAREDOBJ, sharedobj );
  213. DECLARE_GC_EMIT_GROUP( SPEW_MICROTXN, microtxn );
  214. DECLARE_GC_EMIT_GROUP( SPEW_PROMO, promo );
  215. DECLARE_GC_EMIT_GROUP( SPEW_PKGITEM, pkgitem );
  216. DECLARE_GC_EMIT_GROUP( SPEW_ECONOMY, econ );
  217. DECLARE_GC_EMIT_GROUP( SPEW_THREADS, threads );
  218. } // namespace GCSDK