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

.logger_typeObject



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

def logger_type
  unless defined? @@logger_type
    @@logger_type = :logger
  end
  @@logger_type
end

.logger_type=(logger_type_class) ⇒ Object

allowed logger types are :logger (default) and :logging (logging gem supporting async logging) updating logger type value resets logger



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

def logger_type=(logger_type_class)
  @@logger_type = logger_type_class
  reset_logger!
end

.logging_appender_optionsObject



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

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



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

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

.logging_device_file_optionsObject



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

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



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

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]



77
78
79
80
81
82
# File 'lib/ext/glimmer/config.rb', line 77

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



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

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

.logging_layoutObject



114
115
116
117
118
119
120
121
122
# File 'lib/ext/glimmer/config.rb', line 114

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



124
125
126
127
# File 'lib/ext/glimmer/config.rb', line 124

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

.reset_logger!Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ext/glimmer/config.rb', line 130

def reset_logger!
  if logger_type == :logger
    reset_logger_without_glimmer_dsl_swt!
  else
    require 'logging'
    @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
end

.reset_logger_without_glimmer_dsl_swt!Object



129
# File 'lib/ext/glimmer/config.rb', line 129

alias reset_logger_without_glimmer_dsl_swt! reset_logger!