# plan the week

    

index 81349c5..a54301c 100644
@@ -14,8 +14,6 @@ You don't need telegram to read the channel using the link above. If neither of

## To schedule

-1. ./exc-info.md
-1. ./log-extra.md
1. ./dedent.md
1. ./immutable.md
1. ./sqlite3.md
@@ -36,9 +34,8 @@ These are ideas for future posts. Let me know if you want to write a guest post
+ String.Template
+ String module consts
+ Urllib
-+ https://bugs.python.org/issue36326
+ str[0][0][0]
+ https://www.python.org/dev/peps/pep-0505/
+ __dir__
+ ModuleType
diff --git a/pythonetc/exc-info.md b/pythonetc/exc-info.md
index 7c66a29..0fecc52 100644
--- a/pythonetc/exc-info.md
+++ b/pythonetc/exc-info.md
@@ -1,25 +1,24 @@
+# logging exc_info
+
+Published: 20 April 2021, 18:00
+
When something fails, usually you want to log it. Let's have a look at a small toy example:

python
from logging import getLogger

logger = getLogger(__name__)
-channels = dict(
-  pythonetc='Python etc',
-)
+channels = {}

def update_channel(slug, name):
try:
old_name = channels[slug]
except KeyError as exc:
logger.error(repr(exc))
-    channels[slug] = name
-    return
-  if name != old_name:
-    channels[slug] = name
+  ...

-update_channel('telegram', 'Telegram News')
-# Logged: KeyError('telegram')
+update_channel('pythonetc', 'Python etc')
+# Logged: KeyError('pythonetc')


This example has a few issues:
@@ -37,12 +36,12 @@ def update_channel(slug, name):
...

-update_channel('telegram', 'Telegram News')
+update_channel('pythonetc', 'Python etc')
# Traceback (most recent call last):
-#   File "...", line 10, in update_channel
+#   File "...", line 3, in update_channel
#     old_name = channels[slug]
-# KeyError: 'telegram'
+# KeyError: 'pythonetc'


Also, the logger provides a convenient method exception which is the same as error with exc_info=True:
diff --git a/pythonetc/log-extra.md b/pythonetc/log-extra.md
index 338afe5..90bd2c2 100644
--- a/pythonetc/log-extra.md
+++ b/pythonetc/log-extra.md
@@ -1,3 +1,7 @@
+# logging extra
+
+Published: 22 April 2021, 18:00
+
Let's have a look at the following log message:

python
@@ -14,7 +18,7 @@ user_id = 13


-That's better, now we know what user it was. However, it's hard to work with such kinds of messages. For example, we want to get a notification when the same type of error messages occurred too many times in a minute. Before, it was one error message, "user not found". Now, for every user, we get a different message. Or another example, if we want to get all messages related to the same user. If we just search for "13", we will get many false positives where "13" means something else, not user_id.
+That's better, now we know what user it was. However, it's hard to work with such kinds of messages. For example, we want to get a notification when the same type of error messages occurred too many times in a minute. Before, it was one error message, "user not found". Now, for every user, we get a different message. Or another example, if we want to get all messages related to the same user. If we just search for "13", we will get many false positives where "13" means something else, not user_id.

The solution is to use [structured logging](softwareengineering.stackexchange.com/questions/312197/). The idea of structured logging is to store all additional values as separate fields instead of mixing everything in one text message. In Python, it can be achieved by passing the variables as the extra argument. Most of the logging libraries will recognize and store everything passed into extra. For example, how it looks like in [python-json-logger](https://pypi.org/project/python-json-logger/):



+So, if you use extra, stick to the third-party formatter you use or write your own.
+
+## Custom formatter
+
+NOTE: The text below wasn't published. Should it be a separate post?
+
So, to show extra when printing human-readable log messages as plain text, you have to write your own logs formatter:

python
diff --git a/pythonetc/slots-docs.md b/pythonetc/slots-docs.md
index 5367857..fd93cc7 100644
--- a/pythonetc/slots-docs.md
+++ b/pythonetc/slots-docs.md
@@ -2,7 +2,7 @@

Published: 05 November 2020, 18:00

-__slots__ [can be used to save memory](https://t.me/pythonetc/233). You can use any iterable as __slots__ value, including dict. AND Starting from Python 3.8, you can use dict to specify docstrings for slotted attributes __slots__:
+__slots__ [can be used to save memory](https://t.me/pythonetc/233). You can use any iterable as __slots__ value, including dict. And starting from Python 3.8, you can use dict to specify docstrings for slotted attributes __slots__:

python
class Channel: