(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[162],{9330:function(n,s,o){(window.__NEXT_P=window.__NEXT_P||[]).push(["/documentation/example_app/monitoring_and_logging",function(){return o(966)}])},966:function(n,s,o){"use strict";o.r(s),o.d(s,{__N_SSG:function(){return r}});var e=o(5893),a=o(1151);function t(n){let s=Object.assign({h2:"h2",a:"a",p:"p",pre:"pre",code:"code"},(0,a.ah)(),n.components),{Button:o}=s;return o||function(n,s){throw Error("Expected "+(s?"component":"object")+" `"+n+"` to be defined: you likely forgot to import, pass, or provide it.")}("Button",!0),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(s.h2,{id:"monitoring-and-logging",children:(0,e.jsx)(s.a,{href:"#monitoring-and-logging",children:"Monitoring and Logging"})}),"\n",(0,e.jsx)(s.p,{children:"To keep an eye on the performance of his application and troubleshoot issues, Batman decided to implement monitoring and logging. He used a third-party library to integrate logging middleware, enabling him to track requests, errors, and performance metrics."}),"\n",(0,e.jsx)(s.pre,{language:"python",code:'from robyn import Logger\n\nlogger = Logger(app)\n\n@app.before_request()\nasync def log_request(request: Request):\n    logger.info(f"Received request: %s", request)\n\n@app.after_request()\nasync def log_response(response: Response):\n    logger.info(f"Sending response: %s", response)\n',children:(0,e.jsx)(s.code,{className:"language-python",children:'<span><span style="color: var(--shiki-token-keyword)">from</span><span style="color: var(--shiki-color-text)"> robyn </span><span style="color: var(--shiki-token-keyword)">import</span><span style="color: var(--shiki-color-text)"> Logger</span></span>\n<span></span>\n<span><span style="color: var(--shiki-color-text)">logger </span><span style="color: var(--shiki-token-keyword)">=</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">Logger</span><span style="color: var(--shiki-token-punctuation)">(app)</span></span>\n<span></span>\n<span><span style="color: var(--shiki-token-function)">@app</span><span style="color: var(--shiki-token-punctuation)">.</span><span style="color: var(--shiki-token-function)">before_request</span><span style="color: var(--shiki-token-punctuation)">()</span></span>\n<span><span style="color: var(--shiki-token-keyword)">async</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">def</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">log_request</span><span style="color: var(--shiki-color-text)">(</span><span style="color: var(--shiki-token-parameter)">request</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> Request):</span></span>\n<span><span style="color: var(--shiki-color-text)">    logger</span><span style="color: var(--shiki-token-punctuation)">.</span><span style="color: var(--shiki-token-function)">info</span><span style="color: var(--shiki-token-punctuation)">(</span><span style="color: var(--shiki-token-keyword)">f</span><span style="color: var(--shiki-token-string-expression)">&quot;Received request: %s&quot;</span><span style="color: var(--shiki-token-punctuation)">, request)</span></span>\n<span></span>\n<span><span style="color: var(--shiki-token-function)">@app</span><span style="color: var(--shiki-token-punctuation)">.</span><span style="color: var(--shiki-token-function)">after_request</span><span style="color: var(--shiki-token-punctuation)">()</span></span>\n<span><span style="color: var(--shiki-token-keyword)">async</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-keyword)">def</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-function)">log_response</span><span style="color: var(--shiki-color-text)">(</span><span style="color: var(--shiki-token-parameter)">response</span><span style="color: var(--shiki-token-punctuation)">:</span><span style="color: var(--shiki-color-text)"> Response):</span></span>\n<span><span style="color: var(--shiki-color-text)">    logger</span><span style="color: var(--shiki-token-punctuation)">.</span><span style="color: var(--shiki-token-function)">info</span><span style="color: var(--shiki-token-punctuation)">(</span><span style="color: var(--shiki-token-keyword)">f</span><span style="color: var(--shiki-token-string-expression)">&quot;Sending response: %s&quot;</span><span style="color: var(--shiki-token-punctuation)">, response)</span></span>\n<span></span>'}),title:"Monitoring and Logging"}),"\n",(0,e.jsx)(s.p,{children:"With monitoring and logging in place, Batman could now easily detect issues and analyze the performance of his web application, ensuring that it was always running optimally and ready to assist him in his fight against crime."}),"\n",(0,e.jsx)("div",{className:"not-prose",children:(0,e.jsx)(o,{href:"/documentation/example_app/deployment",variant:"text",arrow:"right",children:"Deploying the application"})})]})}var r=!0;s.default=function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}=Object.assign({},(0,a.ah)(),n.components);return s?(0,e.jsx)(s,Object.assign({},n,{children:(0,e.jsx)(t,n)})):t(n)}}},function(n){n.O(0,[774,888,179],function(){return n(n.s=9330)}),_N_E=n.O()}]);