<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Manudev H Menon on Medium]]></title>
        <description><![CDATA[Stories by Manudev H Menon on Medium]]></description>
        <link>https://medium.com/@manudev.h.menon?source=rss-73fc5abb6c04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aX24Ba9ZSDKyjTAAhCRGvA.jpeg</url>
            <title>Stories by Manudev H Menon on Medium</title>
            <link>https://medium.com/@manudev.h.menon?source=rss-73fc5abb6c04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:58:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manudev.h.menon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker container logs using syslog logging driver]]></title>
            <link>https://medium.com/@manudev.h.menon/container-logs-using-syslog-logging-driver-42a039c68ab4?source=rss-73fc5abb6c04------2</link>
            <guid isPermaLink="false">https://medium.com/p/42a039c68ab4</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[syslog-ng]]></category>
            <category><![CDATA[syslog]]></category>
            <dc:creator><![CDATA[Manudev H Menon]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 09:13:55 GMT</pubDate>
            <atom:updated>2024-07-25T09:21:33.378Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>why should we use logging drivers for container logs?</strong></p><p>Using a logging driver is essential for efficiently managing and monitoring the logs generated by applications and services in a containerized environment.</p><p>It has following advantages</p><ul><li>Centralized log management</li><li>Standardized log formats</li><li>Real-time log streaming</li><li>Log rotation and retention</li><li>Integration with monitoring and analytics tools</li><li>Security and compliance</li><li>Flexibility and customization</li></ul><p>Docker, for instance, offers various logging drivers that allow you to specify how and where you want the logs to be collected and stored.</p><p>The default logging driver is <strong><em>json-file</em></strong>.</p><p>Let’s see the how logs can be collected using <strong><em>syslog </em></strong>logging driver.</p><p>Syslog is a logging driver for Docker that allows you to send container logs to a Syslog server. It is an integral part of the Docker engine, providing a native and reliable way to manage the logs from your Docker containers.</p><p>With Docker Syslog, you can centralize and manage the logs from your Docker containers in a single place, making it easier to monitor and troubleshoot issues.</p><p>This means that when Docker runs applications, the log messages produced by those applications can be sent to the Syslog server for centralized storage and analysis.</p><p>The syslog logging driver routes logs to a syslog server. The syslog protocol uses a raw string as the log message and supports a limited set of metadata. The syslog message must be formatted in a specific way to be valid. From a valid message, the receiver can extract the following information:</p><ul><li><strong>priority</strong>: the logging level, such as debug, warning, error, info.</li><li><strong>timestamp</strong>: when the event occurred.</li><li><strong>hostname</strong>: where the event happened.</li><li><strong>facility</strong>: which subsystem logged the message, such as mail or kernel.</li><li><strong>process name</strong> and <strong>process ID (PID)</strong>: The name and ID of the process that generated the log.</li></ul><p>open-source options for syslog logging drivers are Rsyslog and Syslog-ng.</p><p>Evaluation of syslog-ng is done here.</p><p><strong>Steps to use:</strong></p><p>Assuming that we have a webapp/service (<strong>service1</strong> and <strong>service2</strong>) created for containerize with logs statements (<strong><em>Hey! This is Service 1</em></strong> and <strong><em>Hey! This is Service 2 </em></strong>) respectively.</p><ol><li><em>Pull and run docker image for syslog-ng to have a running container instance</em></li></ol><pre> docker run -d --name=syslog-ng   -e PUID=YOUR_PUID -e PGID=YOUR_PGID-e TZ=etc/UTC  -p 514:5514/udp   -p 601:6601/tcp  -p 6514:6514/tcp  -v /path/to/config:/config   lscr.io/linuxserver/syslog-ng:latest</pre><p><em>2. Configure logging driver as syslog and run </em><strong><em>service1</em></strong><em> and </em><strong><em>service2</em></strong><em> instance with </em><strong><em>udp address</em></strong><em> of the running </em><strong><em>syslog-ng</em></strong><em> instance. (could be found from DockerDesktop-&gt; syslog-ng container -&gt; inspect tab)</em></p><pre>docker run --name service1_syslog -dp 3000:3000 --log-driver syslog --log-opt syslog-address=udp://X.X.X.X:514 service1<br>docker run --name service2_syslog -dp 4000:4000 --log-driver syslog --log-opt syslog-address=udp://X.X.X.X:514 service2</pre><p><em>3. Logging configuration could be changed using s</em><strong><em>yslog-ng.conf</em></strong><em> (path: /config/syslog-ng.conf )</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJIQouG6IEwYF5ztiXcbqw.png" /></figure><p><em>4. Logs from both containers would be present at var/log/message as mentioned in conf.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p83PKv0_LszHX5FAzLewaw.png" /><figcaption><strong><em>message</em></strong><em> logs all data from container</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_rq-OG7daaAfx6SYhOHMA.png" /><figcaption><strong><em>message-kv</em></strong><em> holds logs including </em><strong><em>host_ip</em></strong><em>,</em><strong><em>timestamp</em></strong><em> and </em><strong><em>container_id</em></strong><em> as mentioned in the config file.</em></figcaption></figure><p><strong>Do we have an option to send logs from the current syslog-ng instance to any other remote machine ?</strong></p><p>Yes. For the evaluation purpose, we have created an another <em>syslog-ng-destintaion </em>instance which has different IP address and we will be sending logs from <strong>source</strong> syslog-ng container to <strong>destination</strong> syslog-ng container.</p><p>Steps to use:</p><ol><li><em>It is mandatory that destination machine also should has syslog instance running in their system. To mimic this usecase , Run a docker instance as syslog-ng-destintaion</em></li></ol><pre>docker run -d \<br>  --name=syslog-ng-destination \<br>  -e PUID=YOUR_PUID \<br>  -e PGID=YOUR_PGID \<br>  -e TZ=Etc/UTC \<br>  -p 514:514/udp \<br>  -p 601:601/tcp \<br>  -p 6514:6514/tcp \<br>  -v /path/to/config:/config \<br>  lscr.io/linuxserver/syslog-ng:latest</pre><p>2. <em>Along with existing default configuration, Config the source container syslog-ng.conf with the following and restart the container (/config/syslog-ng.conf)</em></p><pre> destination d_dest {<br>     # Define the destination for forwarding logs to the receiver.<br>     network(<br>         &quot;X.X.X.X&quot;    # destination ip-address<br>         transport(udp)   # transfer protocol<br>         port(5514)     # destination  port<br>     );<br> };<br> log {<br>   source(s_local);  <br>   source(s_network_tcp);<br>   source(s_network_udp);<br>   destination(d_dest);<br> };</pre><p>3. <em>Config the destination container syslog-ng.conf with the following and restart the container</em></p><pre> destination d_local {<br>   file(&quot;/var/log/messages&quot;);<br>   file(&quot;/var/log/messages-kv.log&quot; template(&quot;$ISODATE $HOST $(format-welf --scope all-nv-pairs)\n&quot;) frac-digits(3));<br> };<br> log {<br>   source(s_local);<br>   source(s_network_tcp);<br>   source(s_network_udp);<br>   destination(d_local);<br>};</pre><p>Now, logs will be visible in the destination syslog-ng container (/var/log/messages)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKeG8Vw4-_CH2Uxu-IWRUQ.png" /></figure><p>By integrating Docker Syslog with syslog-ng, you can efficiently centralize and manage logs from multiple containers, enhancing your ability to monitor and troubleshoot your applications. The setup allows for both local and remote log management, providing flexibility and scalability for various environments. With proper configuration, syslog-ng facilitates reliable log forwarding and analysis, making it a robust solution for containerized applications.</p><p><strong><em>Note: The logs shown here are from a local development environment and do not contain any sensitive information.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42a039c68ab4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker container logs using Fluentd logging driver]]></title>
            <link>https://medium.com/@manudev.h.menon/container-logs-using-fluentd-logging-driver-289d33fefe33?source=rss-73fc5abb6c04------2</link>
            <guid isPermaLink="false">https://medium.com/p/289d33fefe33</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[fluentd]]></category>
            <dc:creator><![CDATA[Manudev H Menon]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 08:27:40 GMT</pubDate>
            <atom:updated>2024-07-25T09:21:44.204Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Why should we use logging drivers for container logs?</strong></p><p>Using a logging driver is essential for efficiently managing and monitoring the logs generated by applications and services in a containerized environment.</p><p>It has following advantages</p><ul><li>Centralized log management</li><li>Standardized log formats</li><li>Real-time log streaming</li><li>Log rotation and retention</li><li>Integration with monitoring and analytics tools</li><li>Security and compliance</li><li>Flexibility and customization</li></ul><p>Docker, for instance, offers various logging drivers that allow you to specify how and where you want the logs to be collected and stored.</p><p>The default logging driver is <strong><em>json-file</em></strong>.</p><p>Let’s see the how logs can be collected using <strong><em>fluentd </em></strong>logging driver.</p><p><strong>Fluentd </strong>is an open-source tool that helps collect and manage data from various sources in a unified way. The Fluentd logging driver sends logs from containers to Fluentd, which then structures this log data. Users can then use Fluentd’s output plugins to send these logs to different destinations.</p><p>In addition to the log message itself, the fluentd log driver sends the following metadata in the structured log message:</p><ul><li>container_id — The full 64-character container ID.</li><li>container_name — The container name at the time it was started. If you use docker rename to rename a container, the new name is not reflected in the journal entries.</li><li>source — stdout or stderr</li><li>log — The container log</li></ul><p><strong>Steps to use:</strong></p><p>Assuming that we have a webapp/service (<strong>service1</strong> and <strong>service2</strong>) created for containerize with logs statements (<strong><em>Hey! This is Service 1</em></strong> and <strong><em>Hey! This is Service 2 </em></strong>) respectively.</p><ol><li><em>Pull and ran docker image for fluentd to have a running container instance</em></li></ol><pre>  docker run --name fluentd_container fluentd</pre><p>2. <em>Configure logging driver as </em><strong><em>fluentd</em></strong><em> and run </em><strong><em>service1</em></strong><em> and </em><strong><em>service2</em></strong><em> instance with </em><strong><em>HOSTIP</em></strong><em> of the running fluentd instance.</em></p><pre>  docker run --name service1_fluentd_logging -dp 3000:3000 --log-driver=fluentd --log-opt fluentd-address=HOSTIP :24224 service1<br>  docker run --name service1_fluentd_logging -dp 4000:4000 --log-driver=fluentd --log-opt fluentd-address=HOSTIP :24224 service2</pre><p>The destination of the logs and filtering of containers can be configured through <strong>fluent.conf </strong>(<em>path: fluentd/etc/fluent.conf</em> ).</p><p>Two Approaches can be considered here, Logging all services in a consolidated file and logging in seperate files for each containers.</p><p>3. <em>Configure </em><strong><em>fluent.conf </em></strong><em>to change consolidate all container logs in a single file. Generally, fluent.conf logs all the containers logs to a single file based on the default match criteria in the configuration.</em></p><p><em>By default, logs will be visible </em><strong><em>fluentd/log</em></strong><em> in the host machine.</em></p><pre>   # for consolidated logs from all container <br>    &lt;match **&gt;<br>      @type file<br>      @id   output1<br>      path         /fluentd/log/data.consolidated_conatiner_logs.log<br>      symlink_path /fluentd/log/data.log<br>      append       true<br>      time_slice_format %Y%m%d<br>      time_slice_wait   10m<br>      time_format       %Y%m%dT%H%M%S%z<br>    &lt;/match&gt;</pre><p><em>Here, (match **) provides option to consolidate all container logs to single file. </em><strong><em>path</em></strong><em> can be edited to change the location for the logfile in the host machine.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4Q4XYj7Nb9B-3SAGmBe3w.png" /><figcaption>The log statements from both services are highlighted.</figcaption></figure><p>4. C<em>onfigure </em><strong><em>fluent.conf </em></strong><em>to have separate log file for each containers.One of the way to segregate container logs is based on the </em><strong><em>tagnames </em></strong><em>we provide on docker run command.</em></p><pre>  docker run --name service1_fluentd_logging -dp 4000:4000 --log-driver=fluentd --log-opt fluentd-address=HOSTIP :24224  --log-opt tag=docker.service2 service2<br>  <br>    &lt;match docker.service2.**&gt;<br>      @type file<br>      @id   output1<br>      path         /fluentd/log/data.service2_logs.log<br>      symlink_path /fluentd/log/data.log<br>      append       true<br>      time_slice_format %Y%m%d<br>      time_slice_wait   10m<br>      time_format       %Y%m%dT%H%M%S%z<br>    &lt;/match&gt;</pre><p><em>Here, </em><strong><em>docker.service2</em></strong><em> is the tagname for the container </em><strong><em>service2</em></strong><em>. So when we have </em><strong><em>docker.service2.** </em></strong><em>in the match expression, it will redirect all service2 container logs to the specified file location.</em></p><p><em>We can also provide conatiner_id also in the match expression in conf. since by default, container_id is the default tagname.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3sb-Zlj7uaPqXNH5PGUzg.png" /><figcaption>The log statements from service 1 is highlighted from it’s separate log file.</figcaption></figure><p><strong>Do we have an option to send logs from the current fluentd instance to any other remote machine ?</strong></p><p>Yes. For the evaluation purpose, we have created an another fluentd_container instance which has different IP address and we will be sending logs from <strong>source</strong> fluentd container to <strong>destination</strong> fluentd container.</p><p>Steps to use:</p><ol><li><em>It is mandatory that destination machine also should has fluentd installed in their system. To mimic this usecase , Run a docker instance as fluentd_destintaion_container</em></li></ol><pre> docker run --name fluentd_destintaion_container fluentd</pre><p><em>2. Config the source container fluent.conf with the following</em></p><pre> &lt;match **&gt;<br>   @type forward<br>   send_timeout 60s<br>   recover_wait 10s<br>   heartbeat_interval 1s<br>   phi_threshold 16<br>   hard_timeout 60s<br>   &lt;server&gt;<br>     host destination_ip<br>     port destination_port<br>   &lt;/server&gt;<br> &lt;/match&gt;</pre><p><em>3. Config the destination container fluent.conf with the following and restart the container</em></p><pre> &lt;source&gt;<br>   @type forward<br>   port 24224 # The port to listen for incoming logs (should match the port in the source machine)<br> &lt;/source&gt;<br> <br> &lt;match logs&gt;<br>   @type file<br>   path /path/to/destination/logfile.log<br> &lt;/match&gt;</pre><p>Now, logs will be visible in the destination fluentd container.</p><p>Using Fluentd as a logging driver for Docker provides a powerful and flexible solution for managing container logs. Fluentd can aggregate and structure logs from multiple containers, allowing you to direct them to consolidated or separate log files based on your needs. Additionally, Fluentd supports forwarding logs to remote instances, making it a scalable option for distributed log management across different systems. This setup enhances both local and remote log handling, ensuring comprehensive log analysis and troubleshooting capabilities.</p><p><strong><em>Note: The logs shown here are from a local development environment and do not contain any sensitive information.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=289d33fefe33" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>