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',
  'org.eclipse.swt.printing',
]
DEFAULT_AUTO_SYNC_EXEC =
true

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



86
87
88
89
90
91
92
93
# File 'lib/ext/glimmer/config.rb', line 86

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



95
96
97
98
# File 'lib/ext/glimmer/config.rb', line 95

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

.logging_device_file_optionsObject



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

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



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

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]



63
64
65
66
67
68
# File 'lib/ext/glimmer/config.rb', line 63

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



71
72
73
74
# File 'lib/ext/glimmer/config.rb', line 71

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

.logging_layoutObject



100
101
102
103
104
105
106
107
108
# File 'lib/ext/glimmer/config.rb', line 100

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



110
111
112
113
# File 'lib/ext/glimmer/config.rb', line 110

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

.reset_logger!Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ext/glimmer/config.rb', line 115

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