Skip to content

Commit

Permalink
Configure 'logging' to generate log files on Windows/Linux/Mac and sy…
Browse files Browse the repository at this point in the history
…slog where available / Configure 'logging' to do async buffered logging via a thread to avoid impacting app performance with logging
  • Loading branch information
AndyObtiva committed Jul 22, 2020
1 parent b316c09 commit a5db7a2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ pkg
.gladiator

tmp
log
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Support scaffold commands for gems with `scaffold:gem:cw` pattern (`cs` as other suffix)
- Support listing commands with `list:gems:cw` pattern (`cs` as other suffix)
- 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

### 0.4.1

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

### 0.5.0

- 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
- Upgrade to glimmer 0.10.0 to take advantage of the new logging library

Expand Down
43 changes: 42 additions & 1 deletion lib/ext/glimmer/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,50 @@ def import_swt_packages
@@import_swt_packages
end

# Returns Logging Devices. Default is [:stdout, :syslog]
def logging_devices
unless defined? @@logging_devices
@@logging_devices = [:stdout, :syslog]
end
@@logging_devices
end

# Logging Devices is an array of these possible values: :stdout (default), :stderr, :file, :syslog (default), :stringio
def logging_devices=(devices)
@@logging_devices = devices
reset_logger!
end

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

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

def logging_appender_options
@@logging_appender_options = {async: true, auto_flushing: 25, write_size: 5, immediate_at: [:error, :fatal]} unless defined? @@logging_appender_options
@@logging_appender_options
end

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

def reset_logger!
self.logger = Logging.logger(STDOUT).tap do |logger|
self.logger = Logging.logger['glimmer'].tap do |logger|
logger.level = Logger::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)
appenders << Logging.appenders.rolling_file('log/glimmer.log', logging_appender_options.merge(logging_device_file_options)) if logging_devices.include?(:file)
Syslog.close if Syslog.opened? if logging_devices.include?(:syslog)
appenders << Logging.appenders.syslog('glimmer', logging_appender_options) if logging_devices.include?(:syslog)
logger.appenders = appenders
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ module GlimmerSpec
expect(widget.getStyle & style_value).to eq(style_value)
end
end

# Enable when testing logging manually
# Glimmer::Config.logging_devices = [:stdout, :file, :syslog]
# Glimmer::Config.logger.level = :debug

0 comments on commit a5db7a2

Please sign in to comment.