<?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 Mannie Sah on Medium]]></title>
        <description><![CDATA[Stories by Mannie Sah on Medium]]></description>
        <link>https://medium.com/@manniesah?source=rss-485ace4fc2d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u6GapEBMCXgHgxkqroWIOw.png</url>
            <title>Stories by Mannie Sah on Medium</title>
            <link>https://medium.com/@manniesah?source=rss-485ace4fc2d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:53:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manniesah/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[Custom Logging Levels using Log4j 1.2]]></title>
            <link>https://medium.com/@manniesah/custom-logging-levels-using-log4j-1-2-68d1b41d4d7c?source=rss-485ace4fc2d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/68d1b41d4d7c</guid>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Mannie Sah]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 13:53:19 GMT</pubDate>
            <atom:updated>2018-08-26T14:04:06.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*mdfHyoKIFSnKswxx3RblSg.png" /></figure><p>In my career of all aspects of software development, i have come across multiple scenarios where we need a little more logging in production where ERROR logging level is not enough. Sometimes, we need some more information on what was going on during the transaction. However, logging levels like INFO which is perhaps designed for higher environment than development and lower than production becomes too verbose for production.</p><p>To address this need, i found a way which comes out of the box from log4j for java applications. Coming across this need over and over again, i decided to write this story about how to easily implement a custom logging level using <a href="https://cwiki.apache.org/confluence/display/LOGGING/Log4j">log4j</a>.</p><p>For this demonstration, i am using log4j 1.2. (Even though Log4j 1.2 has reached end of life i know lot of projects are still using this. So, i hope this might help someone.)</p><p>Prerequisite:</p><ul><li>Understanding of how to configure log4j 1.2 for logging in Java applications</li><li>Maven: This example uses maven, same thing can be done using gradle or other build tools</li></ul><p>The code for this example is in a git repository <a href="https://github.com/mannie-logging/custom-log-levels">here</a>.</p><h3>What do we need:</h3><ul><li>Defining project with pom.xml for maven</li><li>Create a Custom logging level</li><li>Have appropriate logging level in log4j.properties (For this example, we will consider ERROR)</li><li>Class where this custom logging level is used</li><li>Test class to invoke the logging method</li></ul><h4>Defining project with pom.xml</h4><p>Only 2 dependencies are needed for this test:</p><ul><li>junit 4.x</li><li>log4j 1.2.x</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ae498d4616d0c4215e4a82f6be7e4bb/href">https://medium.com/media/3ae498d4616d0c4215e4a82f6be7e4bb/href</a></iframe><h4>Creating Custom logging level</h4><p>Create a class as shown below which defines the custom logging level</p><ul><li>The custom logging level name is <strong><em>FUNNY</em></strong>.</li><li>The <em>int</em> value for <strong><em>FUNNY </em></strong>logging level is<strong><em> ERROR_INT + 10</em></strong><em> </em>(Line#5). This makes these logs show up when the logging level of the application is set to <strong><em>ERROR</em></strong><em>.</em></li><li>Initialization of <strong><em>FUNNY</em></strong> logging level happens at Line#7 using the constructor defined at Line#9.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f1b0d5d93f1ced1e3c67d084f596d7c/href">https://medium.com/media/7f1b0d5d93f1ced1e3c67d084f596d7c/href</a></iframe><p><em>Side note: Why is the FUNNY_INT set to ERROR_INT +10? What does that mean? As shown in below image (Image is a snippet from </em><a href="https://logging.apache.org/log4j/1.2/apidocs/constant-values.html#org.apache.log4j.Priority.ALL_INT"><em>Apache Log4j 1.2</em></a><em>), ERROR_INT is defined as 40,000, so when the logging level is set to ERROR, it will print all log statements with priority 40,000 and higher and hence </em><strong><em>ERROR_INT + 10</em></strong><em> is also shown. (</em><strong><em>Beware: </em></strong><em>This is changing big time in Log4j2.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*dOhOMdw3j7OgY3SldR8DkA.png" /></figure><h4><em>logging.properties</em></h4><ul><li>Goes in src/test/resources because we are testing using a Test class. Otherwise this would be in src/main/resources</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6426514043499ac49f1a438df15ff4b/href">https://medium.com/media/e6426514043499ac49f1a438df15ff4b/href</a></iframe><h4>Class using the logging level for logging statements</h4><ul><li>FunnyLogging.java in src/main/java with appropriate package name</li><li>FunnyLogging.java is using the <strong><em>FUNNY </em></strong>logging level at Line#11</li><li>Along with ERROR logging at Line#12 and DEBUG logging at Line#15</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc1b97be850b016b86b1e1b2f642bb67/href">https://medium.com/media/dc1b97be850b016b86b1e1b2f642bb67/href</a></iframe><h4>Test Class to invoke the logging</h4><ul><li>FunnyLoggingTest.java in src/main/test with appropriate package name</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd7bb0b99d508a4444cc5cb0032cdc73/href">https://medium.com/media/cd7bb0b99d508a4444cc5cb0032cdc73/href</a></iframe><p>Now, we can go to the root of the project and run the test.</p><pre>mvn clean test</pre><p>This should show output with other logs as below:</p><pre>-------------------------------------------------------</pre><pre>T E S T S</pre><pre>-------------------------------------------------------</pre><pre>Running com.mannietest.customloglevellogj12.customlevel.FunnyLoggingTest</pre><pre>2018-08-24 15:51:42 FUNNY FunnyLogging:13 - I am a Funny log, because the Log level set is ERROR and my log level is FUNNY!!</pre><pre>2018-08-24 15:51:42 ERROR FunnyLogging:14 - I am an ERROR message</pre><pre>Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.163 sec</pre><p>We see that <strong><em>FUNNY </em></strong>logs are printed but <strong><em>DEBUG</em></strong> is <strong><em>not</em></strong>, this is because the logging level for application in logging.properties is set to ERROR.</p><p>Same approach can be used if we want custom logging level to be printed along with INFO or DEBUG. Why would we do this? To be able to search specific logs easily along with DEBUG logs from the pile of logs.</p><p>The code for the ERROR level example is available in a git repository <a href="https://github.com/mannie-logging/custom-log-levels">here</a>.</p><p>We could do the same thing using Log4j 2, i will share that story next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68d1b41d4d7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Controlling 5V DC Motor using Raspberry Pi 3 Model B+]]></title>
            <link>https://medium.com/@manniesah/turning-on-5v-dc-motor-from-raspberry-pi-3-model-b-d0875df974da?source=rss-485ace4fc2d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0875df974da</guid>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[raspberry-pi-3]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mannie Sah]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 15:16:43 GMT</pubDate>
            <atom:updated>2018-08-29T22:49:33.821Z</atom:updated>
            <content:encoded><![CDATA[<p>In this demonstration, i will show how to turn on a 5V DC Motor using a Raspberry Pi 3 Model B+. Being able to control a motor from Raspberry Pi can help in building robots, remote controlled garage doors, remote controlled fans or other appliances.</p><h3><strong>What all do we need?</strong></h3><ul><li><a href="https://www.amazon.com/V-Kits-Raspberry-Model-Starter-LATEST/dp/B07BDRD3LP?ref=ast_p_ep">Raspberry Pi 3 Model B+</a> installed with Raspian.</li></ul><p>Version information below.</p><pre>$cat /etc/os-release<br>PRETTY_NAME=&quot;Raspbian GNU/Linux 9 (stretch)&quot;<br>NAME=&quot;Raspbian GNU/Linux&quot;<br>VERSION_ID=&quot;9&quot;<br>VERSION=&quot;9 (stretch)&quot;<br>ID=raspbian<br>ID_LIKE=debian<br>HOME_URL=&quot;http://www.raspbian.org/&quot;<br>SUPPORT_URL=&quot;http://www.raspbian.org/RaspbianForums&quot;<br>BUG_REPORT_URL=&quot;http://www.raspbian.org/RaspbianBugs&quot;</pre><ul><li>Python: Installed on Raspberry Pi. Its possible its pre-installed. Version information below.</li></ul><pre>$python --version<br>Python 2.7.13</pre><ul><li>Breadboard: This is where all the connections go on.</li><li>Cables/Wires: To make the connections.</li><li><a href="https://www.amazon.com/PIXNOR-16-pin-Stepper-Drivers-Controllers/dp/B00ODQM8KC/ref=sr_1_3?ie=UTF8&amp;qid=1534757574&amp;sr=8-3&amp;keywords=L293D">L293D</a> Motor driver chip</li><li><a href="https://www.amazon.com/dp/B077WWS63B/ref=sspa_dk_detail_1?psc=1&amp;pd_rd_i=B077WWS63B&amp;pd_rd_wg=buEEI&amp;pd_rd_r=4SZHFYCW960W95RCZTNZ&amp;pd_rd_w=UjYLK">1 DC Motor 5V</a></li><li>2 AA Batteries</li><li>1 Battery Holder</li></ul><h4><strong>Reading PIN Numbers on Raspberry Pi</strong></h4><p>PINs on Raspberry Pi: Figure#1is an image showing all the pins of Raspberry Pi 3 Model B+ (It has 40 Pins).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6m313ho-ySV8hPA1k2XsBQ.png" /><figcaption>Figure#1: GPIO Pins on Raspberry Pi</figcaption></figure><ul><li>The numbers inside the RED box is the PIN Numbers which can be used in BOARD mode.</li></ul><pre>GPIO.setmode(GPIO.BOARD)</pre><ul><li>The numbers outside the RED box, for example GPIO2 or GPIO14 or GPIOx are the notations to be used in BCM Mode. I generally prefer BOARD mode.</li></ul><pre>GPIO.setmode(GPIO.BCM)</pre><h4>Reading Pin numbers on L293D Chip</h4><p>I have gone through multiple articles and where the PIN#1 started from seemed different in different articles. After few trials and errors, i came up with the Figure#2 reference image. <a href="https://elec-club-iitb.github.io/blog/2016/08/l293d/">And based on some other articles (one of them linked here), this looks accurate</a>. However, this is the reference i will be using for this demonstration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qii3UmKdOxQVLv1AMdQbsg.png" /><figcaption>Figure#2: Pins of L293D</figcaption></figure><h3><strong>Begin Connections</strong></h3><p>It is recommended to have the Pi turned off when making multiple connections to avoid short-circuits on accident.</p><p>I have color coded all my wires that i used for connections as below:</p><p><em>Note: I am using BOARD mode for PIN numbers on Pi</em></p><ul><li>Red: Power from PI</li><li>Black: Ground</li><li>Green: Pi PIN#36</li><li>Yellow: Pi PIN#38</li><li>Orange: Pi PIN#40</li><li>White: Connection from L293D to Motor. PIN#3 and PIN#6 of L293D to Motor.</li><li>Blue: Battery to L293D PIN#9</li></ul><h4>Sequence of connections</h4><p>Connect 5V(Pi PIN#2) to L293D PIN#1(Enable PIN) (Red Cable)</p><p>Connect Ground (Black Cables)</p><ol><li>We are using Raspberry Pi PIN#6 for the ground</li><li>We are connecting ground on breadboard to the vertical connections, so we don’t have to use multiple ground pins on the Pi. Instead, we could use the vertical connections. As shown in the screenshot, if the Ground is connected as shown in <em>label#1</em> on the image, the whole vertical line is ground now.</li></ol><p>Figure#3 shows the above connections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*UhhffsLib9H3QiBrF3-ruw.jpeg" /><figcaption>Figure#3: Inital Enabling of L293D</figcaption></figure><p>For easy access to the ground on the both sides of breadboard, we connect the vertical line with vertical line on other side as shown in below image.</p><p>Continue on Grounds for L293D, below are the PINS on L293D which need to be grounded. PINS #4, #5, #12 and #13 are ground pins. (Black Cables)</p><p>Figure#4 shows more ground connections to L293D:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*R6Je0vQFZCOonlTWAWw1hg.jpeg" /><figcaption>Figure#4: L293D Ground Connections</figcaption></figure><p>Connect Pi’s GPIO to L293D</p><ol><li>Pi PIN#36 to L293D PIN#2 (Green Cable)</li><li>Pi PIN#38 to L293D PIN#7 (Yellow Cable)</li><li>Pi PIN#40 to L293D PIN#8 (Orange Cable)</li></ol><p>Figure#5 shows the GPIO to Chip connections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*REt89RbZnmwNtu3ef4_ZXg.jpeg" /><figcaption>Figure#5: GPIO to L293D</figcaption></figure><p>Connect Power using AA Battery to L293D Chip</p><ol><li>Connect the PIN#9 of L293D Chip with one of the vertical connections which is not used by ground. (Blue Cable)</li></ol><p>2. Connect the Batteries’s Positive to the vertical connection same as PIN#9&#39;s.</p><p>3. Connect the Batteries’s Negative to <em>ground</em>.</p><p>Connect Motor with L293D Chip (While Cables)</p><ol><li>Connect Motor with PIN#3 and #6 of L293D</li></ol><p>Figure#6 shows Battery and motor connections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*whEEAZiVHA_zD7sQebTuiA.jpeg" /><figcaption>Figure#6: Batttery and Motor connected to L293D</figcaption></figure><p>Connections are all done.</p><p>Power up the Raspberry Pi</p><h3><strong>Write the Code</strong></h3><p>Create a file with a name of your preference with <em>“.py”</em> extension. For this demo, let’s call it motor.py and paste the below code into this file.</p><pre>import RPi.GPIO as GPIO <br>from time import sleep  </pre><pre>GPIO.setmode(GPIO.BOARD)             #1</pre><pre>Motor1A = 36 <br>Motor1B = 38 <br>Motor1E = 40 </pre><pre>GPIO.setup(Motor1A,GPIO.OUT)         #2<br>GPIO.setup(Motor1B,GPIO.OUT) <br>GPIO.setup(Motor1E,GPIO.OUT)</pre><pre>try:<br>    print &quot;Turning motor on&quot;<br>    GPIO.output(Motor1A,GPIO.HIGH)   #3<br>    GPIO.output(Motor1B,GPIO.LOW)<br>    GPIO.output(Motor1E,GPIO.HIGH)</pre><pre>    sleep(10)</pre><pre>    print &quot;Stopping motor&quot;<br>    GPIO.output(Motor1E,GPIO.LOW)    #4</pre><pre>finally:<br>    GPIO.output(Motor1E,GPIO.LOW)    #5<br>    GPIO.cleanup()                   #6</pre><p>In above code, we see the below happening: (The line numbers represented are serial numbers of the below.)</p><ol><li>We are using BOARD mode</li></ol><p>2. We are using PIN#36, #38 and #40 of GPIO as OUT mode.</p><p>3. To run the motor, we provide value of 1 or HIGH to PIN#36 and PIN#40 and 0 or LOW to PIN#38.</p><p>4. We sleep for 10 seconds, that means the motor will run for 10 seconds (This is how long the motor will run because during this time the PINS are with value 1 or HIGH)</p><p>5. To shutdown the motor, we pass value of 0 or LOW to PIN#40.</p><p>6. Finally, we clean up to reset all GPIO pins of Raspberry to its default values.</p><p><strong>All Set, Ready to run the motor?</strong></p><p>Go to the directory where the above file is stored from command line and run the below command. (If you used a different file name, use that file name.)</p><pre>$python motor.py</pre><p>The motor should have started running. And the terminal would show below:</p><pre>$python motor.py<br>Turning motor on</pre><p>After running for 10 seconds, the motor should have stopped. And the terminal would show below:</p><pre>$python motor.py<br>Turning motor on<br>Stopping motor<br>$</pre><p>So, now we have the motor running by passing signal from Raspberry Pi. There are more things that can be done like controlling the direction and speed of the motor and controlling more than one motor. We will look at those things in upcoming stories.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0875df974da" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>