0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

(Core) ETW logging: replaced std::cerr with macro EASY_ETW_LOG to make possible to change output destination

This commit is contained in:
Victor Zarubkin 2016-12-21 21:49:29 +03:00
parent 649eda5641
commit 5977dbda11

View File

@ -58,7 +58,10 @@
#include <Psapi.h> #include <Psapi.h>
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
#include <iostream> # include <iostream>
# ifndef EASY_ETW_LOG
# define EASY_ETW_LOG ::std::cerr
# endif
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -275,7 +278,7 @@ namespace profiler {
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
if (!success) if (!success)
::std::cerr << "Warning: EasyProfiler failed to set " << _privelegeName << " privelege for the application.\n"; EASY_ETW_LOG << "Warning: EasyProfiler failed to set " << _privelegeName << " privelege for the application.\n";
#endif #endif
return success; return success;
@ -295,7 +298,7 @@ namespace profiler {
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
const bool success = setPrivilege(hToken, SE_DEBUG_NAME); const bool success = setPrivilege(hToken, SE_DEBUG_NAME);
if (!success) if (!success)
::std::cerr << "Warning: Some context switch events could not get process name.\n"; EASY_ETW_LOG << "Warning: Some context switch events could not get process name.\n";
#else #else
setPrivilege(hToken, SE_DEBUG_NAME); setPrivilege(hToken, SE_DEBUG_NAME);
#endif #endif
@ -305,7 +308,7 @@ namespace profiler {
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
else else
{ {
::std::cerr << "Warning: EasyProfiler failed to open process to adjust priveleges.\n"; EASY_ETW_LOG << "Warning: EasyProfiler failed to open process to adjust priveleges.\n";
} }
#endif #endif
} }
@ -358,26 +361,26 @@ namespace profiler {
} }
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_ALREADY_EXISTS. To stop another session execute cmd: logman stop \"" << KERNEL_LOGGER_NAME << "\" -ets\n"; EASY_ETW_LOG << "Error: EasyProfiler.ETW not launched: ERROR_ALREADY_EXISTS. To stop another session execute cmd: logman stop \"" << KERNEL_LOGGER_NAME << "\" -ets\n";
#endif #endif
return EVENT_TRACING_WAS_LAUNCHED_BY_SOMEBODY_ELSE; return EVENT_TRACING_WAS_LAUNCHED_BY_SOMEBODY_ELSE;
} }
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_ACCESS_DENIED. Try to launch your application as Administrator.\n"; EASY_ETW_LOG << "Error: EasyProfiler.ETW not launched: ERROR_ACCESS_DENIED. Try to launch your application as Administrator.\n";
#endif #endif
return EVENT_TRACING_NOT_ENOUGH_ACCESS_RIGHTS; return EVENT_TRACING_NOT_ENOUGH_ACCESS_RIGHTS;
case ERROR_BAD_LENGTH: case ERROR_BAD_LENGTH:
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_BAD_LENGTH. It seems that your KERNEL_LOGGER_NAME differs from \"" << m_properties.sessionName << "\". Try to re-compile easy_profiler or contact EasyProfiler developers.\n"; EASY_ETW_LOG << "Error: EasyProfiler.ETW not launched: ERROR_BAD_LENGTH. It seems that your KERNEL_LOGGER_NAME differs from \"" << m_properties.sessionName << "\". Try to re-compile easy_profiler or contact EasyProfiler developers.\n";
#endif #endif
return EVENT_TRACING_BAD_PROPERTIES_SIZE; return EVENT_TRACING_BAD_PROPERTIES_SIZE;
} }
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: StartTrace() returned " << startTraceResult << ::std::endl; EASY_ETW_LOG << "Error: EasyProfiler.ETW not launched: StartTrace() returned " << startTraceResult << ::std::endl;
#endif #endif
return EVENT_TRACING_MISTERIOUS_ERROR; return EVENT_TRACING_MISTERIOUS_ERROR;
} }
@ -418,7 +421,7 @@ namespace profiler {
if (m_openedHandle == INVALID_PROCESSTRACE_HANDLE) if (m_openedHandle == INVALID_PROCESSTRACE_HANDLE)
{ {
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: OpenTrace() returned invalid handle.\n"; EASY_ETW_LOG << "Error: EasyProfiler.ETW not launched: OpenTrace() returned invalid handle.\n";
#endif #endif
return EVENT_TRACING_OPEN_TRACE_ERROR; return EVENT_TRACING_OPEN_TRACE_ERROR;
} }