this repo has no description

fix: wording and add thanks to Kai

Changed files
+59 -16
content
templates
+19 -13
content/post/log-all-the-things.md
···
"programming",
"observability"
]
+
+
[[extra.thanks]]
+
name = "Kai Wern Choong"
+++
In Elixir 1.11 landed set of new features that allows for more powerful logging
-
by utilising Erlang's [`logger`][erl-log] features. Here I will try to descibe
+
by utilising Erlang's [`logger`][erl-log] features. Here I will try to describe
new possibilities and how You can use them to improve your logs.
<!-- more -->
···
# Nothing got logged as top-level verbositi is still set to `:error`
```
-
Of course it will not work if you decide to use [compile time purging](https://hexdocs.pm/logger/Logger.html#module-application-configuration).
+
Of course it will not work if you decide to use [compile time purging][logger-purge]
## Logger handlers {#handlers}
···
hierarchy which then can be used for filtering. All events fired using
`Logger` macros and functions will have `:elixir` prepended to their
domain list.
-
- `:report_cb` - function that will be used to format `{:report, map() | keyword()}`
-
messages. This can be either 1-ary function, that takes report and returns
-
`{:io.format(), [term()]}` leaving truncation and further formatting up to
-
the main formatter, or 2-ary function that takes report and configuration
-
map `%{depth: pos_integer() | :unlimited, chars_limit: pos_integer() |
-
:unlimited, single_line: boolean()}` and returns already formatted
-
`:unicode.chardata()`. More about it can be found in [separate section](#structured-logging).
+
- `:report_cb` - function that will be used to format `{:report, map() |
+
keyword()}` messages. This can be either 1-ary function, that takes report
+
and returns `{:io.format(), [term()]}` leaving truncation and further
+
formatting up to the main formatter, or 2-ary function that takes report
+
and configuration map `%{depth: pos_integer() | :unlimited, chars_limit:
+
pos_integer() | :unlimited, single_line: boolean()}` and returns already
+
formatted `:unicode.chardata()`. More about it can be found in [separate
+
section](#structured-logging).
Return value of this function is ignored. If there will be any exception raised
when calling this function, then it will be captured and failing handler will be
···
can cause quite substantial load on application.
To read on other, optional, callbacks that can be defined by Erlang handler, that
-
will not be covered there, I suggest looking into [Erlang documentation](https://erlang.org/doc/man/logger.html#formatter-callback-functions).
+
will not be covered there, I suggest looking into [Erlang documentation][formatter_cb].
## Structured logging {#structured-logging}
···
The rule of thumb you can follow is:
-
> If it is thing that you will want to filter on, then it propably should be
+
> If it is thing that you will want to filter on, then it probably should be
> part of the metadata. If you want to aggregate information or just display
> them, it should be part of the message report.
···
approach you could abuse translators, but that was error prone, as first
successful translator was breaking pipeline, so you couldn't just smash one on
top and then keep rest working as is. With "new" approach and structured logging
-
you can just traverse the report and replace all occurences of the unsafe data
+
you can just traverse the report and replace all occurrences of the unsafe data
with anonymised data. For example:
```elixir
···
defp replace(other), do: other
```
-
This snippet will replace all occurences of `:password` or `"password"` with
+
This snippet will replace all occurrences of `:password` or `"password"` with
filtered out value.
The disadvantage of such approach - it will make all messages with such fields
···
[`LoggerJSON`]: https://github.com/Nebo15/logger_json
[`Ink`]: https://hex.pm/packages/ink
[logger_filters]: https://erlang.org/doc/man/logger_filters.html
+
[logger-purge]: https://hexdocs.pm/logger/Logger.html#module-application-configuration
+
[formatter_cb]: https://erlang.org/doc/man/logger.html#formatter-callback-functions
+4
templates/index.html
···
</nav>
</header>
{% endblock %}
+
+
{#
+
vi: ft=jinja
+
#}
+4
templates/macros/posts.html
···
#<a class="p-category" href="{{get_taxonomy_url(kind="tags", name=tag )}}">{{ tag }}</a>
{% endfor -%}
{% endmacro tags %}
+
+
{#
+
vi: ft=jinja
+
#}
+4
templates/macros/toc.html
···
{%- endfor -%}
</ol>
{% endmacro toc %}
+
+
{#
+
vi: ft=jinja
+
#}
+28 -3
templates/page.html
···
{%- import "macros/toc.html" as toc -%}
{%- block title -%}
-
<title>{{ page.title }} - {{ config.extra.author }}</title>
+
<title>{{ page.title }} - {{ config.extra.author }}</title>
{%- endblock title -%}
{%- block main -%}
···
<div class="post-content e-content">
{{ page.content | safe }}
</div>
-
{% if not page.extra.no_comments %}
+
{%- if page.extra.thanks -%}
+
<hr />
+
<p>
+
<b>Special thanks</b>:
+
<ul>
+
{%- for person in page.extra.thanks -%}
+
<li class="h-card">
+
{%- if person is object -%}
+
{%- if person.url -%}
+
<a class="u-url p-name" href="{{ person.url }}">{{ person.name }}</a>
+
{%- else -%}
+
<span class="p-name">{{ person.name }}</span>
+
{%- endif -%}
+
{%- else -%}
+
<span class="p-name">{{ person }}</span>
+
{%- endif -%}
+
</li>
+
{%- endfor -%}
+
</ul>
+
</p>
+
{%- endif -%}
+
{%- if not page.extra.no_comments -%}
<hr />
<div>
<p>You can provide feedback via mailing list
···
page.title }}">~hauleth/blog@lists.sr.ht</a>
(<a href="https://lists.sr.ht/~hauleth/blog">archive</a>).</p>
</div>
-
{% endif %}
+
{%- endif -%}
</article>
{%- endblock main -%}
+
+
{#
+
vi: ft=jinja
+
#}