Commit fc507b26 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

Don't try to access XlogFileScopeInfo->category if not supported

Summary: This was breaking Windows builds.

Reviewed By: Orvid

Differential Revision: D5351468

fbshipit-source-id: 3385931b82b11d71d98861fb45efc71a632d470b
parent b7fd076d
...@@ -52,20 +52,6 @@ LogStreamProcessor::LogStreamProcessor( ...@@ -52,20 +52,6 @@ LogStreamProcessor::LogStreamProcessor(
INTERNAL, INTERNAL,
std::string()) {} std::string()) {}
LogStreamProcessor::LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo,
LogLevel level,
folly::StringPiece filename,
unsigned int lineNumber,
AppendType) noexcept
: LogStreamProcessor(
fileScopeInfo,
level,
filename,
lineNumber,
INTERNAL,
std::string()) {}
LogStreamProcessor::LogStreamProcessor( LogStreamProcessor::LogStreamProcessor(
const LogCategory* category, const LogCategory* category,
LogLevel level, LogLevel level,
...@@ -90,13 +76,6 @@ LogCategory* getXlogCategory( ...@@ -90,13 +76,6 @@ LogCategory* getXlogCategory(
} }
return categoryInfo->getCategory(&xlog_detail::xlogFileScopeInfo); return categoryInfo->getCategory(&xlog_detail::xlogFileScopeInfo);
} }
LogCategory* getXlogCategory(XlogFileScopeInfo* fileScopeInfo) {
// By the time a LogStreamProcessor is created, the XlogFileScopeInfo object
// should have already been initialized to perform the log level check.
// Therefore we never need to check if it is initialized here.
return fileScopeInfo->category;
}
} }
/** /**
...@@ -125,12 +104,28 @@ LogStreamProcessor::LogStreamProcessor( ...@@ -125,12 +104,28 @@ LogStreamProcessor::LogStreamProcessor(
message_{std::move(msg)}, message_{std::move(msg)},
stream_{this} {} stream_{this} {}
#ifdef __INCLUDE_LEVEL__
namespace {
LogCategory* getXlogCategory(XlogFileScopeInfo* fileScopeInfo) {
// By the time a LogStreamProcessor is created, the XlogFileScopeInfo object
// should have already been initialized to perform the log level check.
// Therefore we never need to check if it is initialized here.
return fileScopeInfo->category;
}
}
/** /**
* Construct a LogStreamProcessor from an XlogFileScopeInfo. * Construct a LogStreamProcessor from an XlogFileScopeInfo.
* *
* We intentionally define this in LogStreamProcessor.cpp instead of * We intentionally define this in LogStreamProcessor.cpp instead of
* LogStreamProcessor.h to avoid having it inlined at every XLOG() call site, * LogStreamProcessor.h to avoid having it inlined at every XLOG() call site,
* to reduce the emitted code size. * to reduce the emitted code size.
*
* This is only defined if __INCLUDE_LEVEL__ is available. The
* XlogFileScopeInfo APIs are only invoked if we can use __INCLUDE_LEVEL__ to
* tell that an XLOG() statement occurs in a non-header file. For compilers
* that do not support __INCLUDE_LEVEL__, the category information is always
* passed in as XlogCategoryInfo<true> rather than as XlogFileScopeInfo.
*/ */
LogStreamProcessor::LogStreamProcessor( LogStreamProcessor::LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo, XlogFileScopeInfo* fileScopeInfo,
...@@ -146,6 +141,21 @@ LogStreamProcessor::LogStreamProcessor( ...@@ -146,6 +141,21 @@ LogStreamProcessor::LogStreamProcessor(
message_{std::move(msg)}, message_{std::move(msg)},
stream_{this} {} stream_{this} {}
LogStreamProcessor::LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo,
LogLevel level,
folly::StringPiece filename,
unsigned int lineNumber,
AppendType) noexcept
: LogStreamProcessor(
fileScopeInfo,
level,
filename,
lineNumber,
INTERNAL,
std::string()) {}
#endif
/* /*
* We intentionally define the LogStreamProcessor destructor in * We intentionally define the LogStreamProcessor destructor in
* LogStreamProcessor.cpp instead of LogStreamProcessor.h to avoid having it * LogStreamProcessor.cpp instead of LogStreamProcessor.h to avoid having it
......
...@@ -108,39 +108,29 @@ class LogStreamProcessor { ...@@ -108,39 +108,29 @@ class LogStreamProcessor {
AppendType) noexcept; AppendType) noexcept;
/** /**
* LogStreamProcessor constructors for use with XLOG() macros with no extra * LogStreamProcessor constructor for use with a LOG() macro with arguments
* arguments. * to be concatenated with folly::to<std::string>()
* *
* These are defined separately from the above constructor so that the work * Note that the filename argument is not copied. The caller should ensure
* of initializing the XLOG LogCategory data is done in a separate function * that it points to storage that will remain valid for the lifetime of the
* body defined in LogStreamProcessor.cpp. We intentionally want to avoid * LogStreamProcessor. (This is always the case for the __FILE__
* inlining this work at every XLOG() statement, to reduce the emitted code * preprocessor macro.)
* size.
*/ */
template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
XlogCategoryInfo<true>* categoryInfo, const LogCategory* category,
LogLevel level,
folly::StringPiece categoryName,
bool isCategoryNameOverridden,
folly::StringPiece filename,
unsigned int lineNumber,
AppendType) noexcept;
LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo,
LogLevel level,
folly::StringPiece filename,
unsigned int lineNumber,
AppendType) noexcept;
LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo,
LogLevel level, LogLevel level,
folly::StringPiece /* categoryName */,
bool /* isCategoryNameOverridden */,
folly::StringPiece filename, folly::StringPiece filename,
unsigned int lineNumber, unsigned int lineNumber,
AppendType) noexcept AppendType,
: LogStreamProcessor(fileScopeInfo, level, filename, lineNumber, APPEND) { Args&&... args) noexcept
} : LogStreamProcessor(
category,
level,
filename,
lineNumber,
INTERNAL,
createLogString(std::forward<Args>(args)...)) {}
/** /**
* LogStreamProcessor constructor for use with a LOG() macro with arguments * LogStreamProcessor constructor for use with a LOG() macro with arguments
...@@ -157,7 +147,8 @@ class LogStreamProcessor { ...@@ -157,7 +147,8 @@ class LogStreamProcessor {
LogLevel level, LogLevel level,
folly::StringPiece filename, folly::StringPiece filename,
unsigned int lineNumber, unsigned int lineNumber,
AppendType, FormatType,
folly::StringPiece fmt,
Args&&... args) noexcept Args&&... args) noexcept
: LogStreamProcessor( : LogStreamProcessor(
category, category,
...@@ -165,11 +156,25 @@ class LogStreamProcessor { ...@@ -165,11 +156,25 @@ class LogStreamProcessor {
filename, filename,
lineNumber, lineNumber,
INTERNAL, INTERNAL,
createLogString(std::forward<Args>(args)...)) {} formatLogString(fmt, std::forward<Args>(args)...)) {}
/** /*
* Versions of the above constructor for use in XLOG() statements. * Versions of the above constructors for use in XLOG() statements.
*
* These are defined separately from the above constructor so that the work
* of initializing the XLOG LogCategory data is done in a separate function
* body defined in LogStreamProcessor.cpp. We intentionally want to avoid
* inlining this work at every XLOG() statement, to reduce the emitted code
* size.
*/ */
LogStreamProcessor(
XlogCategoryInfo<true>* categoryInfo,
LogLevel level,
folly::StringPiece categoryName,
bool isCategoryNameOverridden,
folly::StringPiece filename,
unsigned int lineNumber,
AppendType) noexcept;
template <typename... Args> template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
XlogCategoryInfo<true>* categoryInfo, XlogCategoryInfo<true>* categoryInfo,
...@@ -191,72 +196,69 @@ class LogStreamProcessor { ...@@ -191,72 +196,69 @@ class LogStreamProcessor {
createLogString(std::forward<Args>(args)...)) {} createLogString(std::forward<Args>(args)...)) {}
template <typename... Args> template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo, XlogCategoryInfo<true>* categoryInfo,
LogLevel level, LogLevel level,
folly::StringPiece /* categoryName */, folly::StringPiece categoryName,
bool /* isCategoryNameOverridden */, bool isCategoryNameOverridden,
folly::StringPiece filename, folly::StringPiece filename,
unsigned int lineNumber, unsigned int lineNumber,
AppendType, FormatType,
folly::StringPiece fmt,
Args&&... args) noexcept Args&&... args) noexcept
: LogStreamProcessor( : LogStreamProcessor(
fileScopeInfo, categoryInfo,
level, level,
categoryName,
isCategoryNameOverridden,
filename, filename,
lineNumber, lineNumber,
INTERNAL, INTERNAL,
createLogString(std::forward<Args>(args)...)) {} formatLogString(fmt, std::forward<Args>(args)...)) {}
/** #ifdef __INCLUDE_LEVEL__
* LogStreamProcessor constructor for use with a LOG() macro with arguments /*
* to be concatenated with folly::to<std::string>() * Versions of the above constructors to use in XLOG() macros that appear in
* .cpp files. These are only used if the compiler supports the
* __INCLUDE_LEVEL__ macro, which we need to determine that the XLOG()
* statement is not in a header file.
* *
* Note that the filename argument is not copied. The caller should ensure * These behave identically to the XlogCategoryInfo<true> versions of the
* that it points to storage that will remain valid for the lifetime of the * APIs, but slightly more optimized, and allow the XLOG() code to avoid
* LogStreamProcessor. (This is always the case for the __FILE__ * storing category information at each XLOG() call site.
* preprocessor macro.)
*/ */
template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
const LogCategory* category, XlogFileScopeInfo* fileScopeInfo,
LogLevel level, LogLevel level,
folly::StringPiece filename, folly::StringPiece filename,
unsigned int lineNumber, unsigned int lineNumber,
FormatType, AppendType) noexcept;
folly::StringPiece fmt, LogStreamProcessor(
Args&&... args) noexcept XlogFileScopeInfo* fileScopeInfo,
: LogStreamProcessor( LogLevel level,
category, folly::StringPiece /* categoryName */,
level, bool /* isCategoryNameOverridden */,
filename, folly::StringPiece filename,
lineNumber, unsigned int lineNumber,
INTERNAL, AppendType) noexcept
formatLogString(fmt, std::forward<Args>(args)...)) {} : LogStreamProcessor(fileScopeInfo, level, filename, lineNumber, APPEND) {
}
/**
* Versions of the above constructor for use in XLOG() statements.
*/
template <typename... Args> template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
XlogCategoryInfo<true>* categoryInfo, XlogFileScopeInfo* fileScopeInfo,
LogLevel level, LogLevel level,
folly::StringPiece categoryName, folly::StringPiece /* categoryName */,
bool isCategoryNameOverridden, bool /* isCategoryNameOverridden */,
folly::StringPiece filename, folly::StringPiece filename,
unsigned int lineNumber, unsigned int lineNumber,
FormatType, AppendType,
folly::StringPiece fmt,
Args&&... args) noexcept Args&&... args) noexcept
: LogStreamProcessor( : LogStreamProcessor(
categoryInfo, fileScopeInfo,
level, level,
categoryName,
isCategoryNameOverridden,
filename, filename,
lineNumber, lineNumber,
INTERNAL, INTERNAL,
formatLogString(fmt, std::forward<Args>(args)...)) {} createLogString(std::forward<Args>(args)...)) {}
template <typename... Args> template <typename... Args>
LogStreamProcessor( LogStreamProcessor(
XlogFileScopeInfo* fileScopeInfo, XlogFileScopeInfo* fileScopeInfo,
...@@ -275,6 +277,7 @@ class LogStreamProcessor { ...@@ -275,6 +277,7 @@ class LogStreamProcessor {
lineNumber, lineNumber,
INTERNAL, INTERNAL,
formatLogString(fmt, std::forward<Args>(args)...)) {} formatLogString(fmt, std::forward<Args>(args)...)) {}
#endif
~LogStreamProcessor() noexcept; ~LogStreamProcessor() noexcept;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment