Skip to content

MSVC symbol decorators #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using namespace std;
@brief Mutex for serializing access to global logging state
@ingroup logtools
*/
mutex g_log_mutex;
EXPORT_SYMBOL mutex g_log_mutex;

/**
@brief The current indentation level
Expand All @@ -59,21 +59,21 @@ __thread unsigned int g_logIndentLevel = 0;

@ingroup logtools
*/
vector<unique_ptr<LogSink>> g_log_sinks;
EXPORT_SYMBOL vector<unique_ptr<LogSink>> g_log_sinks;

/**
@brief If set, STDLogSink will only write to stdout even for error/warning severity and never use stderr

@ingroup logtools
*/
bool g_logToStdoutAlways = false;
EXPORT_SYMBOL bool g_logToStdoutAlways = false;

/**
@brief Set of classes or class::function for high verbosity trace messages

@ingroup logtools
*/
set<string> g_trace_filters;
EXPORT_SYMBOL set<string> g_trace_filters;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// String formatting
Expand Down
45 changes: 27 additions & 18 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
#include <thread>
#undef ERROR
#define __thread __declspec(thread)
#define EXPORT_SYMBOL __declspec(dllexport)
#define IMPORT_SYMBOL _declspec(dllimport)
#else
#define EXPORT_SYMBOL
#define IMPORT_SYMBOL
#endif

/**
Expand Down Expand Up @@ -84,7 +89,7 @@ extern __thread unsigned int g_logIndentLevel;
@brief Base class for all log sinks
@ingroup liblog
*/
class LogSink
class EXPORT_SYMBOL LogSink
{
public:
LogSink(Severity min_severity = Severity::VERBOSE)
Expand Down Expand Up @@ -135,7 +140,7 @@ class LogSink
@brief A log sink writing to stdout/stderr depending on severity
@ingroup liblog
*/
class STDLogSink : public LogSink
class EXPORT_SYMBOL STDLogSink : public LogSink
{
public:
STDLogSink(Severity min_severity = Severity::VERBOSE);
Expand All @@ -152,7 +157,7 @@ class STDLogSink : public LogSink
@brief A STDLogSink that colorizes "warning" or "error" keywords
@ingroup liblog
*/
class ColoredSTDLogSink : public STDLogSink
class EXPORT_SYMBOL ColoredSTDLogSink : public STDLogSink
{
public:
ColoredSTDLogSink(Severity min_severity = Severity::VERBOSE);
Expand All @@ -171,7 +176,7 @@ class ColoredSTDLogSink : public STDLogSink
@brief A log sink writing to a FILE* file handle
@ingroup liblog
*/
class FILELogSink : public LogSink
class EXPORT_SYMBOL FILELogSink : public LogSink
{
public:
FILELogSink(FILE *f, bool line_buffered = false, Severity min_severity = Severity::VERBOSE);
Expand All @@ -184,17 +189,17 @@ class FILELogSink : public LogSink
FILE *m_file;
};

extern std::mutex g_log_mutex;
extern std::vector<std::unique_ptr<LogSink>> g_log_sinks;
extern std::set<std::string> g_trace_filters;
extern IMPORT_SYMBOL std::mutex g_log_mutex;
extern IMPORT_SYMBOL std::vector<std::unique_ptr<LogSink>> g_log_sinks;
extern IMPORT_SYMBOL std::set<std::string> g_trace_filters;

/**
@brief RAII wrapper for log indentation
@ingroup liblog

Log messages are indented once for each LogIndenter object in the call stack.
*/
class LogIndenter
class EXPORT_SYMBOL LogIndenter
{
public:
LogIndenter();
Expand All @@ -206,7 +211,7 @@ class LogIndenter
@brief Helper function for parsing arguments that use common syntax
@ingroup liblog
*/
bool ParseLoggerArguments(
bool EXPORT_SYMBOL ParseLoggerArguments(
int& i,
int argc,
char* argv[],
Expand All @@ -219,12 +224,16 @@ bool ParseLoggerArguments(
#else
#define ATTR_FORMAT(n, m) __attribute__((__format__ (__printf__, n, m)))
#endif
#define ATTR_NORETURN_PRE
#define ATTR_NORETURN __attribute__((noreturn))
#else
//FIXME on MSVC/Windows
#if _MSC_VER
// FIXME - doesn't seem to be any equivalent to __attribute__((__format__())) in MSVC
#define ATTR_FORMAT(n, m)
#define ATTR_NORETURN_PRE __declspec(noreturn)
#define ATTR_NORETURN
#endif
#endif

/**
\def(LogTrace(...)
Expand All @@ -241,16 +250,16 @@ bool ParseLoggerArguments(
#define LogTrace(...) LogDebugTrace(__func__, __VA_ARGS__)
#endif

ATTR_FORMAT(1, 2) void LogVerbose(const char *format, ...);
ATTR_FORMAT(1, 2) void LogNotice(const char *format, ...);
ATTR_FORMAT(1, 2) void LogWarning(const char *format, ...);
ATTR_FORMAT(1, 2) void LogError(const char *format, ...);
ATTR_FORMAT(1, 2) void LogDebug(const char *format, ...);
ATTR_FORMAT(2, 3) void LogDebugTrace(const char* function, const char *format, ...);
ATTR_FORMAT(1, 2) ATTR_NORETURN void LogFatal(const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL void LogVerbose(const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL void LogNotice(const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL void LogWarning(const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL void LogError(const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL void LogDebug(const char *format, ...);
ATTR_FORMAT(2, 3) EXPORT_SYMBOL void LogDebugTrace(const char *function, const char *format, ...);
ATTR_FORMAT(1, 2) EXPORT_SYMBOL ATTR_NORETURN void LogFatal(const char *format, ...);

///Just print the message at given log level, don't do anything special for warnings or errors
ATTR_FORMAT(2, 3) void Log(Severity severity, const char *format, ...);
ATTR_FORMAT(2, 3) EXPORT_SYMBOL void Log(Severity severity, const char *format, ...);

#undef ATTR_FORMAT
#undef ATTR_NORETURN
Expand Down