Skip to content

Commit

Permalink
Plugin API: Add RmLog and RmLogF functions
Browse files Browse the repository at this point in the history
These functions take a `void* rm` parameter that is used to populate the Source field in the log.
  • Loading branch information
poiru committed Oct 21, 2013
1 parent f99418d commit c2530b3
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
39 changes: 34 additions & 5 deletions Library/Export.cpp
Expand Up @@ -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)
{
Expand Down
6 changes: 4 additions & 2 deletions Library/Exports.def
@@ -1,14 +1,16 @@
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 '<ExcludeTests>true</ExcludeTests>' in Rainmeter.props first to minimize the .lib size.
RmReadString
RmReadFormula
RmReplaceVariables
RmPathToAbsolute
RmExecute
RmGet
RmLog
RmLogF
LSLog
ReadConfigString
PluginBridge
Expand Down
13 changes: 12 additions & 1 deletion Library/Logger.cpp
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions Library/Logger.h
Expand Up @@ -61,6 +61,7 @@ class Logger
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; }
Expand Down
4 changes: 3 additions & 1 deletion Library/Section.h
Expand Up @@ -55,7 +55,9 @@ class __declspec(novtable) Section : public Group

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
Expand Down
6 changes: 5 additions & 1 deletion Plugins/API/RainmeterAPI.h
Expand Up @@ -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
Expand Down
Binary file modified Plugins/API/x32/Rainmeter.lib
Binary file not shown.
Binary file modified Plugins/API/x64/Rainmeter.lib
Binary file not shown.

0 comments on commit c2530b3

Please sign in to comment.