diff --git a/Library/Export.cpp b/Library/Export.cpp index ebf48a7b..0738cba5 100644 --- a/Library/Export.cpp +++ b/Library/Export.cpp @@ -117,19 +117,48 @@ void __stdcall RmExecute(void* skin, LPCWSTR command) } } -BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage) +BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message) { - NULLCHECK(pszMessage); + NULLCHECK(message); - // Ignore Level::Debug messages from plugins unless in debug mode - if (nLevel != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) { - GetLogger().Log((Logger::Level)nLevel, L"", pszMessage); + GetLogger().Log((Logger::Level)level, L"", message); } return TRUE; } +void __stdcall RmLog(void* rm, int level, LPCWSTR message) +{ + NULLCHECK(message); + + MeasurePlugin* measure = (MeasurePlugin*)rm; + + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + { + GetLogger().LogSection((Logger::Level)level, measure, message); + } +} + +void RmLogF(void* rm, int level, LPCWSTR format, ...) +{ + NULLCHECK(format); + + MeasurePlugin* measure = (MeasurePlugin*)rm; + + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + { + va_list args; + va_start(args, format); + GetLogger().LogSectionVF((Logger::Level)level, measure, format, args); + va_end(args); + } +} + // Deprecated! LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue) { diff --git a/Library/Exports.def b/Library/Exports.def index 6ca08df6..58b76fc1 100644 --- a/Library/Exports.def +++ b/Library/Exports.def @@ -1,7 +1,7 @@ LIBRARY EXPORTS - ; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\x32 and Plugins\API\x64 - ; must be replaced by the corresponding file in Library\x32\Release and Library\x64\Release. + ; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\{x32,x64} must be + ; replaced by the corresponding file in {x32,x64}-Release\Obj\Library. ; Set 'true' in Rainmeter.props first to minimize the .lib size. RmReadString RmReadFormula @@ -9,6 +9,8 @@ EXPORTS RmPathToAbsolute RmExecute RmGet + RmLog + RmLogF LSLog ReadConfigString PluginBridge diff --git a/Library/Logger.cpp b/Library/Logger.cpp index 4429f50a..4f077ed4 100644 --- a/Library/Logger.cpp +++ b/Library/Logger.cpp @@ -234,7 +234,7 @@ void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_lis delete [] buffer; } -void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) +std::wstring GetSectionSourceString(Section* section) { std::wstring source; if (section) @@ -250,7 +250,18 @@ void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* fo source += section->GetOriginalName(); source += L']'; } + return source; +} +void Logger::LogSection(Logger::Level level, Section* section, const WCHAR* message) +{ + const std::wstring source = GetSectionSourceString(section); + GetLogger().Log(level, source.c_str(), message); +} + +void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) +{ + const std::wstring source = GetSectionSourceString(section); GetLogger().LogVF(level, source.c_str(), format, args); } diff --git a/Library/Logger.h b/Library/Logger.h index 45f548ab..645da3b3 100644 --- a/Library/Logger.h +++ b/Library/Logger.h @@ -61,6 +61,7 @@ public: void Log(Level level, const WCHAR* source, const WCHAR* msg); void LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args); void LogMeterWindowVF(Logger::Level level, MeterWindow* meterWindow, const WCHAR* format, va_list args); + void LogSection(Logger::Level level, Section* section, const WCHAR* message); void LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args); const std::wstring& GetLogFilePath() { return m_LogFilePath; } diff --git a/Library/Section.h b/Library/Section.h index 04070e29..78406d03 100644 --- a/Library/Section.h +++ b/Library/Section.h @@ -55,7 +55,9 @@ protected: bool UpdateCounter(); - const std::wstring m_Name; // Name of this Section + // Plugins may access this string through RmGetMeasureName(). This should never changed be to + // ensure thread-safety. + const std::wstring m_Name; bool m_DynamicVariables; // If true, the section contains dynamic variables int m_UpdateDivider; // Divider for the update diff --git a/Plugins/API/RainmeterAPI.h b/Plugins/API/RainmeterAPI.h index d74d08b3..fae3a835 100644 --- a/Plugins/API/RainmeterAPI.h +++ b/Plugins/API/RainmeterAPI.h @@ -56,7 +56,11 @@ enum RmGetType RMG_SKINWINDOWHANDLE = 4 }; -LIBRARY_EXPORT BOOL LSLog(int type, LPCWSTR unused, LPCWSTR message); +LIBRARY_EXPORT void __stdcall RmLog(void* rm, int level, LPCWSTR message); + +LIBRARY_EXPORT void __cdecl RmLogF(void* rm, int level, LPCWSTR format, ...); + +LIBRARY_EXPORT BOOL __cdecl LSLog(int level, LPCWSTR unused, LPCWSTR message); // // Wrapper functions diff --git a/Plugins/API/x32/Rainmeter.lib b/Plugins/API/x32/Rainmeter.lib index 47bcfa30..f7d3cb66 100644 Binary files a/Plugins/API/x32/Rainmeter.lib and b/Plugins/API/x32/Rainmeter.lib differ diff --git a/Plugins/API/x64/Rainmeter.lib b/Plugins/API/x64/Rainmeter.lib index b45859fd..2834474e 100644 Binary files a/Plugins/API/x64/Rainmeter.lib and b/Plugins/API/x64/Rainmeter.lib differ