{"id":6199,"date":"2023-10-25T12:19:00","date_gmt":"2023-10-25T12:19:00","guid":{"rendered":"https:\/\/middleware.io\/backend\/?p=6199"},"modified":"2023-10-25T12:19:02","modified_gmt":"2023-10-25T12:19:02","slug":"python-logging","status":"publish","type":"post","link":"https:\/\/stage-site.middleware.io\/es\/python-logging\/","title":{"rendered":"Everything a Dev Needs to Know about Python Logging"},"content":{"rendered":"\n<p>Python logging is a fundamental element in the development and maintenance of Python applications.\u00a0<\/p>\n\n\n\n<div id=\"parent-banner\">\n <div class=\"sticky-banner orange\" id=\"sticky-banner\">\n   <img decoding=\"async\" src=\"\/images\/log_cta.png\" alt=\"Logs content CTA\" \/>\n   <h4>Start logging &#038; monitoring\u00a0your Python applications in 60 seconds.<\/h4>\n   <a href=\"https:\/\/app.middleware.io\/auth\/register\/\" target=\"_blank\" rel=\"noopener\"><button class=\"bordered-orange bottom-button white arrow\">Get started free<\/button><\/a>\n <\/div>\n<\/div>\n\n\n\n<p>When building software, it&#8217;s essential to understand what&#8217;s happening under the hood, especially when things go wrong. Python&#8217;s built-in logging library equips developers with the ability to capture and preserve valuable information about their application&#8217;s behavior. <\/p>\n\n\n\n<p>This invaluable data serves as a reference point when diagnosing and addressing issues, streamlining the troubleshooting process.<\/p>\n\n\n\n<p>In this article, we delve into the multifaceted world of Python logging, exploring various use cases, best practices, and proven strategies for overcoming the challenges of performance enhancement.\u00a0<\/p>\n\n\n\n<div id=\"accordian\" class=\"table-of-content\">\n<div class=\"toc-heading accordion\" data-toggle=\"collapse\" data-target=\"#toc\">Table of Contents<\/div>\n<div id=\"toc\" class=\"collapse\" data-parent=\"#accordian\">\n<div class=\"toc-list\">&nbsp;<\/div>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-python-logging\">What is Python Logging?<\/h2>\n\n\n\n<p>Python logging is a built-in logging module specific to applications built with Python. Developers use it to capture valuable information about code execution and software behavior during runtime.&nbsp;<\/p>\n\n\n\n<p>Python logging also provides multiple ways to configure the logging system, such as using basicConfig() for simple setups and dictConfig() for more advanced configurations.<\/p>\n\n\n\n<p>The Python logging architecture consists of loggers, handlers, filters, and formatters. Let&#8217;s provide an overview of each component.<\/p>\n\n\n\n<ul><li>Loggers are where logging begins. You create instances that emit log records. Loggers invoke functions on preconfigured logger instances and objects that contain event-relevant information, including logger name, message, and function.<\/li><\/ul>\n\n\n\n<ul><li>Handlers determine where log messages go after generation by loggers. Users can configure multiple built-in handlers to send logs to various destinations, such as log files, consoles, emails, and external services. These handlers include StreamHandler, FileHandler, NullHandler, and HTTPHandler.<\/li><\/ul>\n\n\n\n<ul><li>Filters are used to decide which log records are processed by handlers. They encompass context, logger, and appender filters. Each filter must return a True or False value, and all filters must return True values before any record can be outputted by handlers.<\/li><\/ul>\n\n\n\n<ul><li>Formatters specify the layout of log records and enable users to format messages with timestamps, log levels, or any other desired information. To enable log formatting and LogRecord conversion into strings, you configure a formatter and add it to each Handler.<\/li><\/ul>\n\n\n\n<p>However, it&#8217;s important to note that logging is not the only library available for capturing information about the performance of Python applications; developers also utilize print statements.&nbsp;<\/p>\n\n\n\n<p>So, what&#8217;s the difference between the two?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-printing-vs-logging\">Printing vs. Logging<\/h2>\n\n\n\n<p>Although printing and logging are both built-in libraries, they offer distinct advantages in various contexts.<\/p>\n\n\n\n<p>Printing is easy to use when quick code testing is required. Users can employ print() statements during development to display variable values or intermediate results for debugging. However, printing does not provide timestamps for pinpointing the exact moments when errors occur.&nbsp;<\/p>\n\n\n\n<p>In contrast, logging helps users track events in a more flexible manner, providing comprehensive information, including timestamps, stack traces, and exceptions. We will take a closer look at both in the table below.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Functionalities<\/strong><\/td><td><strong>Printing<\/strong><\/td><td><strong>Logging<\/strong><\/td><\/tr><tr><td>Purpose<\/td><td>Printing provides quick information display during program execution.<\/td><td>Logging captures log messages for debugging and analysis.<\/td><\/tr><tr><td>Output<\/td><td>Printing outputs to the console only.<\/td><td>Logging offers flexible output destinations via handlers.<\/td><\/tr><tr><td>Flexibility<\/td><td>Printing provides limited control and formatting options.<\/td><td>Logging is highly flexible, offering advanced customizable functionalities, including handlers, log levels, formatters, and filters.<\/td><\/tr><tr><td>Duration<\/td><td>Printing is not designed for long-term log retention or analysis.<\/td><td>Logging is designed for long-term log retention and analysis.<\/td><\/tr><tr><td>Integration<\/td><td>Printing has limited integration with external libraries and frameworks.<\/td><td>Logging seamlessly integrates with libraries and frameworks for centralized logging.<\/td><\/tr><tr><td>Log Importance<\/td><td>Printing simply displays records sent to it, placing less emphasis on the importance or severity of messages.<\/td><td>Logging allows users to assign log levels to indicate the importance or severity of messages. <br><br>It offers several log levels, including Debug, Info, Warning, Error, and Critical, with the highest being Critical.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-logging-levels\">Python Logging Levels<\/h2>\n\n\n\n<p>Python logging levels indicate the severity of a log message, with each level representing a different degree of importance. When you log a message with a specific level, the system records all messages at that level or higher, while filtering out others.&nbsp;<\/p>\n\n\n\n<p>For example, if users log a message with the ERROR level, it will include logs from both the Error and Critical levels. Let&#8217;s explore each level:<\/p>\n\n\n\n<p><strong>Debug: <\/strong>This level is used to trace and diagnose problems in the program&#8217;s execution, providing insights into the application&#8217;s internal workings.<\/p>\n\n\n\n<p><strong>Info: <\/strong>It provides general information about the program&#8217;s regular operation, ensuring that it functions normally. This level communicates various milestones and important events within the application.<\/p>\n\n\n\n<p><strong>Warning:<\/strong> This level indicates that something unexpected has occurred and alerts that there may be a potential issue in the application (e.g., an unauthorized login).<\/p>\n\n\n\n<p><strong>Error:<\/strong> It is used to report software malfunctions that cause the application to be unable to process a request.<\/p>\n\n\n\n<p><strong>Critical: <\/strong>This level represents the most severe logging level, indicating a serious error that may lead to the application&#8217;s termination.&nbsp;<\/p>\n\n\n\n<p>The logging level is set to \u2018WARNING\u2019 by default but can be reconfigured to your desired logging level.<\/p>\n\n\n\n<p>Now, let&#8217;s look at an example:<\/p>\n\n\n\n<p>To implement logging using all of these levels, set up a basic logger. You can use \u2018DEBUG\u2019 to receive outputs for all levels.<\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n<span>python <\/span> \nimport logging\n\n<span># Create a logger object <\/span>\nlogger = logging.getLogger(__name__)\n\n<span># Set the log level <\/span>\nlogger.setLevel(logging.DEBUG)\n\n<span># Create a file handler to write logs to a file <\/span>\nfile_handler = logging.FileHandler('mylog.log')\n\n<span># Create a formatter <\/span>\nformatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')\n\n<span># Set the formatter for file handler <\/span>\nfile_handler.setFormatter(formatter)\n\n<span># Add the file handler to the logger <\/span>\nlogger.addHandler(file_handler)\n\n<span># Log messages at different levels <\/span>\nlogger.debug('Debug message')\nlogger.info('Info message')\nlogger.warning('Warning message')\nlogger.error('Error message')\nlogger.critical('Critical message')\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p>Below are log message outputs for each logging level.<\/p>\n\n\n\n<p><strong>Output for \u2018DEBUG\u2019 Level Logging:<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n2023-10-07 10:00:00,000 - <span>DEBUG <\/span>- [PYTHON APP] Initializing request...\n2023-10-07 10:00:01,234 - <span>DEBUG <\/span>- [PYTHON APP] Received user input: \"Where is Mount Everest located?\"\n2023-10-07 10:00:01,236 - <span>DEBUG <\/span>- [PYTHON APP] Generating response...\n2023-10-07 10:00:01,238 - <span>DEBUG <\/span>- [PYTHON APP] Sending response to the user: \"Mount Everest is located between Nepal and Tibet, a region of China...\"\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>Output for \u2018INFO\u2019 Level Logging:<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n2023-10-07 10:00:00,000 - <span>INFO <\/span>- [PYTHON APP] App is up and running.\n2023-10-07 10:00:05,678 - <span>INFO <\/span>- [PYTHON APP] User requested the weather forecast for New York City.\n2023-10-07 10:00:10,543 - <span>INFO <\/span>- [PYTHON APP] Successfully fetched weather data for New York City.\n2023-10-07 10:00:10,544 - <span>INFO <\/span>- [PYTHON APP] Displaying weather forecast to the user: \"Today's weather in New York City: sunny with a high of 25\u00b0C.\"\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>Output for \u2018WARNING\u2019 Level Logging:<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n2023-10-07 10:00:00,000 - <span>WARNING <\/span>- [PYTHON APP] Connection to the database is taking longer than usual.\n2023-10-07 10:00:10,987 - <span>WARNING <\/span>- [PYTHON APP] Failed to retrieve user preferences. Using default settings.\n2023-10-07 10:00:30,123 - <span>WARNING <\/span>- [PYTHON APP] Low disk space detected. Free up some space to avoid performance issues.\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>Output for \u2018ERROR\u2019 Level Logging:<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n2023-10-07 10:00:00,000 - <span>ERROR <\/span>- [PYTHON APP] An internal server error occurred. Please contact administrator.\n2023-10-07 10:00:05,432 - <span>ERROR <\/span>- [PYTHON APP] Failed to process user input: \"Where did COVID-19 start?\"\n2023-10-07 10:00:10,876 - <span>ERROR <\/span>- [PYTHON APP] Unable to establish a connection to the external API.\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>Output for \u2018CRITICAL\u2019 Level Logging:<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n2023-10-07 10:00:00,000 - <span>CRITICAL <\/span>- [PYTHON APP] System overload! Shutting down to prevent damage.\n2023-10-07 10:00:05,123 - <span>CRITICAL <\/span>- [PYTHON APP] Critical security breach detected. Taking immediate action to protect sensitive data.\n2023-10-07 10:00:10,987 - <span>CRITICAL <\/span>- [PYTHON APP] Server crashed unexpectedly. Restarting the system.\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-log-to-a-file-in-python\">How to Log to a File in Python<\/h2>\n\n\n\n<p>To log events to a file in Python, take the following steps.<\/p>\n\n\n\n<p><strong>1. Import the logging module.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python\r\nimport logging\r<\/code><\/pre>\n\n\n\n<p><strong>2. Set up the logger.<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n    python\n# Create a logger object\n<span>logger <\/span>= logging.getLogger(__name__)\n\n# Set the log level (optional)\n<span>logger.setLevel(logging.DEBUG)<\/span>\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>3. Create a file handler.<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>\n    python\n# Create a file handler to write logs to a file\n<span>file_handler <\/span>= logging.FileHandler('app.log')\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>4. Set the log message format.<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>   \n   python\n# Create a formatter for the log messages\n<span>formatter <\/span>= logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')\n\n# Set the formatter for the file handler\n<span>file_handler.setFormatter(formatter)<\/span>\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p>In this log message format, we use `logging.Formatter` with a specific format string, which includes the timestamp, log level, and the actual log message.<\/p>\n\n\n\n<p><strong>5. Add the file handler to the logger<\/strong> to ensure that log messages are formatted according to the desired format.<\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>  \n   python\n# Add the file handler to the logger\n<span>logger.addHandler(file_handler) <\/span>\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p><strong>6. Log messages.<\/strong><\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>  \n   python\n# Log messages at different levels\n<span>logger.debug <\/span> ('Debug message')\n<span>logger.info <\/span> ('Info message')\n<span>logger.warning <\/span> ('Warning message')\n<span>logger.error <\/span> ('Error message')\n<span>logger.critical <\/span> ('Critical message')\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-log-variables-and-exceptions-in-python\">How to Log Variables and Exceptions in Python?<\/h2>\n\n\n\n<p>Variables are containers for storing data values of different types (e.g., numbers, strings, lists, and objects). In Python, you do not need to declare variables beforehand. Users can perform various operations on variables, such as mathematical calculations, string concatenations, or list manipulations.<\/p>\n\n\n\n<p>Exceptions are events that occur during the execution of a program and disrupt the normal flow of events. For example, when errors\u2014such as division by zero\u2014occur, Python raises an exception to prevent the program from crashing.<\/p>\n\n\n\n<p>To log variables and exceptions in Python, set up the basic steps discussed in previous subsections.<\/p>\n\n\n\n<p>After completing the basic setup, log variables using string formatting.<\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>  \n   python\nvariable = 42\n<span>logger.debug <\/span>('The value of the variable is %s', variable)\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<p>Then, log an exception within a `try`-`except` block.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   python\r\ntry:\r\n    result = 10 \/ 0\r\nexcept Exception as e:\r\n    logger.exception('An exception occurred: %s', e)\r<\/code><\/pre>\n\n\n\n<p>After running the code, you&#8217;ll have the output below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>An exception occurred: division by zero\r\nTraceback (most recent call last):\r\n  File \"&lt;ipython-input-1-783ac74dcee8>\", line 16, in &lt;module>\r\n    result = 10 \/ 0\r\nZeroDivisionError: division by zero\r\n<\/code><\/pre>\n\n\n\n<p>The log file (`mylog.log`) will contain the following log messages.<\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code>  \n2023-10-07 00:00:00,000 - <span>DEBUG <\/span>- The value of the variable is 42\n2023-10-07 00:00:00,000 - <span>ERROR <\/span>- An exception occurred: division by zero\nTraceback (most recent call last):\n  File \"<ipython-input-1-783ac74dcee8>\", line 16, in <module>\n    result = 10 \/ 0\nZeroDivisionError: division by zero\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-use-cases-of-python-logging\">Use Cases of Python Logging<\/h2>\n\n\n\n<p>Python logging is an effective tool for developers involved in building and monitoring applications across various industries, including technology, finance, healthcare, streaming, and gaming service providers. Developers typically rely on Python logging for three key use cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-logging-with-context\">Logging with Context<\/h3>\n\n\n\n<p>Python logging is valuable in situations where specific contextual information, such as the message&#8217;s origin, timestamp, and logging levels, is essential. This information facilitates efficient debugging and troubleshooting.<\/p>\n\n\n\n<p>Using this contextual information, developers can pinpoint the thread, module, system function, and line number from which a log originated. <\/p>\n\n\n\n<p>They can also utilize timestamps to determine when an error message was recorded, when a task failed to complete, or to trace the path of an error before it led to a system crash.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-configuration-over-code\">Configuration Over Code<\/h3>\n\n\n\n<p>In complex software monitoring environments with multiple modules and threads, Python logging provides developers with the ability to adjust logging behavior on the fly.<\/p>\n\n\n\n<p>For instance, with the dictConfig() function, they can display &#8220;DEBUG&#8221; logs in the console during app development, switch to &#8220;INFO&#8221; logs during testing, and reconfigure the system to send &#8220;WARNING,&#8221; &#8220;ERROR,&#8221; and &#8220;CRITICAL&#8221; log outputs via SMTPHandler to a specified email address once the app is running or at any time during the software development life cycle (SDLC).<\/p>\n\n\n\n<div class=\"full-container-cta orange\">\n    <div class=\"d-flex\">\n        <div class=\"img\">\n            <img decoding=\"async\" src=\"\/images\/log_cta.png\" alt=\"Logs banner\"\/>\n        <\/div>\n        <div class=\"content-cta\">\n            <h3>Whatever your use case, Middleware has got you covered.<\/h3>\n            <a href=\"https:\/\/app.middleware.io\/auth\/register\/\" target=\"_blank\" rel=\"noopener\"><button class=\"primary white arrow\">Start logging<\/button><\/a>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-fine-grained-control\">Fine-Grained Control<\/h3>\n\n\n\n<p>When developers need precise control over logging and output destinations, Python logging is the ideal solution. Depending on their specific requirements, developers can use module and class functions to create loggers, handlers, and formatters.&nbsp;<\/p>\n\n\n\n<p>They can also utilize the fileConfig() function to create and read configuration files or the dictConfig() function to manage dictionary-based configuration information. <\/p>\n\n\n\n<p>LogRecords generated can then be filtered based on logging levels and displayed in the console (through StreamHandler) or any other output destination.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-benefits-of-logging\">Benefits of Logging<\/h2>\n\n\n\n<p>Logging provides several advantages in application development and monitoring, including the following.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-error-detection-and-root-cause-analysis\">Error Detection and Root Cause Analysis<\/h3>\n\n\n\n<p>Python logging allows users to capture error messages, stack traces, and other relevant information when an error occurs. These logs are invaluable for root cause analysis, aiding in the understanding of how and where an error originated.<\/p>\n\n\n\n<p>Below is an example of an error log message:<\/p>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code> \n2023-10-07 10:00:00,000 - <span>ERROR <\/span>- [PYTHON APP] An internal server error occurred. Please contact administrator.\n2023-10-07 10:00:05,432 - <span>ERROR <\/span>- [PYTHON APP] Failed to process user input: \"Where did COVID-19 start?\"\n2023-10-07 10:00:10,876 - <span>ERROR <\/span>- [PYTHON APP] Unable to establish a connection to the external API.\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-audit-and-compliance\">Audit and Compliance<\/h3>\n\n\n\n<p>Industry regulations, such as GDPR and PCI-DSS, often mandate that organizations safeguard sensitive data and establish audit trails through the maintenance of logs for specific events, including user access, system changes, and data modifications.<\/p>\n\n\n\n<p>Python logging offers a standardized mechanism for capturing and recording these events, thereby facilitating compliance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-reduced-incident-response-time\">Reduced Incident Response Time<\/h3>\n\n\n\n<p>By strategically placing log statements at critical code points, developers can trace the flow of execution and gain insights into the program&#8217;s behavior.<\/p>\n\n\n\n<p>Log messages frequently contain variable values, function call information, and other contextual details, such as time and location, which expedite the identification of the root cause of an incident. This reduces the time required to investigate and resolve issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-key-parameter-tracking-with-performance-monitoring\">Key Parameter Tracking with Performance Monitoring<\/h3>\n\n\n\n<p>By logging specific parameters like response times, database query execution times, or resource utilization, developers can gain insights into <a href=\"https:\/\/middleware.io\/blog\/what-is-application-performance-monitoring\/\">application performance<\/a>. This information is invaluable for optimizing software performance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-alerting\">Alerting<\/h3>\n\n\n\n<p>Python logging can be seamlessly integrated with an alerting system to configure custom alerts or notifications for the CRITICAL logging level. <a href=\"https:\/\/middleware.io\/platform\/alerts\/\">Middleware<\/a> serves as an example of such alerting systems, where developers can establish alerts to notify them when the number of logged errors surpasses a specific threshold.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"427\" src=\"https:\/\/middleware.io\/backend\/wp-content\/uploads\/2023\/10\/MW-Alert-1024x427.png\" alt=\"Middleware alerts\" class=\"wp-image-6213\" srcset=\"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-1024x427.png 1024w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-300x125.png 300w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-768x320.png 768w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-1536x640.png 1536w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-1200x500.png 1200w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert.png 1647w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Middleware also lets developers assign alerts to specific people or teams.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"610\" src=\"https:\/\/middleware.io\/backend\/wp-content\/uploads\/2023\/10\/MW-Alert-Config-1024x610.png\" alt=\"Middleware Alerts Confirmation\" class=\"wp-image-6202\" srcset=\"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-Config-1024x610.png 1024w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-Config-300x179.png 300w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-Config-768x457.png 768w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-Config-1200x715.png 1200w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Alert-Config.png 1254w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-logging-best-practices\">Python Logging Best Practices<\/h2>\n\n\n\n<p>Here are six <a href=\"https:\/\/middleware.io\/blog\/python-logging-best-practices\/\">Python logging best practices<\/a> that every Dev should incorporate: <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-use-appropriate-log-levels\">Use Appropriate Log Levels<\/h3>\n\n\n\n<p>Choose the right log level for each message to strike a balance between generating enough information and avoiding excessive noise. This will help you focus on important information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-log-meaningful-messages\">Log Meaningful Messages<\/h3>\n\n\n\n<p>Write descriptive and concise log messages that provide valuable information about the state of your application, making troubleshooting and understanding the code easier.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-limit-sensitive-information\">Limit Sensitive Information<\/h3>\n\n\n\n<p>Be mindful of data protection regulations. Avoid logging sensitive data or user-specific information that could compromise data privacy and security.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-implement-log-rotation\">Implement Log Rotation<\/h3>\n\n\n\n<p>Manage log file size and prevent excessive disk usage by periodically archiving or deleting older log files to make space for new logs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-continuously-improve-logging-approach\">Continuously Improve Logging Approach<\/h3>\n\n\n\n<p>Regularly review your logging approach as your project evolves. Analyze the effectiveness of your logs, review their levels and message formats, and adapt them to changing requirements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-use-a-logging-solution\">Use a Logging Solution<\/h3>\n\n\n\n<p>Consider using a log management solution to automate the logging process. Some logging solutions also provide dashboards that simplify log visibility alongside features for customizing log message displays. With an ideal <a href=\"https:\/\/middleware.io\/product\/log-monitoring\/\" target=\"_blank\" rel=\"noreferrer noopener\">logging solution<\/a>, you won&#8217;t need to run command after command to log your Python applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-logging-with-middleware\">Python Logging with Middleware<\/h2>\n\n\n\n<p>For <a href=\"https:\/\/middleware.io\/blog\/what-is-real-user-monitoring\/\">real-time monitoring<\/a> and error tracking, developers should integrate Middleware into their Python application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-why\">Why?<\/h3>\n\n\n\n<p><a href=\"https:\/\/middleware.io\/product\/log-monitoring\/\" target=\"_blank\" rel=\"noreferrer noopener\">Middleware\u2019s log monitoring system<\/a> can help them collect logs from their Python application into a single dashboard.\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how\">How?<\/h3>\n\n\n\n<p>To see how this is possible, follow the steps below:<\/p>\n\n\n\n<ol><li>Create an <a href=\"https:\/\/app.middleware.io\/auth\/register\/\">account<\/a>.<\/li><li>Install the Middleware agent on your Python application using our easy one-step installation or one-step auto instrumentation commands. For more about Middleware configuration, check our <a href=\"https:\/\/docs.middleware.io\/docs\/apm-configuration\/python\/python-apm-setup\">documentation<\/a>.<\/li><\/ol>\n\n\n\n<p>Once successfully installed, the Python APM will add severity-based logging support and data export rules so that data can be forwarded to the Middleware Agent.<\/p>\n\n\n\n<ol start=\"3\"><li>Install the Python package by running the command below in your terminal.<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code> pip install middleware-apm<\/code><\/pre>\n\n\n\n<ol start=\"4\"><li>Add the query below at the very start of your project to the import tracker.<\/li><\/ol>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code> \nfrom apmpythonpackage import apmpythonclass\ntracker=apmpythonclass()\ntracker.mw_tracer({APM-PROJECT-NAME}, {APM-SERVICE-NAME})\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<ol start=\"5\"><li>Run this command to enable the tracker.<\/li><\/ol>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code> \nhandler = tracker.mw_handler()\nlogging.getLogger().addHandler(handler)\nlogging.error(\"error log sample\")\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<ol start=\"6\"><li>To ingest custom logs, run this command based on desired log severity levels.<\/li><\/ol>\n\n\n\n<div class=\"code-block content-copy\">\n<div class=\"pre\" id=\"code-blog\"><pre><code> \nlogging.info(\u201c<info sample>\u201d)\nlogging.warn(\u201c<warn sample>\u201d)\nlogging.error(\u201c<error sample>\u201d)\n<\/code>\n<\/pre>\n<\/div>\n<a class=\"copy-btn\" id=\"first-button\"><\/a>\n<\/div>\n\n\n\n<ol start=\"7\"><li>Sign in to Middleware to start.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"870\" src=\"https:\/\/middleware.io\/backend\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-1024x870.png\" alt=\"Middleware Unified Platform\" class=\"wp-image-6201\" srcset=\"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-1024x870.png 1024w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-300x255.png 300w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-768x653.png 768w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-1536x1306.png 1536w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform-1200x1020.png 1200w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Unified-Platform.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ol start=\"8\"><li>Navigate to \u201clog\u201d to see your log information.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"870\" src=\"https:\/\/middleware.io\/backend\/wp-content\/uploads\/2023\/10\/MW-Log-1024x870.png\" alt=\"Middleware Logs\" class=\"wp-image-6200\" srcset=\"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log-1024x870.png 1024w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log-300x255.png 300w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log-768x653.png 768w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log-1536x1306.png 1536w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log-1200x1020.png 1200w, https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/MW-Log.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Welcome to a new logging experience!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-closing-thoughts\">Closing Thoughts<\/h2>\n\n\n\n<p>Developers can seamlessly debug and troubleshoot issues while ensuring compliance with industry standards by implementing effective logging practices and selecting the right logging tool.&nbsp;<\/p>\n\n\n\n<p>Python logging will remain essential for Python APM. With AI-enabled logging solutions like <a href=\"https:\/\/middleware.io\/\">Middleware<\/a> in the ring, the future looks promising and reassuring for developers<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs\">FAQs<\/h2>\n\n\n\n\n\n<p>Python logging records events, messages, and errors that occur during program execution. It provides a standardized way to gather information about an application&#8217;s behavior for ease of debugging and monitoring.<\/p>\n\n\n\n\n\n<p>The Python logging library is a built-in module in Python that offers a framework for generating log messages in applications. <\/p>\n\n\n\n<p>It provides various features such as different logging levels, log formatters, log handlers, and configuration options.<\/p>\n\n\n\n\n\n<p>While the Python logging module does not originally use log4j (as log4j is a logging library specific to Java), you can configure the Python logging module to use log4j. <\/p>\n\n\n\n<p>However, this configuration requires a significant amount of code.<\/p>\n\n\n\n\n\n<p>The speed of logging in Python depends on various factors, including the log level, log handlers used, and the configuration. However, for faster logging, it is best to use a reputable log management solution.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Explore Python logging, from basics to use cases in compliance, incident response, and performance tracking. Learn best practices and middleware integration.<\/p>\n","protected":false},"author":4,"featured_media":6216,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[487],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Everything a Dev Needs to Know about Python Logging<\/title>\n<meta name=\"description\" content=\"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Everything a Dev Needs to Know about Python Logging\" \/>\n<meta property=\"og:description\" content=\"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/stage-site.middleware.io\/es\/python-logging\/\" \/>\n<meta property=\"og:site_name\" content=\"Middleware\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-25T12:19:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-25T12:19:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/opt_Everything-a-Dev-Needs-to-Know-about-Python-Logging.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1300\" \/>\n\t<meta property=\"og:image:height\" content=\"700\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Meghraj Choudhary\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Meghraj Choudhary\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/stage-site.middleware.io\/es\/python-logging\/\",\"url\":\"https:\/\/stage-site.middleware.io\/es\/python-logging\/\",\"name\":\"Everything a Dev Needs to Know about Python Logging\",\"isPartOf\":{\"@id\":\"https:\/\/stage-site.middleware.io\/es\/#website\"},\"datePublished\":\"2023-10-25T12:19:00+00:00\",\"dateModified\":\"2023-10-25T12:19:02+00:00\",\"author\":{\"@id\":\"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/abb9b5f89051c6190d2256bc01753d93\"},\"description\":\"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:\",\"breadcrumb\":{\"@id\":\"https:\/\/stage-site.middleware.io\/es\/python-logging\/#breadcrumb\"},\"inLanguage\":\"es-ES\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/stage-site.middleware.io\/es\/python-logging\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/stage-site.middleware.io\/es\/python-logging\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/stage-site.middleware.io\/es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Conocimientos\",\"item\":\"https:\/\/stage-site.middleware.io\/es\/category\/conocimientos\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Everything a Dev Needs to Know about Python Logging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/stage-site.middleware.io\/es\/#website\",\"url\":\"https:\/\/stage-site.middleware.io\/es\/\",\"name\":\"Middleware\",\"description\":\"Observability platform\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/stage-site.middleware.io\/es\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"es-ES\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/abb9b5f89051c6190d2256bc01753d93\",\"name\":\"Meghraj Choudhary\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es-ES\",\"@id\":\"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d01414151377c6cb34d1a828ce603438?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d01414151377c6cb34d1a828ce603438?s=96&d=mm&r=g\",\"caption\":\"Meghraj Choudhary\"},\"description\":\"With over a decade of experience, Meghraj has significantly contributed to many successful projects. His expertise lies in architecting complex applications and implementing scalable solutions with a focus on performance and efficiency.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/devmraj\/\"],\"url\":\"https:\/\/stage-site.middleware.io\/es\/author\/meghraj\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Everything a Dev Needs to Know about Python Logging","description":"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"es_ES","og_type":"article","og_title":"Everything a Dev Needs to Know about Python Logging","og_description":"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:","og_url":"https:\/\/stage-site.middleware.io\/es\/python-logging\/","og_site_name":"Middleware","article_published_time":"2023-10-25T12:19:00+00:00","article_modified_time":"2023-10-25T12:19:02+00:00","og_image":[{"width":1300,"height":700,"url":"https:\/\/stage-site.middleware.io\/wp-content\/uploads\/2023\/10\/opt_Everything-a-Dev-Needs-to-Know-about-Python-Logging.jpg","type":"image\/jpeg"}],"author":"Meghraj Choudhary","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Meghraj Choudhary","Tiempo de lectura":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/stage-site.middleware.io\/es\/python-logging\/","url":"https:\/\/stage-site.middleware.io\/es\/python-logging\/","name":"Everything a Dev Needs to Know about Python Logging","isPartOf":{"@id":"https:\/\/stage-site.middleware.io\/es\/#website"},"datePublished":"2023-10-25T12:19:00+00:00","dateModified":"2023-10-25T12:19:02+00:00","author":{"@id":"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/abb9b5f89051c6190d2256bc01753d93"},"description":"Logging in Python is a fundamental element. Learn about Python logging, from basics to use cases in compliance, incident response, and performance tracking:","breadcrumb":{"@id":"https:\/\/stage-site.middleware.io\/es\/python-logging\/#breadcrumb"},"inLanguage":"es-ES","potentialAction":[{"@type":"ReadAction","target":["https:\/\/stage-site.middleware.io\/es\/python-logging\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/stage-site.middleware.io\/es\/python-logging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/stage-site.middleware.io\/es\/"},{"@type":"ListItem","position":2,"name":"Conocimientos","item":"https:\/\/stage-site.middleware.io\/es\/category\/conocimientos\/"},{"@type":"ListItem","position":3,"name":"Everything a Dev Needs to Know about Python Logging"}]},{"@type":"WebSite","@id":"https:\/\/stage-site.middleware.io\/es\/#website","url":"https:\/\/stage-site.middleware.io\/es\/","name":"Middleware","description":"Observability platform","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/stage-site.middleware.io\/es\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"es-ES"},{"@type":"Person","@id":"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/abb9b5f89051c6190d2256bc01753d93","name":"Meghraj Choudhary","image":{"@type":"ImageObject","inLanguage":"es-ES","@id":"https:\/\/stage-site.middleware.io\/es\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d01414151377c6cb34d1a828ce603438?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d01414151377c6cb34d1a828ce603438?s=96&d=mm&r=g","caption":"Meghraj Choudhary"},"description":"With over a decade of experience, Meghraj has significantly contributed to many successful projects. His expertise lies in architecting complex applications and implementing scalable solutions with a focus on performance and efficiency.","sameAs":["https:\/\/www.linkedin.com\/in\/devmraj\/"],"url":"https:\/\/stage-site.middleware.io\/es\/author\/meghraj\/"}]}},"_links":{"self":[{"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/posts\/6199"}],"collection":[{"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/comments?post=6199"}],"version-history":[{"count":18,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/posts\/6199\/revisions"}],"predecessor-version":[{"id":6311,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/posts\/6199\/revisions\/6311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/media\/6216"}],"wp:attachment":[{"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/media?parent=6199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/categories?post=6199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stage-site.middleware.io\/es\/wp-json\/wp\/v2\/tags?post=6199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}