Skip to content

Commit

Permalink
Update all logger calls to be lazy blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Jul 23, 2020
1 parent a5db7a2 commit 8f42bb9
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add -BinstalldirChooser=true / -Bcopyright=string / -Bvendor=string / -Bwin.menuGroup=string to Package class to support Windows packaging
- Configure 'logging' to generate log files on Windows/Linux/Mac and syslog where available
- Configure 'logging' to do async buffered logging via a thread to avoid impacting app performance with logging
- Update all logger calls to be lazy blocks

### 0.4.1

Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Here is a list of tasks to do (moved to [CHANGELOG.md](CHANGELOG.md) once done).

### 0.5.0

- Update all logger calls to be lazy blocks
- Consider making "DSL keyword cannot be handled" errors at level :warn
- Lower logging level for unimportant debug info
- Upgrade to glimmer 0.10.0 to take advantage of the new logging library

### 0.6.0
Expand Down
1 change: 1 addition & 0 deletions lib/glimmer/dsl/swt/custom_widget_expression.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/dsl/swt/tab_item_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def can_interpret?(parent, keyword, *args, &block)
if parent.swt_widget.is_a?(TabFolder)
return true
else
Glimmer::Config.logger&.error "tab_item widget may only be used directly under a tab_folder widget!"
Glimmer::Config.logger.error {"tab_item widget may only be used directly under a tab_folder widget!"}
end
end
false
Expand Down
10 changes: 5 additions & 5 deletions lib/glimmer/dsl/swt/widget_listener_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ class WidgetListenerExpression < Expression
include_package 'org.eclipse.swt.widgets'

def can_interpret?(parent, keyword, *args, &block)
Glimmer::Config.logger&.debug "keyword starts with on_: #{keyword.start_with?('on_')}"
Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
return false unless keyword.start_with?('on_')
widget_or_display_parentage = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy)
Glimmer::Config.logger&.debug "parent is a widget or display: #{widget_or_display_parentage}"
Glimmer::Config.logger.debug {"parent is a widget or display: #{widget_or_display_parentage}"}
return false unless widget_or_display_parentage
Glimmer::Config.logger&.debug "block exists?: #{!block.nil?}"
Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
Glimmer::Config.logger&.debug "args are empty?: #{args.empty?}"
Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
result = parent.can_handle_observation_request?(keyword)
Glimmer::Config.logger&.debug "can add listener? #{result}"
Glimmer::Config.logger.debug {"can add listener? #{result}"}
raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/swt/color_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def swt_color
def method_missing(method, *args, &block)
swt_color.send(method, *args, &block)
rescue => e
Glimmer::Config.logger&.debug "Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"
Glimmer::Config.logger.debug {"Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"}
super
end

Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/swt/display_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(*args)
def method_missing(method, *args, &block)
swt_display.send(method, *args, &block)
rescue => e
Glimmer::Config.logger&.debug "Neither DisplayProxy nor #{swt_display.class.name} can handle the method ##{method}"
Glimmer::Config.logger.debug {"Neither DisplayProxy nor #{swt_display.class.name} can handle the method ##{method}"}
super
end

Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/swt/layout_data_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(widget_proxy, args)
begin
@swt_layout_data = swt_layout_data_class.new(*args)
rescue => e
Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
@swt_layout_data = args.first if args.count == 1
end
@widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
Expand Down
4 changes: 2 additions & 2 deletions lib/glimmer/swt/layout_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def swt_layout_class_for(underscored_layout_name)
end
swt_layout_class
rescue => e
Glimmer::Config.logger&.debug e.message
# Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
Glimmer::Config.logger.debug {e.message}
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
raise e
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/swt/shell_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def start_event_loop
begin
@display.sleep unless @display.readAndDispatch
rescue => e
Glimmer::Config.logger&.debug e.full_message
Glimmer::Config.logger.debug {e.full_message}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/glimmer/swt/style_constantizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def constant(symbol)
negative ? ~bit_value : bit_value
rescue => e
begin
# Glimmer::Config.logger&.debug(e.full_message)
# Glimmer::Config.logger.debug {e.full_message}
alternative_swt_constant_symbol = constant_source_class.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
bit_value = constant_source_class.const_get(alternative_swt_constant_symbol)
negative ? ~bit_value : bit_value
rescue => e
# Glimmer::Config.logger&.debug(e.full_message)
# Glimmer::Config.logger.debug {e.full_message}
bit_value = extra_styles[swt_constant_symbol]
if bit_value
negative ? ~bit_value : bit_value
Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/swt/table_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def edit_table_item(table_item, column_index, before_write: nil, after_write: ni
}
@table_editor.setEditor(@table_editor_widget_proxy.swt_widget, table_item, column_index)
rescue => e
Glimmer::Config.logger&.error e.full_message
Glimmer::Config.logger.error {e.full_message}
raise e
end

Expand Down
14 changes: 7 additions & 7 deletions lib/glimmer/swt/widget_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,17 @@ def self.swt_widget_class_for(underscored_widget_name)
swt_widget_name = underscored_widget_name.camelcase(:upper)
swt_widget_class = eval(swt_widget_name)
unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
Glimmer::Config.logger&.debug("Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget")
Glimmer::Config.logger.debug {"Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget"}
return nil
end
swt_widget_class
rescue SyntaxError, NameError => e
Glimmer::Config.logger&.debug e.full_message
# Glimmer::Config.logger&.debug("#{e.message}\n#{e.backtrace.join("\n")}")
Glimmer::Config.logger.debug {e.full_message}
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
nil
rescue => e
Glimmer::Config.logger&.debug e.full_message
# Glimmer::Config.logger&.debug("#{e.message}\n#{e.backtrace.join("\n")}")
Glimmer::Config.logger.debug {e.full_message}
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
nil
end

Expand Down Expand Up @@ -359,7 +359,7 @@ def can_handle_drag_observation_request?(observation_request)
end
end
rescue => e
Glimmer::Config.logger&.debug(e.full_message)
Glimmer::Config.logger.debug {e.full_message}
false
end

Expand Down Expand Up @@ -399,7 +399,7 @@ def content(&block)
def method_missing(method, *args, &block)
swt_widget.send(method, *args, &block)
rescue => e
Glimmer::Config.logger&.debug "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}"
Glimmer::Config.logger.debug {"Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
super
end

Expand Down
6 changes: 3 additions & 3 deletions lib/glimmer/ui/custom_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def for(underscored_custom_widget_name)
return constant if constant.ancestors.include?(Glimmer::UI::CustomWidget)
constant
rescue => e
# Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
result
end
end
end
raise "#{underscored_custom_widget_name} has no custom widget class!"
rescue => e
Glimmer::Config.logger&.debug e.message
Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
Glimmer::Config.logger.debug {e.message}
Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
nil
end

Expand Down

0 comments on commit 8f42bb9

Please sign in to comment.