{"id":21992,"date":"2015-04-08T11:00:21","date_gmt":"2015-04-08T08:00:21","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=21992"},"modified":"2015-04-06T11:59:30","modified_gmt":"2015-04-06T08:59:30","slug":"logback-syslog-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/","title":{"rendered":"Logback Syslog Example"},"content":{"rendered":"<p>Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our guide book when we need to explore what is happening and what was happened in the code.<\/p>\n<p>In this post, we shall show you how to transmit logs to the Syslog server using Logback framework. After a brief introduction to Logback framework and Syslog protocol, we will look at the implementation details of our example.<\/p>\n<h2>1. What is Logback?<\/h2>\n<p>Logback is basically a logging framework. Log4j, Java logging API, Apache Commons Logging are some other alternatives. But Logback is the most recent, modern one with extra useful features. It was designed by Ceki G\u00fclc\u00fc. He is also the founder of the popular Log4j framework. So we can consider Logback as a successor to the Log4j.<\/p>\n<h3>1.1 Logback Architecture<\/h3>\n<p>Logback is divided into three modules, <b>logback-core<\/b>, <b>logback-classic<\/b> and <b>logback-access<\/b>. The core module provides the groundwork for the other two modules. The classic module corresponds to a significantly improved version of Log4j. <\/p>\n<p>SLF4J API serves as a simple abstraction for various logging frameworks. Logging codes written with SLF4J in the embedded components and libraries are compatible with the preferred logging framework. At runtime, SLF4J codes are bound to the logging framework in the classpath. Logback-classic module <strong>natively implements the SLF4J API.<\/strong> So this flexible architecture allows the end user to switch back and forth between other logging systems and Logback.<\/p>\n<p>The logback-access module integrates with Servlet containers, such as Tomcat and Jetty, to provide rich and powerful HTTP-access log functionality. The logback-access setup is done at Servlet container level. So the web applications deployed in the Servlet container are unaware of it. But this module is out of scope in our example.<\/p>\n<h3>1.2 Logback Configuration<\/h3>\n<p>Logback can be configured either programmatically or with a configuration file expressed in XML or Groovy format. Logback follows these steps to try to configure itself:<\/p>\n<p>1) Logback tries to find a file called <b>logback.groovy<\/b> in the classpath.<br \/>\n2) If no such file is found, logback tries to find a file called <b>logback-test.xml<\/b> in the classpath.<br \/>\n3) If no such file is found, it checks for the file <b>logback.xml<\/b> in the classpath.<br \/>\n4) If neither file is found, logback configures itself automatically using the <b>BasicConfigurator<\/b> which will cause logging output to be directed to the console.<\/p>\n<p>Also I would like to mention about <b>appenders<\/b> and <b>layouts<\/b>. Each log event for a given logger is forwarded to the relevant appender. Appender determines the log destination system such as console, file, e-mail, syslog\u2026 Log layout determines the log message pattern with some fields such as length, thread name, log level\u2026<\/p>\n<h2>2. What is Syslog?<\/h2>\n<p>Syslog is a message logging protocol originally written by Eric Allman. This protocol provides a transport to allow a client to send event messages across IP networks to event message receiver, commonly called syslogd, syslog daemon or syslog server. <\/p>\n<p>Implementations of syslog exist for many operating systems. In most of the UNIX\/Linux distributions, an internal daemon, called Syslogd, handles the syslog process. This daemon is an integral part of the operating system and does not need to be installed. And also some other open source or commercial products that implement the protocol exist. <\/p>\n<p>Syslog messages may be transmitted via the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP). Syslog uses the port number 514.<\/p>\n<p>Each syslog message is labeled with a facility code and assigned a severity label. <\/p>\n<h3>2.1 Syslog Facility and Severity<\/h3>\n<p>Facility label indicates the source system category that generate the syslog message. These sources can be the operating system, the process, or an application. Different facilities may be handled differently by the Syslog server. These facilities are represented by an integer number. Facilities are 0 (kern), 1 (user), 2 (mail), 3 (daemon), 4 (auth), 5 (syslog), 6 (lpr), 7 (news), 8 (uucp), 9 (clock daemon), 10 (authpriv), 11 (ftp), 12(ntp system), 13 (log audit), 14 (log alert), 15 (cron), 16 (local0), 17 (local1), 18 (local2), 19 (local3), 20 (local4), 21 (local5), 22 (local6), 23 (local7)<\/p>\n<p>Syslog protocol defines eight severity levels presented by single-digit integer: 0 (emergency), 1 (alert), 2 (critical), 3 (error), 4 (warning), 5 (notice), 6 (informational), 7 (debug)<\/p>\n<h3>2.2 Logback Syslog Configuration<\/h3>\n<p>In the Logback, syslog messages are configured by the <b>SyslogAppender<\/b>. Here are the properties you can pass to a SyslogAppender:<\/p>\n<p><b>syslogHost:<\/b> The host name of the syslog server.<\/p>\n<p><b>port:<\/b> The port number on the syslog server to connect to. Default value is 514. <\/p>\n<p><b>facility:<\/b> The source of the message.<\/p>\n<p><b>suffixPattern:<\/b> It specifies the format of the message sent to the syslog server. By default, its value is [%thread] %logger %msg.<\/p>\n<p><b>stackTracePattern:<\/b> This property allows the customization of the string appearing just before each stack trace line. The default value for this property is &#8220;\\t&#8221;, i.e. the tab character.<\/p>\n<p><b>throwableExcluded:<\/b> This is a boolean field. Setting it to true will cause stack trace data associated with a Throwable to be omitted. By default, it is set to false so that stack trace data is sent to the syslog server. <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The syslog severity of a logging event is converted from the level of the logging event.<\/p>\n<h2>3. Overview<\/h2>\n<p>We create a Maven project in the Eclipse IDE and add logback dependencies to our pom.xml file. Please note that Maven Integration Plugin should be already installed in the Eclipse IDE, if you would like to delegate the classpath setting process to the Eclipse. We are using <b>logback.xml<\/b> file to configure Logback Syslog Appender. As we mentioned before, There are a lot of Syslog implementations. We prefer to use <b><a href=\"http:\/\/www.kiwisyslog.com\/\" title=\"Kiwi Syslog Server\">Kiwi Free Edition<\/a><\/b> to test the log transportation in the Windows operating system. In order to see the log messages in the Linux operating system, we use <b>Rsyslog<\/b> package in the Ubuntu operating system. <\/p>\n<p>In the Ubuntu Server, syslog messages are appended to the <i>syslog<\/i> file in the &#8220;\/var\/log&#8221; directory. But in advance, you must uncomment the lines below in the &#8220;\/etc\/rsyslog.conf&#8221; file and next, restart the rsyslog service to provide UDP syslog reception:<\/p>\n<p>$ModLoad imudp<br \/>\n$UDPServerRun 514<\/p>\n<p>When we execute the code, We expect to see messages in the both of the Syslog servers.      <\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>You may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<h2>4. Create a new Maven project<\/h2>\n<p>Go to File -&gt; Project -&gt;Maven -&gt; Maven Project.<\/p>\n<p><figure id=\"attachment_22045\" aria-describedby=\"caption-attachment-22045\" style=\"width: 624px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img1.jpg\" alt=\"Eclipse new Project Wizard\" width=\"624\" height=\"504\" class=\"size-full wp-image-22045\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img1.jpg 624w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img1-300x242.jpg 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><figcaption id=\"caption-attachment-22045\" class=\"wp-caption-text\">Eclipse new Project Wizard<\/figcaption><\/figure><\/p>\n<p>In the next screen, accept the default options and click on <b>Next<\/b><\/p>\n<p><figure id=\"attachment_22047\" aria-describedby=\"caption-attachment-22047\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img2.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img2.jpg\" alt=\"Eclipse Maven Project\" width=\"711\" height=\"550\" class=\"size-full wp-image-22047\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img2.jpg 711w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img2-300x232.jpg 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/a><figcaption id=\"caption-attachment-22047\" class=\"wp-caption-text\">Eclipse Maven Project<\/figcaption><\/figure><\/p>\n<p>In the next screen, select the <b>maven-archetype-quickstart<\/b> option and click Next<\/p>\n<p><figure id=\"attachment_22049\" aria-describedby=\"caption-attachment-22049\" style=\"width: 668px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img3.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img3.jpg\" alt=\"Eclipse Maven Project\" width=\"668\" height=\"522\" class=\"size-full wp-image-22049\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img3.jpg 668w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img3-300x234.jpg 300w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/a><figcaption id=\"caption-attachment-22049\" class=\"wp-caption-text\">Eclipse Maven Project<\/figcaption><\/figure><\/p>\n<p>In the next screen, type the <b>Group Id, Artifact Id<\/b> and <b>Package<\/b>, as in the following screen and click on <b>Finish<\/b><\/p>\n<p><figure id=\"attachment_22051\" aria-describedby=\"caption-attachment-22051\" style=\"width: 673px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img4.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img4.jpg\" alt=\"Eclipse Maven Project\" width=\"673\" height=\"524\" class=\"size-full wp-image-22051\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img4.jpg 673w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img4-300x234.jpg 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/a><figcaption id=\"caption-attachment-22051\" class=\"wp-caption-text\">Eclipse Maven Project<\/figcaption><\/figure><\/p>\n<p>As you see, the project is created in your workspace.<\/p>\n<p><figure id=\"attachment_22053\" aria-describedby=\"caption-attachment-22053\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img5.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img5.jpg\" alt=\"Eclipse Project\" width=\"521\" height=\"328\" class=\"size-full wp-image-22053\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img5.jpg 521w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img5-300x189.jpg 300w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/a><figcaption id=\"caption-attachment-22053\" class=\"wp-caption-text\">Eclipse Project<\/figcaption><\/figure><\/p>\n<h3>4.1 Adding Maven dependencies<\/h3>\n<p>Before we execute some code, we need to add logback dependencies in the Maven&#8217;s pom.xml file. By the power of the Maven Dependency Management, It is enough to add only <b>logback-classic<\/b> artifact. <b>logback-core<\/b> and <b>slf4j-api<\/b> packages are transitive dependencies of the logback-classic artifact. So they are automatically added to the classpath. It is inessential, but we also add <b>junit<\/b> artifact to able to write unit test code. <\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">\r\n&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\r\n\t&lt;groupId&gt;com.javacodegeeks.examples&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;logbacksyslogexample&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;packaging&gt;jar&lt;\/packaging&gt;\r\n\r\n\t&lt;name&gt;logbacksyslogexample&lt;\/name&gt;\r\n\t&lt;url&gt;http:\/\/maven.apache.org&lt;\/url&gt;\r\n\r\n\t&lt;properties&gt;\r\n\t\t&lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n\t&lt;\/properties&gt;\r\n\r\n\t&lt;build&gt;\r\n\t\t&lt;plugins&gt;\r\n\t\t\t&lt;plugin&gt;\r\n\t\t\t\t&lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n\t\t\t\t&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;version&gt;3.2&lt;\/version&gt;\r\n\t\t\t\t&lt;configuration&gt;\r\n\t\t\t\t\t&lt;source&gt;1.7&lt;\/source&gt;\r\n\t\t\t\t\t&lt;target&gt;1.7&lt;\/target&gt;\r\n\t\t\t\t&lt;\/configuration&gt;\r\n\t\t\t&lt;\/plugin&gt;\r\n\t\t&lt;\/plugins&gt;\r\n\t&lt;\/build&gt;\r\n\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;logback-classic&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;1.1.3&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;junit&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;junit&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;4.12&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t&lt;\/dependencies&gt;\r\n&lt;\/project&gt;\r\n&nbsp;\r\n<\/pre>\n<p><span id=\"code\" \/><\/p>\n<h2>5. Implementation<\/h2>\n<p>We are running the code in a Windows operating system which Kiwi Syslog Server installed on it. On the other hand, an Ubuntu Server is listening its 514 port for syslog transmissions in the same network. We need to add two <b>SyslogAppenders<\/b> in order to send messages simultaneously to both of them. One of the appenders is for the Kiwi and the other one is for the Rsyslog in the Ubuntu Server. <\/p>\n<p><span style=\"text-decoration: underline\"><em>logback.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;wrap-lines:false\">\r\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;configuration&gt;\r\n\r\n\t&lt;appender name=\"KIWI\" class=\"ch.qos.logback.classic.net.SyslogAppender\"&gt;\r\n\t\t&lt;syslogHost&gt;localhost&lt;\/syslogHost&gt;\r\n\t\t&lt;facility&gt;LOCAL0&lt;\/facility&gt;\r\n\t\t&lt;suffixPattern&gt;%thread: %-5level %logger{36} - %msg%n&lt;\/suffixPattern&gt;\r\n\t&lt;\/appender&gt;\r\n\t\r\n\t&lt;appender name=\"RSYSLOG\" class=\"ch.qos.logback.classic.net.SyslogAppender\"&gt;\r\n\t    &lt;!-- Ubuntu Server host name --&gt;\r\n\t\t&lt;syslogHost&gt;cengaver&lt;\/syslogHost&gt;\r\n\t\t&lt;facility&gt;LOCAL1&lt;\/facility&gt;\r\n\t\t&lt;suffixPattern&gt;%thread: %-5level %logger{36} - %msg%n&lt;\/suffixPattern&gt;\r\n\t&lt;\/appender&gt;\r\n\r\n\t&lt;logger name=\"com.javacodegeeks.examples.logbacksyslogexample.message.kiwi\" level=\"INFO\"&gt;\r\n\t\t&lt;appender-ref ref=\"KIWI\" \/&gt;\r\n\t&lt;\/logger&gt;\r\n\r\n\t&lt;logger name=\"com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog\" level=\"INFO\"&gt;\r\n\t\t&lt;appender-ref ref=\"RSYSLOG\" \/&gt;\r\n\t&lt;\/logger&gt;\r\n\r\n&lt;\/configuration&gt;\r\n<\/pre>\n<p>The UML class diagram below demonstrates the overview of the application. We place the logger instances to appenders that associated to the different syslog servers, into two classes: <b>KiwiMessageTransmitterImpl<\/b> and <b>RsyslogMessageTransmitterImpl<\/b>. We generate these classes from an interface to provide an identical method signature and abstraction.<\/p>\n<p><figure id=\"attachment_22075\" aria-describedby=\"caption-attachment-22075\" style=\"width: 572px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img6.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img6.jpg\" alt=\"Example Class Diagram\" width=\"572\" height=\"294\" class=\"size-full wp-image-22075\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img6.jpg 572w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img6-300x154.jpg 300w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/a><figcaption id=\"caption-attachment-22075\" class=\"wp-caption-text\">Example Class Diagram<\/figcaption><\/figure><\/p>\n<p><span style=\"text-decoration: underline\"><em>IMessageTransmitter.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\npackage com.javacodegeeks.examples.logbacksyslogexample.message;\r\n\r\npublic interface IMessageTransmitter {\r\n\r\n\tvoid send( final String message );\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>KiwiMessageTransmitterImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\npackage com.javacodegeeks.examples.logbacksyslogexample.message.kiwi;\r\n\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\n\r\nimport com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;\r\n\r\npublic class KiwiMessageTransmitterImpl implements IMessageTransmitter {\r\n\r\n\tprivate static final Logger\tLOGGER\t= LoggerFactory.getLogger( KiwiMessageTransmitterImpl.class );\r\n\r\n\t@Override\r\n\tpublic void send( final String message ) {\r\n\t\tLOGGER.info( \"Hello! My message is : {}\", message );\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>RsyslogMessageTransmitterImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\npackage com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog;\r\n\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\n\r\nimport com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;\r\n\r\npublic class RsyslogMessageTransmitterImpl implements IMessageTransmitter {\r\n\r\n\tprivate static final Logger\tLOGGER\t= LoggerFactory.getLogger( RsyslogMessageTransmitterImpl.class );\r\n\r\n\t@Override\r\n\tpublic void send( final String message ) {\r\n\t\tLOGGER.info( \"Hello! My message is : {}\", message );\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>ApplicationStarter.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\npackage com.javacodegeeks.examples.logbacksyslogexample;\r\n\r\nimport com.javacodegeeks.examples.logbacksyslogexample.message.IMessageTransmitter;\r\nimport com.javacodegeeks.examples.logbacksyslogexample.message.kiwi.KiwiMessageTransmitterImpl;\r\nimport com.javacodegeeks.examples.logbacksyslogexample.message.rsyslog.RsyslogMessageTransmitterImpl;\r\n\r\npublic class ApplicationStarter {\r\n\r\n\t\/**\r\n\t * Main method\r\n\t *\/\r\n\tpublic static void main( final String[] args ) {\r\n\r\n\t\tfinal IMessageTransmitter kiwiMessageTransmitter = new KiwiMessageTransmitterImpl();\r\n\t\tkiwiMessageTransmitter.send( \"I am learning to send message to Syslog server\" );\r\n\r\n\t\tfinal IMessageTransmitter rsyslogMessageTransmitter = new RsyslogMessageTransmitterImpl();\r\n\t\trsyslogMessageTransmitter.send( \"Logback can easily send message to Syslog server\" );\r\n\t}\r\n}\r\n<\/pre>\n<p>In the main method, we create instances of the message implementation classes. After we invoke their service method ( send ) to cause logger statements in it to perform, the log messages are collected by the Syslog servers ( Kiwi and Rsyslog ) individually.<\/p>\n<p>Let&#8217;s look at the consequences in the Servers. In the Kiwi console:<\/p>\n<p><figure id=\"attachment_22082\" aria-describedby=\"caption-attachment-22082\" style=\"width: 845px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img7.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img7.jpg\" alt=\"Kiwi Screen Shot\" width=\"845\" height=\"226\" class=\"size-full wp-image-22082\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img7.jpg 845w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img7-300x80.jpg 300w\" sizes=\"(max-width: 845px) 100vw, 845px\" \/><\/a><figcaption id=\"caption-attachment-22082\" class=\"wp-caption-text\">Kiwi Screen Shot<\/figcaption><\/figure><\/p>\n<p>When we examine the <code>\"\/var\/log\/syslog\"<\/code> file in the Ubuntu Linux Server, we can see the messages come from our application:<\/p>\n<p><figure id=\"attachment_22085\" aria-describedby=\"caption-attachment-22085\" style=\"width: 669px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img8.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img8.jpg\" alt=\"Ubuntu Server Console\" width=\"669\" height=\"358\" class=\"size-full wp-image-22085\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img8.jpg 669w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslog_img8-300x160.jpg 300w\" sizes=\"(max-width: 669px) 100vw, 669px\" \/><\/a><figcaption id=\"caption-attachment-22085\" class=\"wp-caption-text\">Ubuntu Server Console<\/figcaption><\/figure><\/p>\n<h2>6. Download the Eclipse Project<\/h2>\n<p>This project illustrates how to send messages to the Syslog servers using Logback.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here : <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/logbacksyslogexample.zip\">logbacksyslogexample<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our guide book when we need to explore what is happening and what was happened in the code. In this post, we shall &hellip;<\/p>\n","protected":false},"author":48,"featured_media":12502,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[631],"tags":[],"class_list":["post-21992","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-logback"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logback Syslog Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logback Syslog Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/ilker.konar.7\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-08T08:00:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ilker Konar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ilker Konar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\"},\"author\":{\"name\":\"Ilker Konar\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116\"},\"headline\":\"Logback Syslog Example\",\"datePublished\":\"2015-04-08T08:00:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\"},\"wordCount\":1488,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg\",\"articleSection\":[\"Logback\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\",\"name\":\"Logback Syslog Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg\",\"datePublished\":\"2015-04-08T08:00:21+00:00\",\"description\":\"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Logback\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/logback\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Logback Syslog Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116\",\"name\":\"Ilker Konar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg\",\"caption\":\"Ilker Konar\"},\"description\":\"I am a senior software developer with experience mostly in java-related technologies with appliance in the telecommunication industry. I have been programming for more than fifteen years. I am passionate about programming. I like learning new frameworks, languages and design patterns.\",\"sameAs\":[\"http:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/\",\"http:\/\/www.facebook.com\/ilker.konar.7\",\"https:\/\/www.linkedin.com\/in\/ilkerkonar\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logback Syslog Example - Java Code Geeks","description":"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/","og_locale":"en_US","og_type":"article","og_title":"Logback Syslog Example - Java Code Geeks","og_description":"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"http:\/\/www.facebook.com\/ilker.konar.7","article_published_time":"2015-04-08T08:00:21+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg","type":"image\/jpeg"}],"author":"Ilker Konar","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ilker Konar","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/"},"author":{"name":"Ilker Konar","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116"},"headline":"Logback Syslog Example","datePublished":"2015-04-08T08:00:21+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/"},"wordCount":1488,"commentCount":5,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg","articleSection":["Logback"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/","name":"Logback Syslog Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg","datePublished":"2015-04-08T08:00:21+00:00","description":"Logging is an essential part of a program. We can trace the flow of the program, we can find out the root cause of a bug in the program. Logs are like our","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logback-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/logback\/logback-syslog-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"Logback","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/logback\/"},{"@type":"ListItem","position":5,"name":"Logback Syslog Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116","name":"Ilker Konar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg","caption":"Ilker Konar"},"description":"I am a senior software developer with experience mostly in java-related technologies with appliance in the telecommunication industry. I have been programming for more than fifteen years. I am passionate about programming. I like learning new frameworks, languages and design patterns.","sameAs":["http:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/","http:\/\/www.facebook.com\/ilker.konar.7","https:\/\/www.linkedin.com\/in\/ilkerkonar"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/21992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=21992"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/21992\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/12502"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=21992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=21992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=21992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}