Skip to content

Commit

Permalink
Add a logging BreachHandler (#149)
Browse files Browse the repository at this point in the history
What:
- add a logging BreachHandler

Why:
- Sometimes you may only want to log things when a certain log level is breached. 
  And when  that level is breached, you also want all the log records upto that point

References:
1. https://tersesystems.com/blog/2019/07/28/triggering-diagnostic-logging-on-exception/
2. https://docs.python.org/3.6/library/logging.handlers.html#logging.handlers.MemoryHandler
  • Loading branch information
komuw authored Aug 24, 2019
1 parent d18dd96 commit 3e8931c
Show file tree
Hide file tree
Showing 38 changed files with 373 additions and 80 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
most recent version is listed first.


## **version:** v0.6.4
- added a logging BreachHandler: https://github.com/komuw/naz/pull/149


## **version:** v0.6.3
- added static analysis support using pytype: https://github.com/komuw/naz/pull/148

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/my_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def makelog(log_directory="/usr/src/nazLog", log_file="naz_log_file"):
log_file = makelog()


class MyLogAdapter(naz.logger.NazLoggingAdapter):
class MyLogAdapter(naz.logger._NazLoggingAdapter):
def process(self, msg, kwargs):
timestamp = self.formatTime()
if isinstance(msg, str):
Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Overview: module code &mdash; naz v0.6.3 documentation</title>
<title>Overview: module code &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.client &mdash; naz v0.6.3 documentation</title>
<title>naz.client &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/correlater.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.correlater &mdash; naz v0.6.3 documentation</title>
<title>naz.correlater &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.hooks &mdash; naz v0.6.3 documentation</title>
<title>naz.hooks &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
105 changes: 96 additions & 9 deletions docs/_modules/naz/logger.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/_modules/naz/nazcodec.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.nazcodec &mdash; naz v0.6.3 documentation</title>
<title>naz.nazcodec &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/q.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.q &mdash; naz v0.6.3 documentation</title>
<title>naz.q &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/ratelimiter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.ratelimiter &mdash; naz v0.6.3 documentation</title>
<title>naz.ratelimiter &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/sequence.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.sequence &mdash; naz v0.6.3 documentation</title>
<title>naz.sequence &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/state.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.state &mdash; naz v0.6.3 documentation</title>
<title>naz.state &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/naz/throttle.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.throttle &mdash; naz v0.6.3 documentation</title>
<title>naz.throttle &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/logger.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ logger
---------------

.. automodule:: naz.logger
:members: BaseLogger, SimpleLogger
:members: BaseLogger, SimpleLogger, BreachHandler
:show-inheritance:

2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: 'v0.6.3',
VERSION: 'v0.6.4',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
Expand Down
4 changes: 2 additions & 2 deletions docs/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Client &mdash; naz v0.6.3 documentation</title>
<title>Client &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -62,7 +62,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/correlater.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>correlater &mdash; naz v0.6.3 documentation</title>
<title>correlater &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -62,7 +62,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/example_demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Example demo of using naz &mdash; naz v0.6.3 documentation</title>
<title>Example demo of using naz &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -62,7 +62,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
14 changes: 10 additions & 4 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Index &mdash; naz v0.6.3 documentation</title>
<title>Index &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -61,7 +61,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down Expand Up @@ -192,6 +192,8 @@ <h2 id="_">_</h2>
<li><a href="correlater.html#naz.correlater.SimpleCorrelater.__init__">(naz.correlater.SimpleCorrelater method)</a>
</li>
<li><a href="hooks.html#naz.hooks.SimpleHook.__init__">(naz.hooks.SimpleHook method)</a>
</li>
<li><a href="logger.html#naz.logger.BreachHandler.__init__">(naz.logger.BreachHandler method)</a>
</li>
<li><a href="logger.html#naz.logger.SimpleLogger.__init__">(naz.logger.SimpleLogger method)</a>
</li>
Expand Down Expand Up @@ -246,6 +248,8 @@ <h2 id="B">B</h2>
<li><a href="logger.html#naz.logger.SimpleLogger.bind">(naz.logger.SimpleLogger method)</a>
</li>
</ul></li>
<li><a href="logger.html#naz.logger.BreachHandler">BreachHandler (class in naz.logger)</a>
</li>
</ul></td>
</tr></table>

Expand Down Expand Up @@ -308,20 +312,22 @@ <h2 id="D">D</h2>
<h2 id="E">E</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="logger.html#naz.logger.BreachHandler.emit">emit() (naz.logger.BreachHandler method)</a>
</li>
<li><a href="nazcodec.html#naz.nazcodec.BaseNazCodec.encode">encode() (naz.nazcodec.BaseNazCodec method)</a>

<ul>
<li><a href="nazcodec.html#naz.nazcodec.SimpleNazCodec.encode">(naz.nazcodec.SimpleNazCodec method)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="queue.html#naz.q.BaseOutboundQueue.enqueue">enqueue() (naz.q.BaseOutboundQueue method)</a>

<ul>
<li><a href="queue.html#naz.q.SimpleOutboundQueue.enqueue">(naz.q.SimpleOutboundQueue method)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="client.html#naz.client.Client.enquire_link">enquire_link() (naz.client.Client method)</a>
</li>
<li><a href="client.html#naz.client.Client.enquire_link_resp">enquire_link_resp() (naz.client.Client method)</a>
Expand Down
4 changes: 2 additions & 2 deletions docs/hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>hooks &mdash; naz v0.6.3 documentation</title>
<title>hooks &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -62,7 +62,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz - naz is an async SMPP client. &mdash; naz v0.6.3 documentation</title>
<title>naz - naz is an async SMPP client. &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -61,7 +61,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Introduction to naz &mdash; naz v0.6.3 documentation</title>
<title>Introduction to naz &mdash; naz v0.6.4 documentation</title>



Expand Down Expand Up @@ -62,7 +62,7 @@


<div class="version">
v0.6.3
v0.6.4
</div>


Expand Down
Loading

0 comments on commit 3e8931c

Please sign in to comment.