-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add middleware option for slicer module and a UTF-8 aware slicer #23
Add middleware option for slicer module and a UTF-8 aware slicer #23
Conversation
@@ -1,46 +1,9 @@ | |||
defmodule MetaLogger.Slicer do | |||
@moduledoc """ | |||
Responsible for slicing log entries according to the given max length option. | |||
A bebaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add a behaviour to establish a contract for other custom slicing implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bebaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. | |
A behaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. |
Co-authored-by: Felipe Vieira <[email protected]>
Co-authored-by: Felipe Vieira <[email protected]>
@@ -1,46 +1,9 @@ | |||
defmodule MetaLogger.Slicer do | |||
@moduledoc """ | |||
Responsible for slicing log entries according to the given max length option. | |||
A bebaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bebaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. | |
A behaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. |
|
||
""" | ||
@impl MetaLogger.Slicer | ||
@spec slice(binary(), MetaLogger.Slicer.max_entry_length()) :: [binary()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This spec is not necessary because the specification in the callback.
when byte_size(entry) <= max_entry_length, | ||
do: [entry] | ||
|
||
def slice(entry, max_entry_length) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to add a guard to ensure entry
is binary.
def slice(entry, max_entry_length) do | ||
do_slice(entry, max_entry_length, [], [], 0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defp bank_partial_slice(slices, partial_slice) do | ||
[reconstruct_current_slice_as_binary(partial_slice) | slices] | ||
end | ||
|
||
@spec reconstruct_current_slice_as_binary([iodata()]) :: binary() | ||
defp reconstruct_current_slice_as_binary(current_slice) do | ||
IO.iodata_to_binary(Enum.reverse(current_slice)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test "when max entry length is smaller than the size of given entry, " <> | ||
"returns a list with one entry", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request introduces a new slicing behavior for log entries, adds UTF-8 support, and updates the middleware to allow the use custom slicers through a configuration option. The most important changes include defining new slicing modules, updating the middleware to accept a custom slicer, and adding corresponding tests.
Slicing Behavior Enhancements:
lib/meta_logger/slicer.ex
: Added a behavior definition for slicing log entries and implemented a default slicer module (DefaultImpl
).lib/meta_logger/utf8_slicer.ex
: Introduced a new module (Utf8Impl
) to slice log entries while ensuring valid UTF-8 strings.Middleware Updates:
lib/tesla/middleware/meta_logger.ex
: Updated the middleware to accept a custom slicer module and use it for slicing log entries.Testing Enhancements:
test/meta_logger/slicer_test.exs
: Updated tests to use the default slicer implementation and added tests for UTF-8 slicing.test/meta_logger/utf8_slicer_test.exs
: Added new tests for the UTF-8 slicer implementation.test/tesla/middleware/meta_logger_test.exs
: Added a test module for alternative slicers and tests to verify custom slicer usage in middleware.Highlights
🧵 #23 (comment)
🧵 #23 (comment)