[#XLOG_ACTUAL_IMPL]
= XLOG&lowbar;ACTUAL&lowbar;IMPL
:mrdocs:

Helper macro used to implement XLOG() and XLOGF()

== Synopsis

Declared in `&lt;folly&sol;logging&sol;xlog&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
#define XLOG&lowbar;ACTUAL&lowbar;IMPL(level, cond, always&lowbar;fatal, type, ...)

----

== Description

Beware that the level argument is evaluated twice&period;

This macro is somewhat tricky&colon;

* In order to support streaming argument support (with the &lt;&lt; operator), the macro must expand to a single ternary ? expression&period; This is the only way we can avoid evaluating the log arguments if the log check fails, and still have the macro behave as expected when used as the body of an if or else statement&period;

* We need to store some static&hyphen;scope local state in order to track the LogCategory to use&period; This is a bit tricky to do and still meet the requirements of being a single expression, but fortunately static variables inside a lambda work for this purpose&period;

Inside header files, each XLOG() statement defines two static variables&colon;

* the LogLevel for this category
* a pointer to the LogCategory

If the *INCLUDE&lowbar;LEVEL* macro is available (both gcc and clang support this), then we we can detect when we are inside a &period;cpp file versus a header file&period; If we are inside a &period;cpp file, we can avoid declaring these variables once per XLOG() statement, and instead we only declare one copy of these variables for the entire file&period;

* We want to make sure this macro is safe to use even from inside static initialization code that runs before main&period; We also want to make the log admittance check as cheap as possible, so that disabled debug logs have minimal overhead, and can be left in place even in performance senstive code&period;

In order to do this, we rely on zero&hyphen;initialization of variables with static storage duration&period; The LogLevel variable will always be 0&hyphen;initialized before any code runs&period; Therefore the very first time an XLOG() statement is hit the initial log level check will always pass (since all level values are greater or equal to 0), and we then do a second check to see if the log level and category variables need to be initialized&period; On all subsequent calls, disabled log statements can be skipped with just a single check of the LogLevel&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *level*
| The `folly&colon;&colon;LogLevel` value at which to log&period;
| *cond*
| A predicate&semi; the message is logged only when it is true&period;
| *always&lowbar;fatal*
| Whether the statement always aborts the program&period;
| *type*
| The `LogStreamProcessor` append or format mode&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
