Skip to content
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

Adds configurable option to set message format #204

Merged
merged 2 commits into from
Mar 5, 2017

Conversation

aergonaut
Copy link
Member

This allows the format of the messages produced by each formatter to be configured by specifying a format string in the .pronto.yml config file.

Format can be overridden on a global basis by specifying the format key at the top-level of the file, or it can be overridden on a per-formatter basis by nesting format keys under the formatter's name (as defined in Formatter::FORMATTERS constant). If a formatter does not have a specific format defined in the config file, it will fall back to the global format, and then fall back to the default format (which is just "%{msg}").

Format uses a Ruby format string and makes all of the attributes of the Message object available for interpolation. The TextFormatter additionally adds a special TextMessageDecorator to add colorized and specially formatted values for file location and level. These were in the original formatter code so I wanted to keep them.

The Null, JSON, and Checkstyle formatters are excluded from this PR because those aren't really outputting a human-readable format, but rather transforming the message into some other format for some other system to consume. So specifying a format string for these didn't make sense to me.

This allows the format of the messages produced by each formatter to be
configured by specifying a format string in the .pronto.yml config file.

Format can be overridden on a global basis by specifying the `format`
key at the top-level of the file, or it can be overridden on a
per-formatter basis by nesting `format` keys under the formatter's name
(as defined in `Formatter::FORMATTERS` constant). If a formatter does
not have a specific format defined in the config file, it will fall back
to the global format, and then fall back to the default format (which is
just `"%{msg}"`).

Format uses a Ruby format string and makes all of the attributes of
the `Message` object available for interpolation. The `TextFormatter`
additionally adds a special `TextMessageDecorator` to add colorized
and specially formatted values for file location and level. These were
in the original formatter code so I wanted to keep them.
@aergonaut
Copy link
Member Author

This is the follow-up to #150 and #159

cc @nbekirov @doomspork @mmozuras

@aergonaut
Copy link
Member Author

Looks like Travis ran into a 404 error trying to post Pronto results in the after_success hook 😳

Copy link
Member

@mmozuras mmozuras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, just a couple of comments 👍

class TextFormatter
include Colorizable
class TextFormatter < Base
class TextMessageDecorator < SimpleDelegator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm usually not a fan of classes within classes. Could you move outside to /formatter/text_message_decorator.rb or give an argument why would you want to keep it inside the TextFormatter class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I nested it just because the decorator was only going to be used in this one place so I thought keeping it close improved readability. I don't feel strongly about it though so I'll reorganize it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmozuras moved TextMessageDecorator to pronto/formatter/text_message_decorator.rb

colorize(level[0].upcase, color)
def format(messages, _, _)
messages.map do |message|
(config.message_format(self.class.name) % TextMessageDecorator.new(message).to_h).strip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split this line into multiple for readability? 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split up 💅


def to_h
original = __getobj__.to_h
original[:color_level] = format_level(__getobj__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand pros and cons: why did you decide to leave color_level and color_location off README? 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to README 😃

@mmozuras
Copy link
Member

mmozuras commented Mar 3, 2017

Looks like Travis ran into a 404 error trying to post Pronto results in the after_success hook 😳

@aergonaut will look into it 👌

@mmozuras mmozuras mentioned this pull request Mar 3, 2017
@aergonaut
Copy link
Member Author

@mmozuras I've updated the code according to your comments, please have a look!

@mmozuras mmozuras merged commit 14f857e into prontolabs:master Mar 5, 2017
@mmozuras
Copy link
Member

mmozuras commented Mar 5, 2017

@aergonaut perfect, thank you! 🙇

@aergonaut aergonaut deleted the configurable-messages branch March 5, 2017 15:28
@jeroenj
Copy link
Contributor

jeroenj commented Apr 24, 2017

@aergonaut awesome addition! 👏 👍

apiology pushed a commit to apiology/pronto that referenced this pull request Dec 27, 2019
Adds configurable option to set message format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants