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

[WIP] Do not display log message about a resource when it will not be updated #74

Closed
wants to merge 5 commits into from

Conversation

mizzy
Copy link
Member

@mizzy mizzy commented Feb 12, 2015

リソースに何も変更がなかった場合には、ログに何も表示しないようにするための修正です(まだ途中です)。

このプルリク適用前の状態で、既に httpd が running かつ enabled な状態で、action [:start, :enable] すると、次のようにログが表示されます。

 INFO : Starting Itamae...
 INFO : Recipe: /Users/mizzy/tmp/serverspec/recipe.rb
 INFO :    service[httpd]
 INFO :       action: enable
 INFO :       action: start

プルリク適用後は、以下のようになります。

 INFO : Starting Itamae...
 INFO : Recipe: /Users/mizzy/tmp/serverspec/recipe.rb

@@ -108,9 +108,23 @@ def initialize(recipe, resource_name, &block)
end

def run(specific_action = nil, options = {})
Logger.info "#{resource_type}[#{resource_name}]"
Logger.debug "#{resource_type}[#{resource_name}]"
Copy link
Member Author

Choose a reason for hiding this comment

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

log level が DEBUG の時には、対象のリソースを必ず表示します。

current_value &&
@attributes[key] &&
! current_value.nil? &&
! @attributes[key].nil? &&
current_value != @attributes[key]
Copy link
Member Author

Choose a reason for hiding this comment

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

プルリクの本題とは関係ないのですが、current_value が false で、@attributes[key] が true といった場合に、変更があるため true を返して欲しいのに、false を返してしまうため、nil かどうかでチェックを行うように修正しました。

Copy link
Member

Choose a reason for hiding this comment

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

この変更はLGTMです。nitpickですが!の後のスペースなくしてもらえると〜

Copy link
Member Author

Choose a reason for hiding this comment

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

了解です!


Logger.formatter.indent do
Logger.debug "(in set_current_attributes)"
set_current_attributes
Copy link
Member

Choose a reason for hiding this comment

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

アクションを実行した後はcurrent attributeが変わっている可能性があるので、run_actionで実行する必要があります

@mizzy
Copy link
Member Author

mizzy commented Feb 12, 2015

メモ。

口頭で話した結果、処理の流れを大きく変えるのは厳しい、かといって変えないとログの出力を抑えるのも難しい、なので出力は抑えずに、色を変えたり、info で出しているものを debug にする、といった方向で行くことに。Chef のログが割と見やすいので参考にする。

@mizzy
Copy link
Member Author

mizzy commented Feb 12, 2015

クローズします。レビューとアドバイスありがとうございました!

@mizzy mizzy closed this Feb 12, 2015
@mizzy mizzy deleted the less-log-message branch February 12, 2015 07:24
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.

2 participants