|
2 | 2 |
|
3 | 3 | A custom `Logger` formatter for handling binary data. |
4 | 4 |
|
5 | | - This formatter is designed to correctly format binary messages. It converts |
6 | | - non-printable binary data into a hexadecimal string representation and can |
7 | | - optionally add a directional indicator (`"< "` or `"> "`) when needed. |
| 5 | +This formatter is designed to correctly format binary messages. It converts |
| 6 | +non-printable binary data into a hexadecimal string representation and can |
| 7 | +optionally add a directional indicator (`"< "` or `"> "`) when needed. |
8 | 8 |
|
9 | | - ## Usage |
| 9 | +## Usage |
10 | 10 |
|
11 | | - config :logger, :console, |
12 | | - format: {LoggerBinary.Formatter, :format}, |
13 | | - metadata: [:direction] |
14 | | - |
15 | | - ## Features |
16 | | - |
17 | | - * Formats binary messages as uppercase hexadecimal strings. |
18 | | - * Prepends formatted binary messages with a directional indicator if the `:direction` |
19 | | - metadata is present. Supported values for the `:direction` metadata are `:in` and `:out`. |
20 | | - * Uses the default Logger format for all other types of messages (e.g., printable strings and charlists). |
| 11 | +```elixir |
| 12 | +def deps do |
| 13 | + [ |
| 14 | + {:logger_binary, "~> 0.1.0"} |
| 15 | + ] |
| 16 | +end |
| 17 | +``` |
21 | 18 |
|
22 | | - ## Direction Indicator |
| 19 | +```elixir |
| 20 | +config :logger, :console, |
| 21 | + format: {LoggerBinary.Formatter, :format}, |
| 22 | + metadata: [:direction] |
| 23 | +``` |
23 | 24 |
|
24 | | - You can add the `:direction` metadata to your log messages to indicate if the |
25 | | - binary data is an incoming or outgoing message: |
| 25 | +## Features |
26 | 26 |
|
27 | | - Logger.debug(<<0x01, 0x02, 0x03>>, direction: :in) |
28 | | - # Logs: "[debug] < 01 02 03" |
| 27 | +* Formats binary messages as uppercase hexadecimal strings. |
| 28 | +* Prepends formatted binary messages with a directional indicator if the `:direction` |
| 29 | + metadata is present. Supported values for the `:direction` metadata are `:in` and `:out`. |
| 30 | +* Uses the default Logger format for all other types of messages (e.g., printable strings and charlists). |
29 | 31 |
|
30 | | - Logger.debug(<<0x01, 0x02, 0x03>>, direction: :out) |
31 | | - # Logs: "[debug] > 01 02 03" |
| 32 | +## Direction Indicator |
32 | 33 |
|
33 | | - Without directional metadata, it simply logs the formatted binary: |
| 34 | +You can add the `:direction` metadata to your log messages to indicate if the |
| 35 | +binary data is an incoming or outgoing message: |
34 | 36 |
|
35 | | - Logger.debug(<<0x01, 0x02, 0x03>>) |
36 | | - # Logs: "[debug] 01 02 03" |
| 37 | +```elixir |
| 38 | +Logger.debug(<<0x01, 0x02, 0x03>>, direction: :in) |
| 39 | +# Logs: "[debug] < 01 02 03" |
37 | 40 |
|
38 | | -## Installation |
| 41 | +Logger.debug(<<0x01, 0x02, 0x03>>, direction: :out) |
| 42 | +# Logs: "[debug] > 01 02 03" |
| 43 | +``` |
39 | 44 |
|
40 | | -If [available in Hex](https://hex.pm/docs/publish), the package can be installed |
41 | | -by adding `logger_binary` to your list of dependencies in `mix.exs`: |
| 45 | +Without directional metadata, it simply logs the formatted binary: |
42 | 46 |
|
43 | 47 | ```elixir |
44 | | -def deps do |
45 | | - [ |
46 | | - {:logger_binary, "~> 0.1.0"} |
47 | | - ] |
48 | | -end |
| 48 | +Logger.debug(<<0x01, 0x02, 0x03>>) |
| 49 | +# Logs: "[debug] 01 02 03" |
49 | 50 | ``` |
50 | | - |
51 | | -Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) |
52 | | -and published on [HexDocs](https://hexdocs.pm). Once published, the docs can |
53 | | -be found at <https://hexdocs.pm/logger_binary>. |
0 commit comments