Plugin API: Add RmLog and RmLogF functions

These functions take a `void* rm` parameter that is used to populate the Source field in the log.
This commit is contained in:
Birunthan Mohanathas 2013-10-21 18:04:13 +03:00
parent f99418dd2d
commit c2530b3761
8 changed files with 59 additions and 10 deletions

View File

@ -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 // Ignore Debug messages from plugins unless in debug mode.
if (nLevel != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
{ {
GetLogger().Log((Logger::Level)nLevel, L"", pszMessage); GetLogger().Log((Logger::Level)level, L"", message);
} }
return TRUE; 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! // Deprecated!
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue) LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
{ {

View File

@ -1,7 +1,7 @@
LIBRARY LIBRARY
EXPORTS EXPORTS
; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\x32 and Plugins\API\x64 ; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\{x32,x64} must be
; must be replaced by the corresponding file in Library\x32\Release and Library\x64\Release. ; replaced by the corresponding file in {x32,x64}-Release\Obj\Library.
; Set '<ExcludeTests>true</ExcludeTests>' in Rainmeter.props first to minimize the .lib size. ; Set '<ExcludeTests>true</ExcludeTests>' in Rainmeter.props first to minimize the .lib size.
RmReadString RmReadString
RmReadFormula RmReadFormula
@ -9,6 +9,8 @@ EXPORTS
RmPathToAbsolute RmPathToAbsolute
RmExecute RmExecute
RmGet RmGet
RmLog
RmLogF
LSLog LSLog
ReadConfigString ReadConfigString
PluginBridge PluginBridge

View File

@ -234,7 +234,7 @@ void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_lis
delete [] buffer; delete [] buffer;
} }
void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) std::wstring GetSectionSourceString(Section* section)
{ {
std::wstring source; std::wstring source;
if (section) if (section)
@ -250,7 +250,18 @@ void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* fo
source += section->GetOriginalName(); source += section->GetOriginalName();
source += L']'; 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); GetLogger().LogVF(level, source.c_str(), format, args);
} }

View File

@ -61,6 +61,7 @@ public:
void Log(Level level, const WCHAR* source, const WCHAR* msg); void Log(Level level, const WCHAR* source, const WCHAR* msg);
void LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args); 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 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); void LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args);
const std::wstring& GetLogFilePath() { return m_LogFilePath; } const std::wstring& GetLogFilePath() { return m_LogFilePath; }

View File

@ -55,7 +55,9 @@ protected:
bool UpdateCounter(); 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 bool m_DynamicVariables; // If true, the section contains dynamic variables
int m_UpdateDivider; // Divider for the update int m_UpdateDivider; // Divider for the update

View File

@ -56,7 +56,11 @@ enum RmGetType
RMG_SKINWINDOWHANDLE = 4 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 // Wrapper functions

Binary file not shown.

Binary file not shown.