Skip to content

Commit

Permalink
deploy: f02d6de
Browse files Browse the repository at this point in the history
  • Loading branch information
VachaShah committed Nov 12, 2023
1 parent ac5b402 commit a064938
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions _modules/opensearchpy/connection/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ <h1>Source code for opensearchpy.connection.base</h1><div class="highlight"><pre
<span class="c1"># non-json data or a bulk request</span>
<span class="k">return</span> <span class="n">data</span> <span class="c1"># type: ignore</span>

<span class="k">def</span> <span class="nf">_log_request_response</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">]],</span> <span class="n">response</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">logger</span><span class="o">.</span><span class="n">isEnabledFor</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">):</span>
<span class="k">if</span> <span class="n">body</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
<span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">,</span> <span class="s2">&quot;ignore&quot;</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&gt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">body</span><span class="p">)</span>
<span class="k">if</span> <span class="n">response</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&lt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_log_trace</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">method</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
Expand Down Expand Up @@ -328,17 +338,11 @@ <h1>Source code for opensearchpy.connection.base</h1><div class="highlight"><pre
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Log a successful API call.&quot;&quot;&quot;</span>
<span class="c1"># TODO: optionally pass in params instead of full_url and do urlencode only when needed</span>

<span class="c1"># body has already been serialized to utf-8, deserialize it for logging</span>
<span class="c1"># TODO: find a better way to avoid (de)encoding the body back and forth</span>
<span class="k">if</span> <span class="n">body</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
<span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">,</span> <span class="s2">&quot;ignore&quot;</span><span class="p">)</span>

<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
<span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> [status:</span><span class="si">%s</span><span class="s2"> request:</span><span class="si">%.3f</span><span class="s2">s]&quot;</span><span class="p">,</span> <span class="n">method</span><span class="p">,</span> <span class="n">full_url</span><span class="p">,</span> <span class="n">status_code</span><span class="p">,</span> <span class="n">duration</span>
<span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&gt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">body</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&lt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_log_request_response</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log_trace</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span></div>

<div class="viewcode-block" id="Connection.log_request_fail"><a class="viewcode-back" href="../../../api-ref/connection.html#opensearchpy.Connection.log_request_fail">[docs]</a> <span class="k">def</span> <span class="nf">log_request_fail</span><span class="p">(</span>
Expand All @@ -365,17 +369,8 @@ <h1>Source code for opensearchpy.connection.base</h1><div class="highlight"><pre
<span class="n">exc_info</span><span class="o">=</span><span class="n">exception</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span>

<span class="c1"># body has already been serialized to utf-8, deserialize it for logging</span>
<span class="c1"># TODO: find a better way to avoid (de)encoding the body back and forth</span>
<span class="k">if</span> <span class="n">body</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
<span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">,</span> <span class="s2">&quot;ignore&quot;</span><span class="p">)</span>

<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&gt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">body</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_log_trace</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span>

<span class="k">if</span> <span class="n">response</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;&lt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span></div>
<span class="bp">self</span><span class="o">.</span><span class="n">_log_request_response</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log_trace</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">duration</span><span class="p">)</span></div>

<div class="viewcode-block" id="Connection._raise_error"><a class="viewcode-back" href="../../../api-ref/connection.html#opensearchpy.Connection._raise_error">[docs]</a> <span class="k">def</span> <span class="nf">_raise_error</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
Expand Down

0 comments on commit a064938

Please sign in to comment.