<li>Very fast - performance is the primary goal (see <ahref="#benchmarks">benchmarks</a> below).</li>
<li>Headers only.</li>
<li>No dependencies - just copy and use.</li>
<li>Cross platform - Linux / Windows on 32/64 bits.</li>
<li>
<strong>new!</strong> Feature rich <ahref="#usage-example">call style</a> using the excellent <ahref="http://cppformat.github.io/">cppformat</a> library.</li>
<li>ostream call style is supported too.</li>
<li>Extremely fast asynchronous mode (optional) - using lockfree queues and other tricks to reach millions of calls/sec.</li>
<p>Time needed to log 1,000,000 lines in asynchronous mode, i.e. the time it takes to put them in the async queue (in seconds, the best of 3 runs):</p>
console-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>Welcome to spdlog!<spanclass="pl-pds">"</span></span>) ;
console-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>An info message example {}..<spanclass="pl-pds">"</span></span>, <spanclass="pl-c1">1</span>);
console-><spanclass="pl-c1">info</span>() <<<spanclass="pl-s"><spanclass="pl-pds">"</span>Streams are supported too <spanclass="pl-pds">"</span></span><<<spanclass="pl-c1">1</span>;
<spanclass="pl-c">//Formatting examples</span>
console-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>Easy padding in numbers like {:08d}<spanclass="pl-pds">"</span></span>, <spanclass="pl-c1">12</span>);
console-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>Support for floats {:03.2f}<spanclass="pl-pds">"</span></span>, <spanclass="pl-c1">1.23456</span>);
console-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>Positional args are {1} {0}..<spanclass="pl-pds">"</span></span>, <spanclass="pl-s"><spanclass="pl-pds">"</span>too<spanclass="pl-pds">"</span></span>, <spanclass="pl-s"><spanclass="pl-pds">"</span>supported<spanclass="pl-pds">"</span></span>);
<spanclass="pl-c1">spd::set_level</span>(spd::level::info); <spanclass="pl-c">//Set global log level to info</span>
console-><spanclass="pl-c1">debug</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>This message shold not be displayed!<spanclass="pl-pds">"</span></span>);
console-><spanclass="pl-c1">set_level</span>(spd::level::debug); <spanclass="pl-c">// Set specific logger's log level</span>
console-><spanclass="pl-c1">debug</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>Now it should..<spanclass="pl-pds">"</span></span>);
<spanclass="pl-c">//</span>
<spanclass="pl-c">// Create a file rotating logger with 5mb size max and 3 rotated files</span>
<spanclass="pl-k">for</span>(<spanclass="pl-k">int</span> i = <spanclass="pl-c1">0</span>; i <<spanclass="pl-c1">10</span>; ++i)
file_logger-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>{} * {} equals {:>10}<spanclass="pl-pds">"</span></span>, i, i, i*i);
<spanclass="pl-c">//</span>
<spanclass="pl-c">// Create a daily logger - a new file is created every day on 2:30am</span>
file_logger-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>This is another message with custom format<spanclass="pl-pds">"</span></span>);
<spanclass="pl-c1">spd::get</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>console<spanclass="pl-pds">"</span></span>)-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>loggers can be retrieved from a global registry using the spdlog::get(logger_name) function<spanclass="pl-pds">"</span></span>);
<spanclass="pl-c">//</span>
<spanclass="pl-c">// Compile time debug or trace macros.</span>
<spanclass="pl-c">// Enabled #ifdef SPDLOG_DEBUG_ON or #ifdef SPDLOG_TRACE_ON</span>
<spanclass="pl-c">//</span>
<spanclass="pl-c1">SPDLOG_TRACE</span>(console, <spanclass="pl-s"><spanclass="pl-pds">"</span>Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}<spanclass="pl-pds">"</span></span>, <spanclass="pl-c1">1</span>, <spanclass="pl-c1">3.23</span>);
<spanclass="pl-c1">SPDLOG_DEBUG</span>(console, <spanclass="pl-s"><spanclass="pl-pds">"</span>Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}<spanclass="pl-pds">"</span></span>, <spanclass="pl-c1">1</span>, <spanclass="pl-c1">3.23</span>);
<spanclass="pl-c">//</span>
<spanclass="pl-c">// Asynchronous logging is very fast..</span>
<spanclass="pl-c">// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..</span>
<spanclass="pl-c">//</span>
<spanclass="pl-c1">size_t</span> q_size = <spanclass="pl-c1">1048576</span>; <spanclass="pl-c">//queue size must be power of 2</span>
async_file-><spanclass="pl-c1">info</span>() <<<spanclass="pl-s"><spanclass="pl-pds">"</span>This is async log..<spanclass="pl-pds">"</span></span><<<spanclass="pl-s"><spanclass="pl-pds">"</span>Should be very fast!<spanclass="pl-pds">"</span></span>;
<spanclass="pl-c">// </span>
<spanclass="pl-c">// syslog example. linux only..</span>
syslog_logger-><spanclass="pl-c1">warn</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>This is warning that will end up in syslog. This is Linux only!<spanclass="pl-pds">"</span></span>);
std::ostream&<spanclass="pl-k">operator</span><<(std::ostream& os, <spanclass="pl-k">const</span> some_class& c) { <spanclass="pl-k">return</span> os <<<spanclass="pl-s"><spanclass="pl-pds">"</span>some_class<spanclass="pl-pds">"</span></span>; }
<spanclass="pl-c1">spdlog::get</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>console<spanclass="pl-pds">"</span></span>)-><spanclass="pl-c1">info</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>custom class with operator<<: {}..<spanclass="pl-pds">"</span></span>, c);
<spanclass="pl-c1">spdlog::get</span>(<spanclass="pl-s"><spanclass="pl-pds">"</span>console<spanclass="pl-pds">"</span></span>)-><spanclass="pl-c1">info</span>() <<<spanclass="pl-s"><spanclass="pl-pds">"</span>custom class with operator<<: <spanclass="pl-pds">"</span></span><< c <<<spanclass="pl-s"><spanclass="pl-pds">"</span>..<spanclass="pl-pds">"</span></span>;