<?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 Joseph Sarpong on Medium]]></title>
        <description><![CDATA[Stories by Joseph Sarpong on Medium]]></description>
        <link>https://medium.com/@joseph.sarpong3?source=rss-7a335caa8576------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u5H9l6Nx-yOELUBnkASvsw.jpeg</url>
            <title>Stories by Joseph Sarpong on Medium</title>
            <link>https://medium.com/@joseph.sarpong3?source=rss-7a335caa8576------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:03:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joseph.sarpong3/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[What are we really looking for?]]></title>
            <link>https://medium.com/@joseph.sarpong3/what-are-we-really-looking-for-009b07ddd8c5?source=rss-7a335caa8576------2</link>
            <guid isPermaLink="false">https://medium.com/p/009b07ddd8c5</guid>
            <category><![CDATA[relationships]]></category>
            <category><![CDATA[relationships-love-dating]]></category>
            <category><![CDATA[love]]></category>
            <dc:creator><![CDATA[Joseph Sarpong]]></dc:creator>
            <pubDate>Wed, 25 Dec 2024 13:44:48 GMT</pubDate>
            <atom:updated>2024-12-25T13:44:48.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*wGOSjlRzvSdC5BY4jC_FIQ.jpeg" /></figure><p>What we are looking for is not love! Yes, you read that right. We’ve all heard someone, a friend, a close relative say or even we have said to ourselves “I am looking for love”. Perhaps you recommended or made a list of a few places to find it. Haha. But what did we mean by “looking for love”? Are we looking for someone to love or someone to love us? The answer is almost never the first. What we are really looking for is not love.</p><p>In this article, we will be discussing why “what we are looking for is not love”. Afterwards we’ll talk about what we are really looking for and how to increase our chances of getting it.</p><p>In order to understand that “What we are looking for is not love”, we first need to know what love is. So what is Love? I like the definition given by Tilda Swinton, when she played Alithea Binnie in the 2022 fantasy drama, Three Thousand Years of Longing. She said <em>“Love is a gift, it is a gift of oneself given freely. It’s not something one can ever ask for”</em>. A gift or a present is an item given to someone without the expectation of payment or anything in return. The expectation here is a two-way road, The giver of the said gift is not expecting anything in return and the beneficiary or receiver was not expecting the gift.</p><p>We cannot go around looking for someone to give us a gift, can we? If we do, is it a gift? So love isn’t something that you seek. Rather, love seeks you. Love is not about you. Love is about loving another person. Love is giving yourself for the good of others at the expense of yourself not only at one’s convenience. According to Orion Taraban, Psy.D. Love wants only to remain in the presence of the loved one but is willing to sacrifice even that for the good of the loved one. This is demonstrated by the greatest love of all ever recorded in the 3rd chapter of the Bible book of John. The 16th verse says “For God loved the world so much that he gave his only-begotten Son, so that everyone exercising faith in him might not be destroyed but have everlasting life”.</p><p>How do we know that this was a gift? Let’s break it down with the following questions.</p><ol><li>Did the world expect this gift?</li><li>Did we ask for it?</li><li>Are we expected to give something in return for this gift?</li><li>Is the giver complaining about giving it?</li></ol><p>I’m certain you have answers to these questions. Love isn’t pained by loss so it makes the statement “no love without freedom” a true one. That is to say if you find this love you claim to be looking for, will you happily let the other person go if he/she wants to go? Love isn’t about you, remember? Will you happily let them chase what makes them happy even if it doesn’t involve you? If they didn’t do anything that you wanted or liked, would you keep treating them with “love”? Remember love isn’t about you. Love does not expect anything in return so there’s nothing to compromise. Love is giving attention where it is not returned. Love is in giving, not in seeking gifts. Love is not self-seeking.</p><p>Love does not restrict itself to format. When we “look for love”, males generally look for females and females look for males within the same age group. Love doesn’t restrict itself to these formats. Love can be between a 90 year old and a 3 year old. So is it really love we are looking for?</p><p>So what do we really mean when we say we’re looking for love? We rarely say this when we’re content where we are. If we’re satisfied, feel whole and happy within, we do not “look for love”. It is during the times that we need something that we cannot provide for ourselves that we “look for love”. So when we say we’re looking for love, these are some of the things we mean:</p><ul><li>“I’m looking for someone who will give me attention or affection when I crave it”</li><li>“I’m looking for someone who can cook really well to cook for me”</li><li>“I’m looking for someone who is available to talk when I need to talk”</li><li>“I’m looking for someone who can provide my basic needs”</li><li>“I’m looking for someone who will be available when I want sex”</li></ul><p>These are some reasons why we “are looking for love”. In essence we are expecting something in return even before setting out to “look for love”. Is it really love we’re looking for?</p><p>What then are we looking for if it is not love? We’re looking for ways of having our needs or wants met. It’s a hard pill to swallow but that’s what it really is. We only wrap love around it because we do not want to have to work for it. We want to get our needs met by another person without working or giving anything back for it. So wrapping love around it is a way of manipulating the other person to meet our needs. “If you truly love me you’ll do this for me”. Would you still stay true to this other person even if your needs are not being met? Would you still stay close if they did things to put you off all the time? The answer to these is rarely a yes. So what are you really looking for? What you’re looking for is a relationship. Yes, a Relationship!</p><p>A relationship is the medium in which value is transacted and love has nothing to do with it. You read that right. All relationships are transactional and mutually exclusive of love. This is not a bad thing. A transaction is nothing but an energy exchange. Relationships have compromises, one thing is given up for another at the same time or a later time. Relationships are based on established rules(communicated or not) — this is what is allowed and not allowed. Relations have definitions — this is what it is and this is what it isn’t. This is because we need rules, definitions and compromises in order to transact(do business) with one another. This does not mean there isn’t mutual care for one another in the relationship. In fact by being transactional in our relationships we will tend to care well for the other party. Here are some examples of transactions given by Teal Swan in her Be Consciously Transactional. Why Every Relationship is Transactional video:</p><ul><li>In a friendship you give a person the feeling of being free and unrestricted and they give you that sense of security you’ve always lacked.</li><li>With this partner, they give you the sense of being needed and wanted and valued and you give them the support they need to accomplish their goals.</li><li>With this person you’re helping, they get the help they need and you get the sense of your own goodness. Also that feel-good feeling of doing the right thing.</li><li>With this family member, you give them your availability and understanding and they give you the same.</li></ul><p>If we need things from others, then we don’t want love. We want a relationship. To quote Orion Taraban “We want to do business and there’s nothing wrong with that except the rampant hypocrisy that wants to pretend that that’s not what it’s doing. And that’s because wanting a relationship is the right thing to want if you want things from other people and that is because a relationship is the medium through which value is transacted. So if you want to do business, get yourself down to the market and prepare to barter with what you have to offer. If you want a lot, be prepared to bring a lot to the bargaining table“. Let’s be real and honest with ourselves.</p><p>Now that we know what we really want, that is a relationship. How do we increase our chances of getting one? Because we’re entering this relationship to get our needs met, we need to define our needs and know what they are. If we do not know what our needs are, how do we expect to find someone who can meet them? Mind you needs change, and when they do, relationships change too. We need to communicate the change to the other party. We need to know what value we have and are willing to contribute to the other party. That way we can know if we have what the other party needs in the relationship. Know that a person has to truly need something in order to value it.</p><p>We need to be consciously transactional in our relationships. By this I mean being aware of what we’re being involved in here. Since we know relationships have a definition, rules and compromises, we need to:</p><ol><li>Define the nature of our relationships. Sit and talk to the other party about what it is you’re doing.</li><li>establish and communicate these rules without assuming the other party knows the rules.</li><li>Talk about things you’re willing to compromise. If push comes to shove will you be willing to switch religion, bring a career that you’ve spent your whole life working on to an end etc? Do not assume that the other party will do these without hearing it from them.</li></ol><p>These are ways that I think we can manage our expectations and remain happy in our relationships. That said, go for what you want, not what you think you can get</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=009b07ddd8c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging in Django — Part II [Filters and Formatters]]]></title>
            <link>https://medium.com/django-unleashed/logging-in-django-part-ii-filters-and-formatters-c7190d360ab2?source=rss-7a335caa8576------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7190d360ab2</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Joseph Sarpong]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 17:33:49 GMT</pubDate>
            <atom:updated>2024-01-20T17:03:13.623Z</atom:updated>
            <content:encoded><![CDATA[<h3>Logging in Django — Part II [Filters and Formatters]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1etZXcdBNLSBuOIwZEirvg.png" /></figure><p>In the <a href="https://link.medium.com/Qngo9xVGsGb">first part of this article series</a>, we talked about loggers and handlers in python. As a natural progression, we continue in this part with Filters and Formatter.</p><p>A<strong> Filter</strong> provides a mechanism to control which log records are emitted or modified based on specific criteria. Adding a filter to a handler will cause the handler to emit logs that only pass the filter criteria. For example, we could create a filter for logs that are CRITICAL and attach it to a FileHandler, and the FileHandler will only log CRITICAL events. To create a filter, we have to extend logging.Filter and implement the filter() method. Let’s see how we would do this for the filter criteria we talked about earlier.</p><pre>import logging<br><br>#create a Filter class<br>class LevelFilter(logging.Filter):<br> def filter(self, record):<br>  return record.levelname == &quot;CRITICAL&quot;<br><br>#create an instance of the filter<br>levelFilter = LevelFilter()<br><br>#create a handler<br>fileHandler = logging.FileHandler(&quot;try_log&quot;)<br><br># add filter to the handler<br>fileHandler.addFilter(levelFilter)<br><br># Create logger and set level to debug<br>fileLogger = logging.getLogger(__name__)<br>fileLogger.setLevel(&quot;DEBUG&quot;)<br><br># add a FileHandler<br>fileLogger.addHandler(fileHandler)<br><br># test it with different log levels<br>fileLogger.debug(&quot;something just happened&quot;)<br>fileLogger.critical(&quot;something critical just happened&quot;)</pre><p>In the above snippet, we created a filter class, attached an instance of it to a handler and added the handler to a logger. When the code is ran, a log file with name <em>try_log</em> is created and “something critical just happened” is written to it leaving behind the debug log. Using the power of filters, we can have log files for different log levels.</p><p>Up until this point, the logs we have seen are just messages, they did not contain the time of the logs and the severity of the events. The time of an event is another very important aspect of logging and the way we get it to show is by defining <strong>formatters</strong> for our logger.</p><p><strong>Formatter</strong>: defines the structure of log a log record, specifying what information to include (like timestamps, log levels, etc.) and how it should be formatted. They play a crucial role in controlling the appearance of these log messages. We create a formatter by instantiating logging.Formatter() . We can pass our defined format as the first parameter to the formatter. Lets see how we can define our formats.</p><p>You have seen some log messages like this:<br>[Jan 18 12:55:33] [7]:INFO: Booting worker with pid: 7 <br>we see that this log shows us the time of the event, process id of the event that emitted the log, log level and message. we can define similar formats by using attributes for the LogRecord . The LogRecord has these useful attributes:</p><pre>    %(name)s            Name of the logger (logging channel)<br>    %(levelno)s         Numeric logging level for the message (DEBUG, INFO,<br>                        WARNING, ERROR, CRITICAL)<br>    %(levelname)s       Text logging level for the message (&quot;DEBUG&quot;, &quot;INFO&quot;,<br>                        &quot;WARNING&quot;, &quot;ERROR&quot;, &quot;CRITICAL&quot;)<br>    %(pathname)s        Full pathname of the source file where the logging<br>                        call was issued (if available)<br>    %(filename)s        Filename portion of pathname<br>    %(module)s          Module (name portion of filename)<br>    %(lineno)d          Source line number where the logging call was issued<br>                        (if available)<br>    %(funcName)s        Function name<br>    %(created)f         Time when the LogRecord was created (time.time()<br>                        return value)<br>    %(asctime)s         Textual time when the LogRecord was created<br>    %(msecs)d           Millisecond portion of the creation time<br>    %(relativeCreated)d Time in milliseconds when the LogRecord was created,<br>                        relative to the time the logging module was loaded<br>                        (typically at application startup time)<br>    %(thread)d          Thread ID (if available)<br>    %(threadName)s      Thread name (if available)<br>    %(process)d         Process ID (if available)<br>    %(message)s         The result of record.getMessage(), computed just as<br>                        the record is emitted</pre><p>these attributes can be used to form a useful format that you want your logs to show in. Let’s work with an example to see this at work. In the example, we’ll use the asctime, levelname and message in our formatter</p><pre>import logging<br><br>#create a formatter<br>formatter = logging.Formatter(&quot;[%(asctime)s] %(levelname)s: %(message)s&quot;)<br><br>#create a Filter class<br>class LevelFilter(logging.Filter):<br> def filter(self, record):<br>  return record.levelname == &quot;CRITICAL&quot;<br><br>#create an instance of the filter<br>levelFilter = LevelFilter()<br><br>#create a handler<br>fileHandler = logging.FileHandler(&quot;try_log&quot;)<br><br># add filter to handler<br>fileHandler.addFilter(levelFilter)<br><br>#set formatter for handler<br>fileHandler.setFormatter(formatter)<br><br># Create logger and set level to debug<br>fileLogger = logging.getLogger(__name__)<br>fileLogger.setLevel(&quot;DEBUG&quot;)<br><br># add a FileHandler<br>fileLogger.addHandler(fileHandler)<br><br>fileLogger.critical(&quot;something critical just happened&quot;)</pre><p>in the snippet above we define our own format for our logger. Being able to do this gives us the opportunity to customize log messages that suits our team and application. Running this creates a file try_log with this log:</p><p>[2024–01–19 13:13:46,001] CRITICAL: something critical just happened</p><p>Being able to control our formatter gives us the ability to show loggers the way we want them.</p><p>Now that we know all about the different aspects of logging in python, lets look at another approach to configure them. Logging can be configured in 3 ways in python:</p><ol><li>Creating loggers, handlers, filters and formatters explicitly as we have up until this point.</li><li>Creating a logging config file and reading it using the <a href="https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig">fileConfig()</a> function.</li><li>Creating a dictionary of configuration information and passing it to the <a href="https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig">dictConfig()</a> function.</li></ol><p>The approach that is used in django is the third. This approach defines the logging configuration as a dictionary. The dictionary that is passed must contain version, formatters, filters, handlers, loggers, root, incremental and disable_existing_loggers as keys. Find more about these keys <a href="https://docs.python.org/3/library/logging.config.html#dictionary-schema-details">here</a>. Lets rewrite our previous snippets in this format so we get a hang of it:</p><pre>import logging.config<br><br>#create a Filter class<br>class LevelFilter(logging.Filter):<br> def filter(self, record):<br>  return record.levelname == &quot;CRITICAL&quot;<br><br><br>log_config = {<br>    &quot;version&quot;: 1,<br>    &quot;formatters&quot;: {<br>        &quot;myFormatter&quot;: {<br>            &quot;format&quot;: &quot;[%(asctime)s] %(levelname)s: %(message)s&quot;<br>        }<br>    },<br>    &quot;handlers&quot;: {<br>        &quot;fileHandler&quot;: {<br>            &quot;class&quot;: &quot;logging.FileHandler&quot;,<br>            &quot;filename&quot;: &quot;try_log&quot;,<br>            &quot;formatter&quot;: &quot;myFormatter&quot;,<br>            &quot;filters&quot;: [&quot;levelFilter&quot;]<br>        }<br>    },<br>    &quot;loggers&quot;: {<br>        &quot;fileLogger&quot;: {<br>            &quot;level&quot;: &quot;DEBUG&quot;,<br>            &quot;handlers&quot;: [&quot;fileHandler&quot;]<br>        }<br>    },<br>    &quot;filters&quot;: {<br>        &quot;levelFilter&quot;: {<br>            &quot;()&quot;: &quot;__main__.LevelFilter&quot;<br>        }<br>    }<br>}<br><br>logging.config.dictConfig(log_config)<br># logging.critical(&quot;something critical just happened&quot;)<br>logger = logging.getLogger(&quot;fileLogger&quot;)<br>logger.critical(&quot;something critical just happened&quot;)</pre><p>In the snippet above we defined our logging configuration as a dictionary and read it with logging.config.dictConfig(). If you copy this into a file and run it. You will notice a new file try_log created with the log record in it. This approach is prettry concise and straight forward.</p><p>So here’s the end of the second part of the article series on logging. I hope that you found this very useful. In the next and final part of this series, we will be diving deep into django’s default logging configuration and how to extend it. Understanding this and the previous part of the series will form a solid foundation for the next part and configuring useful logs for your python application. Leave a comment, lets get talking.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7190d360ab2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-unleashed/logging-in-django-part-ii-filters-and-formatters-c7190d360ab2">Logging in Django — Part II [Filters and Formatters]</a> was originally published in <a href="https://medium.com/django-unleashed">Django Unleashed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging in Django — Part I]]></title>
            <link>https://medium.com/django-unleashed/logging-in-django-part-i-e3b0a1d0457d?source=rss-7a335caa8576------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3b0a1d0457d</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[Joseph Sarpong]]></dc:creator>
            <pubDate>Thu, 18 Jan 2024 14:11:20 GMT</pubDate>
            <atom:updated>2024-01-18T14:11:20.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Logging in Django — Part I [Loggers and Handlers]</h3><p>“There is an error but I do not know exactly what is causing it”. If you are into developing software, then you have heard this statement or even said it yourself and you can understand how frustrating it is to not have a clue of what the cause of an error is. Many parts come together to make a good software and one such part is logging or logs. With good logging practices and some luck your system will point you exactly where an issue is, saving you and your team hours of debugging.</p><p>Django as a great web framework provides a good mechanism for logging. Django extends Python’s builtin logging module and in this 3-part article series, we’ll be looking at logging, how to configure loggers in python to get the best out of them and how Django extends this.</p><p>Logging is a means of tracking events that happen when some software runs. Each of these events have some level of severity that we attach to it called <em>log level</em>. Log levels in python in the order of severity are DEBUG, INFO, WARN, ERROR, CRITICAL. For example if your app cannot connect to your database, it is a CRITICAL information because your app may not start because of this. Log levels have numeric values: DEBUG(10), INFO(20), WARN(30), ERROR(40), CRITICAL(50). The log level specifies the minimum severity of logs to track. For example, a logger with log level of WARNING will still catch ERROR and CRITICAL logs, setting the level to DEBUG will catch all logs levels. Below is a summary of log levels and when they are used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9w1BosAx5TJsygM1mdxo_w.png" /><figcaption>Log levels and when to use it.</figcaption></figure><p>The logging module in Python has 4 components that it works with:<br><strong>Logger</strong>: the logger is the main object responsible for capturing log messages. The default log level of a python logger object is WARNING. Lets create a logger:</p><pre>&gt;&gt;&gt; import logging<br>&gt;&gt;&gt; logger = logging.getLogger()<br>&gt;&gt;&gt; logger.<br>logger.addFilter(          logger.error(              logger.getChild(           logger.isEnabledFor(       logger.parent              logger.warn(              <br>logger.addHandler(         logger.exception(          logger.getEffectiveLevel() logger.level               logger.propagate           logger.warning(           <br>logger.callHandlers(       logger.fatal(              logger.handle(             logger.log(                logger.removeFilter(      <br>logger.critical(           logger.filter(             logger.handlers            logger.makeRecord(         logger.removeHandler(     <br>logger.debug(              logger.filters             logger.hasHandlers()       logger.manager             logger.root               <br>logger.disabled            logger.findCaller(         logger.info(               logger.name                logger.setLevel(<br><br>&gt;&gt;&gt; #above are the attributes of the logger we just created.<br>&gt;&gt;&gt; logger.name<br>&#39;root&#39;<br>&gt;&gt;&gt; logger.level<br>30</pre><p>Notice how the logger was not created with logging.Logger() but rather logging.getLogger() . logging.getLogger() optionally takes the nameof the logger and returns the logger instance if it already exists else it creates it. We see also the attributes of the logger object in the code snippet above. When the name parameter of getLogger() is not provided, the logger that is returned has the name root . The log level by default is 30 which is the numeric value for WARNING. Log levels can be set using the setLevel() method of the Logger instance.</p><pre>&gt;&gt;&gt; logger.setLevel(30)<br>&gt;&gt;&gt; print(logger.level)<br>30<br>&gt;&gt;&gt; # you can also set the log level by using the string value of the level<br>&gt;&gt;&gt; logger.setLevel(&quot;CRITICAL&quot;)<br>&gt;&gt;&gt; print(logger.level)<br>50</pre><p>Where’s the root from? The root Logger is the ancestor logger that all loggers inherit from. So every logger you create in python will have the root logger as it’s parent. Lets see this in action:</p><pre>&gt;&gt;&gt; # continuing from the previous snippet<br>&gt;&gt;&gt; logger.parent<br>&gt;&gt;&gt; # returns nothing(None)<br>&gt;&gt;&gt; # new let&#39;s create a new logger<br>&gt;&gt;&gt; new_logger = logging.getLogger(&quot;new_logger&quot;)<br>&gt;&gt;&gt; new_logger.parent.name<br>root</pre><p>we can create other loggers that are children of new_logger . Child or descendant loggers can be created by chaining the names with a dot. Like this:</p><pre>&gt;&gt;&gt; # continuing from the previous snippet<br>&gt;&gt;&gt; another_logger = logging.getLogger(&quot;new_logger.another&quot;)<br>&gt;&gt;&gt; another_logger.name<br>&#39;new_logger.another&#39;<br>&gt;&gt;&gt; another_logger.parent.name<br>&#39;new_logger&#39;</pre><p>We’ll uncover the importance of the parent-child design in later section. So far we have played with logging in the python REPL, lets now see how to use logging in a python file or module. A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows:</p><pre>import logging<br><br>logger = logging.getLogger(__name__)</pre><p>This means that logger names track the package/module hierarchy, and it’s intuitively obvious where events are logged just from the logger name. Now to <strong>handlers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*u9YRAx1S08z0vq-qgSgi4g.png" /></figure><p>A<strong> Handler </strong>sends the log records (created by loggers) to the appropriate destination. The <a href="https://docs.python.org/3/library/logging.handlers.html#:~:text=the%20other%20handlers.-,StreamHandler%C2%B6,-The%20StreamHandler%20class">StreamHandler</a> is one of the handlers and it sends logs to the console(<em>ie output streams</em>). Another one is the <a href="https://docs.python.org/3/library/logging.handlers.html#filehandler:~:text=in%20version%203.2.-,FileHandler,-%C2%B6">FileHandler</a> that writes your logs to a specified file. There are more handlers and you can read about them <a href="https://docs.python.org/3/library/logging.handlers.html#smtphandler">here</a>. Lets see how this works.</p><pre>import logging<br>from logging import StreamHandler, FileHandler<br>logger = logging.getLogger(__name__)<br><br>logger.setLevel(&quot;DEBUG&quot;)<br><br># add a StreamHandler<br>logger.addHandler(StreamHandler())<br><br># add a FileHandler<br>logger.addHandler(FileHandler(&quot;try_log&quot;))<br><br>logger.debug(&quot;something just happened&quot;)</pre><p>If you copy the contents of the snippet above and put it in a file and run it, you’ll notice 2 things.</p><ol><li>something just happened in your console and</li><li>A new file try_log created.</li></ol><p>We noticed that a logger can be configured to have multiple handlers. The handlers can be configured to log different log levels. This is done using <strong>Filters.</strong></p><p>In the next part of this series, we will talk about how to create filters and use them with loggers. Leave a comment if you found this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3b0a1d0457d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-unleashed/logging-in-django-part-i-e3b0a1d0457d">Logging in Django — Part I</a> was originally published in <a href="https://medium.com/django-unleashed">Django Unleashed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django’s ALLOWED_HOSTS in AWS ECS]]></title>
            <link>https://medium.com/django-unleashed/djangos-allowed-hosts-in-aws-ecs-369959f2c2ab?source=rss-7a335caa8576------2</link>
            <guid isPermaLink="false">https://medium.com/p/369959f2c2ab</guid>
            <category><![CDATA[ecs-health-checks]]></category>
            <category><![CDATA[alb-health-checks-django]]></category>
            <dc:creator><![CDATA[Joseph Sarpong]]></dc:creator>
            <pubDate>Thu, 23 Nov 2023 12:14:33 GMT</pubDate>
            <atom:updated>2023-12-05T10:29:49.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*d1dLYXy8ebxdFxx4QjnZdA.png" /><figcaption>source: <a href="https://qph.cf2.quoracdn.net/main-qimg-984567699538c7abdadabdebcec76c92">https://qph.cf2.quoracdn.net/main-qimg-984567699538c7abdadabdebcec76c92</a></figcaption></figure><p>When hosting your Django app on AWS ECS, the load balancer configured to route requests to your container(target) performs health checks on the container to confirm that the container is good to receive requests. It does this by sending requests to it . The request path and healthy target metric are specified during configuration of the target group. For example, I could say my container is healthy if a request to it on the /admin path returns 301 status for 3 consecutive times.</p><p>Health checks will fail with a status 400 because the Host header of the request during health check is set to the containers private IP address. This IP address needs to be added to the <strong>ALLOWED_HOSTS </strong>list in Django’s setting.</p><p>The ALLOWED_HOSTS setting in django specifies hosts or domain names that the Django site can serve. Django will a throw 400: bad request error if the value of the Host header of a request is not in the ALLOWED_HOSTS list. So it must be set to include the domain that your website or api is hosted at.</p><p>The ALLOWED_HOSTS setting is a security measure to prevent HTTP Host header attacks(read more about it <a href="https://portswigger.net/web-security/host-header">here</a>), which are possible even under many seemingly-safe web server configurations.</p><p>Setting ALLOWED_HOSTS to a value of &#39;*&#39; will match anything; in this case you are responsible to provide your own validation of the Host header. So this is outrightly discouraged.</p><p>So how do you include the IP address of your container in your ALLOWED_HOSTS setting if you cannot know the IP address ahead of time? Here’s how:</p><p>Python’s socket module gives us the ability to do this.</p><pre>&gt;&gt;&gt; from socket import gethostbyname, gethostname<br>&gt;&gt;&gt; gethostbyname(gethostname())<br>&#39;172.17.0.2&#39;</pre><p>This works because docker containers at startup will update the <em>hosts</em> file with the <em>container_id</em> (which is it’s hostname) and the private IP address of the container.</p><p>So there it is, no need to set ALLOWED_HOSTS to &#39;*&#39; to pass application load balancer health checks. Simple extend the list to include the container ip address.</p><pre>from socket import gethostbyname<br>from socket import gethostname<br><br># assuming ALLOWED_HOSTS is set in your environment as so:<br># ALLOWED_HOSTS=&#39;domain.com,anotherdomain.com&#39;<br><br>ALLOWED_HOSTS = os.environ.get(&quot;ALLOWED_HOST&quot;).split(&quot;,&quot;) #or however you set it.<br>ALLOWED_HOSTS.append(gethostbyname(gethostname()))</pre><p><em>hope this is useful to you. let’s get talking — leave a comment.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=369959f2c2ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-unleashed/djangos-allowed-hosts-in-aws-ecs-369959f2c2ab">Django’s ALLOWED_HOSTS in AWS ECS</a> was originally published in <a href="https://medium.com/django-unleashed">Django Unleashed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>