<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Odysseas</title>
    <description>The latest articles on DEV Community by Odysseas (@odygrd).</description>
    <link>https://dev.to/odygrd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1989497%2F36199921-4750-49a7-974f-d3a4dcf4c385.png</url>
      <title>DEV Community: Odysseas</title>
      <link>https://dev.to/odygrd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/odygrd"/>
    <language>en</language>
    <item>
      <title>Quill: High-Performance Asynchronous C++ Logging Library</title>
      <dc:creator>Odysseas</dc:creator>
      <pubDate>Wed, 28 Aug 2024 01:01:07 +0000</pubDate>
      <link>https://dev.to/odygrd/quill-high-performance-asynchronous-c-logging-library-lf1</link>
      <guid>https://dev.to/odygrd/quill-high-performance-asynchronous-c-logging-library-lf1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Efficient logging is crucial for application performance and debugging. Logging is an essential part of any software system, but it can often become a performance bottleneck, especially in low-latency applications. Quill addresses this challenge by offering an asynchronous, cross-platform logging solution that minimizes the impact on your application's hot path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Focus
&lt;/h2&gt;

&lt;p&gt;Quill is a feature-rich logging library built with performance in mind. Its design aims to provide faster logging capabilities compared to many traditional logging libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thread-Local Lock-Free Ring Buffer:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Each thread is equipped with its own lock-free ring buffer, facilitating efficient, contention-free logging. This architecture eliminates inter-thread synchronization for log writes, drastically reducing overhead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile-Time Metadata Generation:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Quill generates essential log metadata—such as file name, line number, and format string—at compile time. By shifting this workload to compile time, runtime performance is significantly enhanced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binary Log Message Serialization:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Instead of formatting log messages on-the-fly, Quill serializes argument data in binary form directly into the ring buffer. This approach minimizes processing on the critical path of application threads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous Backend Processing:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A dedicated backend thread retrieves binary data from the ring buffers, formats the log messages, and outputs them to the designated sinks (e.g., files, console).&lt;/p&gt;

&lt;p&gt;This architecture enables Quill to deliver high performance by reducing work in application threads, capitalizing on compile-time optimizations, and leveraging asynchronous processing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example Usage
&lt;/h2&gt;

&lt;p&gt;Here's a basic example of how to use Quill in your C++ application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"quill/Backend.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"quill/Frontend.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"quill/LogMacros.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"quill/Logger.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"quill/sinks/ConsoleSink.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string_view&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;quill&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Backend&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="n"&gt;quill&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;quill&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Frontend&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;create_or_get_logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quill&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Frontend&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;create_or_get_sink&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;quill&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ConsoleSink&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"sink_id_1"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="n"&gt;LOG_INFO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello from {}!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string_view&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Quill"&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can try it on &lt;a href="https://godbolt.org/z/v1oa7Y3dY" rel="noopener noreferrer"&gt;Compiler Explorer&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Involved
&lt;/h2&gt;

&lt;p&gt;To dive deeper into Quill or contribute to the project, visit the &lt;a href="https://github.com/odygrd/quill" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; or the &lt;a href="https://quillcpp.readthedocs.io" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt; page.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>logging</category>
    </item>
  </channel>
</rss>
