Module: Glimmer::Config

Defined in:
lib/ext/glimmer/config.rb

Constant Summary collapse

DEFAULT_IMPORT_SWT_PACKAGES =
[
  'org.eclipse.swt',
  'org.eclipse.swt.widgets',
  'org.eclipse.swt.layout',
  'org.eclipse.swt.graphics',
  'org.eclipse.swt.browser',
  'org.eclipse.swt.custom',
  'org.eclipse.swt.dnd',
]
DEFAULT_AUTO_SYNC_EXEC =
false
GUI_THREAD =
Thread.current

Class Method Summary collapse

Class Method Details

.auto_sync_execObject Also known as: auto_sync_exec?

Returns whether Glimmer will import SWT packages into including class



56
57
58
59
# File 'lib/ext/glimmer/config.rb', line 56

def auto_sync_exec
  @@auto_sync_exec = DEFAULT_AUTO_SYNC_EXEC if !defined?(@@auto_sync_exec)
  @@auto_sync_exec
end

.auto_sync_exec=(value) ⇒ Object

Tells Glimmer to avoid automatic use of sync_exec when invoking GUI calls from another thread (default: true)



51
52
53
# File 'lib/ext/glimmer/config.rb', line 51

def auto_sync_exec=(value)
  @@auto_sync_exec = value
end

.import_swt_packagesObject

Returns whether Glimmer will import SWT packages into including class



45
46
47
48
# File 'lib/ext/glimmer/config.rb', line 45

def import_swt_packages
  @@import_swt_packages = DEFAULT_IMPORT_SWT_PACKAGES if !defined?(@@import_swt_packages) || (defined?(@@import_swt_packages) && @@import_swt_packages == true)
  @@import_swt_packages
end

.import_swt_packages=(value) ⇒ Object

Tells Glimmer to import SWT packages into including class (default: true)



40
41
42
# File 'lib/ext/glimmer/config.rb', line 40

def import_swt_packages=(value)
  @@import_swt_packages = value
end

.logging_appender_optionsObject



90
91
92
93
94
95
96
97
# File 'lib/ext/glimmer/config.rb', line 90

def logging_appender_options
  @@logging_appender_options = {async: true, auto_flushing: 500, write_size: 500, flush_period: 60, immediate_at: [:error, :fatal], layout: logging_layout} unless defined? @@logging_appender_options
  # TODO make this a glimmer command option
  if ENV['GLIMMER_LOGGER_ASYNC'].to_s.downcase == 'false'
    @@logging_appender_options.merge!(async: false, auto_flushing: 1, immediate_at: [:debug, :info, :warn, :error, :fatal])
  end
  @@logging_appender_options
end

.logging_appender_options=(custom_options) ⇒ Object



99
100
101
102
# File 'lib/ext/glimmer/config.rb', line 99

def logging_appender_options=(custom_options)
  @@logging_appender_options = custom_options
  reset_logger!
end

.logging_device_file_optionsObject



80
81
82
83
# File 'lib/ext/glimmer/config.rb', line 80

def logging_device_file_options
  @@logging_device_file_options = {size: 1_000_000, age: 'daily', roll_by: 'number'} unless defined? @@logging_device_file_options
  @@logging_device_file_options
end

.logging_device_file_options=(custom_options) ⇒ Object



85
86
87
88
# File 'lib/ext/glimmer/config.rb', line 85

def logging_device_file_options=(custom_options)
  @@logging_device_file_options = custom_options
  reset_logger!
end

.logging_devicesObject

Returns Logging Devices. Default is [:stdout, :syslog]



67
68
69
70
71
72
# File 'lib/ext/glimmer/config.rb', line 67

def logging_devices
  unless defined? @@logging_devices
    @@logging_devices = [:stdout, :syslog]
  end
  @@logging_devices
end

.logging_devices=(devices) ⇒ Object

Logging Devices is an array of these possible values: :stdout (default), :stderr, :file, :syslog (default), :stringio



75
76
77
78
# File 'lib/ext/glimmer/config.rb', line 75

def logging_devices=(devices)
  @@logging_devices = devices
  reset_logger!
end

.logging_layoutObject



104
105
106
107
108
109
110
111
112
# File 'lib/ext/glimmer/config.rb', line 104

def logging_layout
  unless defined? @@logging_layout
    @@logging_layout = Logging.layouts.pattern(
      pattern: '[%d] %-5l %c: %m\n',
      date_pattern: '%Y-%m-%d %H:%M:%S'
    )
  end
  @@logging_layout
end

.logging_layout=(custom_layout) ⇒ Object



114
115
116
117
# File 'lib/ext/glimmer/config.rb', line 114

def logging_layout=(custom_layout)
  @@logging_layout = custom_layout
  reset_logger!
end

.require_sync_exec?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/ext/glimmer/config.rb', line 62

def require_sync_exec?
  Thread.current != GUI_THREAD
end

.reset_logger!Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ext/glimmer/config.rb', line 119

def reset_logger!
  @first_time = !defined?(@@logger)
  old_level = logger.level unless @first_time
  self.logger = Logging.logger['glimmer'].tap do |logger|
    logger.level = old_level || :error
    appenders = []
    appenders << Logging.appenders.stdout(logging_appender_options) if logging_devices.include?(:stdout)
    appenders << Logging.appenders.stderr(logging_appender_options) if logging_devices.include?(:stderr)
    if logging_devices.include?(:file)
      require 'fileutils'
      FileUtils.mkdir_p('log')
      appenders << Logging.appenders.rolling_file('log/glimmer.log', logging_appender_options.merge(logging_device_file_options)) if logging_devices.include?(:file)
    end
    if Object.const_defined?(:Syslog) && logging_devices.include?(:syslog)
      Syslog.close if Syslog.opened?
      appenders << Logging.appenders.syslog('glimmer', logging_appender_options)
    end
    logger.appenders = appenders
  end
  
end