gorgon 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -2
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Dockerfile +25 -0
- data/Gemfile.lock +20 -15
- data/README.md +33 -6
- data/Rakefile +5 -0
- data/architecture.md +2 -2
- data/bin/gorgon +2 -114
- data/daemon_with_upstart_and_rvm.md +1 -1
- data/docker-compose.yml +28 -0
- data/file_server/Dockerfile +8 -0
- data/file_server/test_gorgon.pem.pub +1 -0
- data/gorgon.gemspec +2 -2
- data/gorgon_secret.json.sample +5 -0
- data/lib/gorgon/amqp_service.rb +28 -26
- data/lib/gorgon/callback_handler.rb +28 -26
- data/lib/gorgon/colors.rb +6 -4
- data/lib/gorgon/command.rb +145 -0
- data/lib/gorgon/configuration.rb +45 -5
- data/lib/gorgon/core_ext/hash/deep_merge.rb +21 -0
- data/lib/gorgon/crash_reporter.rb +15 -13
- data/lib/gorgon/failures_printer.rb +27 -26
- data/lib/gorgon/g_logger.rb +19 -17
- data/lib/gorgon/gem_command_handler.rb +41 -39
- data/lib/gorgon/gem_service.rb +60 -57
- data/lib/gorgon/host_state.rb +23 -21
- data/lib/gorgon/job.rb +19 -17
- data/lib/gorgon/job_definition.rb +23 -21
- data/lib/gorgon/job_state.rb +93 -90
- data/lib/gorgon/listener.rb +137 -146
- data/lib/gorgon/listener_installer.rb +98 -96
- data/lib/gorgon/originator.rb +170 -167
- data/lib/gorgon/originator_logger.rb +30 -28
- data/lib/gorgon/originator_protocol.rb +85 -83
- data/lib/gorgon/ping_service.rb +44 -42
- data/lib/gorgon/pipe_forker.rb +17 -15
- data/lib/gorgon/progress_bar_view.rb +109 -107
- data/lib/gorgon/rsync_daemon.rb +56 -54
- data/lib/gorgon/runtime_file_reader.rb +28 -27
- data/lib/gorgon/runtime_recorder.rb +27 -26
- data/lib/gorgon/settings/files_content.rb +27 -25
- data/lib/gorgon/settings/initial_files_creator.rb +58 -56
- data/lib/gorgon/settings/rails_project_files_content.rb +33 -31
- data/lib/gorgon/settings/simple_project_files_content.rb +11 -9
- data/lib/gorgon/shutdown_manager.rb +20 -18
- data/lib/gorgon/source_tree_syncer.rb +108 -69
- data/lib/gorgon/version.rb +1 -1
- data/lib/gorgon/worker.rb +130 -128
- data/lib/gorgon/worker_manager.rb +139 -137
- data/lib/gorgon_amq-protocol/.rspec +3 -0
- data/run_dev_environment.sh +3 -0
- data/run_gorgon.sh +3 -0
- data/run_listener.sh +3 -0
- data/run_test.sh +3 -0
- data/spec/callback_handler_spec.rb +10 -10
- data/spec/command_spec.rb +172 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/core_ext/hash/deep_merge_spec.rb +11 -0
- data/spec/crash_reporter_spec.rb +10 -10
- data/spec/dummy/.gitignore +3 -0
- data/spec/dummy/Gemfile +11 -0
- data/spec/dummy/Gemfile.lock +76 -0
- data/spec/dummy/README.md +23 -0
- data/spec/dummy/gorgon.json +30 -0
- data/spec/dummy/gorgon_callbacks.rb +68 -0
- data/spec/dummy/gorgon_listener.json +8 -0
- data/spec/dummy/integration_spec.rb +51 -0
- data/spec/{support/mock_app/app/mailers → dummy/log}/.gitkeep +0 -0
- data/spec/dummy/rspec_runner.rb +8 -0
- data/spec/dummy/spec/1_syntax_error_spec.rb +1 -0
- data/spec/dummy/spec/exception_spec.rb +5 -0
- data/spec/dummy/spec/failing_spec.rb +11 -0
- data/spec/dummy/spec/keeping_rspec_config_spec.rb +5 -0
- data/spec/dummy/spec/spec_helper.rb +13 -0
- data/spec/dummy/spec/successful_spec.rb +9 -0
- data/spec/dummy/spec/using_shared_example_spec.rb +3 -0
- data/spec/dummy/test/.rb +15 -0
- data/spec/dummy/test/minitest/mini1_test.rb +11 -0
- data/spec/dummy/test/minitest/mini2_test.rb +25 -0
- data/spec/dummy/test/unit/1_syntax_error_test.rb +9 -0
- data/spec/dummy/test/unit/exception_test.rb +14 -0
- data/spec/dummy/test/unit/failing_test.rb +17 -0
- data/spec/dummy/test/unit/successful_test.rb +9 -0
- data/spec/dummy/test_gorgon.pem +27 -0
- data/spec/end_to_end_spec.rb +142 -0
- data/spec/failures_printer_spec.rb +20 -20
- data/spec/gem_command_handler_spec.rb +24 -24
- data/spec/gem_service_spec.rb +18 -18
- data/spec/gorgon_rspec_formatter_spec.rb +12 -12
- data/spec/host_state_spec.rb +8 -8
- data/spec/job_definition_spec.rb +3 -3
- data/spec/job_state_spec.rb +46 -46
- data/spec/listener_spec.rb +67 -73
- data/spec/mini_test_runner_spec.rb +7 -7
- data/spec/originator_logger_spec.rb +6 -6
- data/spec/originator_protocol_spec.rb +38 -38
- data/spec/originator_spec.rb +78 -69
- data/spec/ping_service_spec.rb +14 -14
- data/spec/pipe_forker_spec.rb +13 -13
- data/spec/progress_bar_view_spec.rb +32 -32
- data/spec/rspec_runner_spec.rb +12 -12
- data/spec/rsync_daemon_spec.rb +18 -16
- data/spec/runtime_file_reader_spec.rb +12 -12
- data/spec/runtime_recorder_spec.rb +19 -19
- data/spec/shutdown_manager_spec.rb +9 -9
- data/spec/source_tree_syncer_spec.rb +148 -61
- data/spec/spec_helper.rb +3 -0
- data/spec/support/end_to_end_helpers.rb +16 -0
- data/spec/support/stream_helpers.rb +23 -0
- data/spec/unknown_runner_spec.rb +1 -1
- data/spec/worker_manager_spec.rb +23 -23
- data/spec/worker_spec.rb +70 -70
- metadata +84 -113
- data/spec/acceptance_spec_helper.rb +0 -7
- data/spec/support/mock_app/.gitignore +0 -15
- data/spec/support/mock_app/Gemfile +0 -39
- data/spec/support/mock_app/Gemfile.lock +0 -135
- data/spec/support/mock_app/README.rdoc +0 -261
- data/spec/support/mock_app/Rakefile +0 -7
- data/spec/support/mock_app/app/assets/images/rails.png +0 -0
- data/spec/support/mock_app/app/assets/javascripts/application.js +0 -15
- data/spec/support/mock_app/app/assets/stylesheets/application.css +0 -13
- data/spec/support/mock_app/app/controllers/application_controller.rb +0 -3
- data/spec/support/mock_app/app/helpers/application_helper.rb +0 -2
- data/spec/support/mock_app/app/models/.gitkeep +0 -0
- data/spec/support/mock_app/app/views/layouts/application.html.erb +0 -14
- data/spec/support/mock_app/config.ru +0 -4
- data/spec/support/mock_app/config/application.rb +0 -62
- data/spec/support/mock_app/config/boot.rb +0 -6
- data/spec/support/mock_app/config/database.yml +0 -25
- data/spec/support/mock_app/config/environment.rb +0 -5
- data/spec/support/mock_app/config/environments/development.rb +0 -37
- data/spec/support/mock_app/config/environments/production.rb +0 -67
- data/spec/support/mock_app/config/environments/test.rb +0 -37
- data/spec/support/mock_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/support/mock_app/config/initializers/inflections.rb +0 -15
- data/spec/support/mock_app/config/initializers/mime_types.rb +0 -5
- data/spec/support/mock_app/config/initializers/secret_token.rb +0 -7
- data/spec/support/mock_app/config/initializers/session_store.rb +0 -8
- data/spec/support/mock_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/support/mock_app/config/locales/en.yml +0 -5
- data/spec/support/mock_app/config/routes.rb +0 -58
- data/spec/support/mock_app/db/seeds.rb +0 -7
- data/spec/support/mock_app/doc/README_FOR_APP +0 -2
- data/spec/support/mock_app/lib/assets/.gitkeep +0 -0
- data/spec/support/mock_app/lib/tasks/.gitkeep +0 -0
- data/spec/support/mock_app/log/.gitkeep +0 -0
- data/spec/support/mock_app/public/404.html +0 -26
- data/spec/support/mock_app/public/422.html +0 -26
- data/spec/support/mock_app/public/500.html +0 -25
- data/spec/support/mock_app/public/favicon.ico +0 -0
- data/spec/support/mock_app/public/index.html +0 -241
- data/spec/support/mock_app/public/robots.txt +0 -5
- data/spec/support/mock_app/script/rails +0 -6
- data/spec/support/mock_app/test/fixtures/.gitkeep +0 -0
- data/spec/support/mock_app/test/functional/.gitkeep +0 -0
- data/spec/support/mock_app/test/integration/.gitkeep +0 -0
- data/spec/support/mock_app/test/performance/browsing_test.rb +0 -12
- data/spec/support/mock_app/test/test_helper.rb +0 -13
- data/spec/support/mock_app/test/unit/.gitkeep +0 -0
- data/spec/support/mock_app/test/unit/passing_test.rb +0 -7
- data/spec/support/mock_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/support/mock_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/support/mock_app/vendor/plugins/.gitkeep +0 -0
- data/spec/support/originator_handler.rb +0 -8
@@ -1,35 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Gorgon
|
2
|
+
class CallbackHandler
|
3
|
+
def initialize(config)
|
4
|
+
@config = config || {}
|
5
|
+
load(@config[:callbacks_class_file]) if @config[:callbacks_class_file]
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def before_originate
|
9
|
+
cluster_id = Gorgon.callbacks.before_originate
|
10
|
+
return cluster_id if cluster_id.is_a?(String)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def after_sync
|
14
|
+
Gorgon.callbacks.after_sync
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def before_creating_workers
|
18
|
+
Gorgon.callbacks.before_creating_workers
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def before_start
|
22
|
+
Gorgon.callbacks.before_start
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def after_creating_workers
|
26
|
+
Gorgon.callbacks.after_creating_workers
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def after_complete
|
30
|
+
Gorgon.callbacks.after_complete
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def after_job_finishes
|
34
|
+
Gorgon.callbacks.after_job_finishes
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
data/lib/gorgon/colors.rb
CHANGED
@@ -0,0 +1,145 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'gorgon'
|
3
|
+
require 'gorgon/originator'
|
4
|
+
require 'gorgon/listener'
|
5
|
+
require 'gorgon/rsync_daemon'
|
6
|
+
require 'gorgon/worker_manager'
|
7
|
+
require 'gorgon/ping_service'
|
8
|
+
require 'gorgon/gem_service'
|
9
|
+
require 'gorgon/version'
|
10
|
+
require 'gorgon/listener_installer'
|
11
|
+
require 'gorgon/settings/initial_files_creator'
|
12
|
+
|
13
|
+
module Gorgon
|
14
|
+
class Command
|
15
|
+
WELCOME_MESSAGE = "Welcome to Gorgon #{Gorgon::VERSION}"
|
16
|
+
USAGE = <<-EOT
|
17
|
+
USAGE: gorgon <command> [<args>]
|
18
|
+
|
19
|
+
COMMANDS:
|
20
|
+
start remotely run all tests specified in gorgon.json
|
21
|
+
listen start a listener process using the settings in gorgon_listener.json
|
22
|
+
ping ping listeners and show hosts and gorgon's version they are running
|
23
|
+
init [<framework>] create initial files for current project
|
24
|
+
install_listener run gorgon listener as a daemon process
|
25
|
+
start_rsync <directory> start rsync daemon. Run this command in File Server
|
26
|
+
stop_rsync stop rsync daemon.
|
27
|
+
gem command [<options>...] execute the gem command on every listener and shutdown listener.
|
28
|
+
(e.g. 'gorgon gem install bunny --version 1.0.0')
|
29
|
+
|
30
|
+
OPTIONS:
|
31
|
+
-h, --help print this message
|
32
|
+
-v, --version print gorgon version
|
33
|
+
EOT
|
34
|
+
|
35
|
+
COMMAND_WHITELIST = %w(help version start listen start_rsync stop_rsync manage_workers ping gem init install_listener)
|
36
|
+
|
37
|
+
attr_reader :argv
|
38
|
+
|
39
|
+
def initialize(argv)
|
40
|
+
if argv.empty?
|
41
|
+
@argv = ['start']
|
42
|
+
else
|
43
|
+
@argv = argv
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.run(argv = ARGV)
|
48
|
+
new(argv).run_command
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_command
|
52
|
+
command = parse(argv.shift)
|
53
|
+
if COMMAND_WHITELIST.include?(command)
|
54
|
+
puts WELCOME_MESSAGE unless ['version', 'help'].include?(command)
|
55
|
+
send(command)
|
56
|
+
else
|
57
|
+
write_error_message(command)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def help
|
62
|
+
write_usage
|
63
|
+
exit(0)
|
64
|
+
end
|
65
|
+
|
66
|
+
def version
|
67
|
+
puts Gorgon::VERSION
|
68
|
+
exit(0)
|
69
|
+
end
|
70
|
+
|
71
|
+
def start
|
72
|
+
o = Originator.new
|
73
|
+
exit o.originate
|
74
|
+
end
|
75
|
+
|
76
|
+
def listen
|
77
|
+
l = Listener.new
|
78
|
+
l.listen
|
79
|
+
end
|
80
|
+
|
81
|
+
def start_rsync
|
82
|
+
puts "Starting rsync daemon..."
|
83
|
+
directory = argv[0]
|
84
|
+
exit 1 unless RsyncDaemon.start directory
|
85
|
+
puts "Rsync Daemon is running. Use 'gorgon stop_rsync' to kill it."
|
86
|
+
end
|
87
|
+
|
88
|
+
def stop_rsync
|
89
|
+
puts "Stopping rsync daemon..."
|
90
|
+
exit 1 unless RsyncDaemon.stop
|
91
|
+
puts "Done"
|
92
|
+
end
|
93
|
+
|
94
|
+
def manage_workers
|
95
|
+
config_path = ENV["GORGON_CONFIG_PATH"]
|
96
|
+
|
97
|
+
manager = WorkerManager.build config_path
|
98
|
+
manager.manage
|
99
|
+
|
100
|
+
# For some reason I have to 'exit' here, otherwise WorkerManager process crashes
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
|
104
|
+
def ping
|
105
|
+
PingService.new.ping_listeners
|
106
|
+
end
|
107
|
+
|
108
|
+
def gem
|
109
|
+
gem_opts = argv.join(" ")
|
110
|
+
GemService.new.run(gem_opts)
|
111
|
+
end
|
112
|
+
|
113
|
+
def init
|
114
|
+
framework = argv[0]
|
115
|
+
Settings::InitialFilesCreator.run(framework)
|
116
|
+
end
|
117
|
+
|
118
|
+
def install_listener
|
119
|
+
ListenerInstaller.install
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def write_usage
|
125
|
+
puts USAGE
|
126
|
+
end
|
127
|
+
|
128
|
+
def parse(command)
|
129
|
+
case command
|
130
|
+
when '--version', '-v'
|
131
|
+
'version'
|
132
|
+
when 'help', '--help', '-h'
|
133
|
+
'help'
|
134
|
+
else
|
135
|
+
command
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def write_error_message(command)
|
140
|
+
puts "Error: Command '#{command}' not recognized"
|
141
|
+
write_usage
|
142
|
+
exit(1)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/lib/gorgon/configuration.rb
CHANGED
@@ -1,9 +1,49 @@
|
|
1
|
+
require "gorgon/core_ext/hash/deep_merge"
|
1
2
|
require "yajl"
|
2
3
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Gorgon
|
5
|
+
module Configuration
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def load_configuration_from_file(first_filename, merge: nil, file_loader: FileLoader)
|
9
|
+
ConfigurationParser.new(
|
10
|
+
file_loader: file_loader
|
11
|
+
).load_from_files(
|
12
|
+
first_filename: first_filename,
|
13
|
+
merge_filename: merge
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
class ConfigurationParser
|
18
|
+
def initialize(file_loader:)
|
19
|
+
@file_loader = file_loader
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_from_files(first_filename:, merge_filename:)
|
23
|
+
if merge_filename && @file_loader.exists?(merge_filename)
|
24
|
+
load_file(first_filename).deep_merge(load_file(merge_filename))
|
25
|
+
else
|
26
|
+
load_file(first_filename)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def load_file(filename)
|
33
|
+
@file_loader.parse(filename)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module FileLoader
|
38
|
+
def self.parse(filename)
|
39
|
+
file = File.new(filename, "r")
|
40
|
+
Yajl::Parser.new(symbolize_keys: true).parse(file)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.exists?(filename)
|
44
|
+
File.exists?(filename)
|
45
|
+
end
|
46
|
+
end
|
8
47
|
end
|
9
48
|
end
|
49
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Algorithm from 'activesupport/core_ext/hash/deep_merge'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def deep_merge(other_hash)
|
5
|
+
dup.deep_merge!(other_hash)
|
6
|
+
end
|
7
|
+
|
8
|
+
def deep_merge!(other_hash)
|
9
|
+
other_hash.each_pair do |current_key, other_value|
|
10
|
+
this_value = self[current_key]
|
11
|
+
|
12
|
+
self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
|
13
|
+
this_value.deep_merge(other_value)
|
14
|
+
else
|
15
|
+
other_value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
@@ -1,19 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Gorgon
|
2
|
+
module CrashReporter
|
3
|
+
OUTPUT_LINES_TO_REPORT = 70
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def report_crash reply_exchange, info
|
6
|
+
stdout = `tail -n #{OUTPUT_LINES_TO_REPORT} #{info[:out_file]}`
|
7
|
+
stderr = `cat #{info[:err_file]}` + \
|
8
|
+
info[:footer_text]
|
8
9
|
|
9
|
-
|
10
|
+
send_crash_message reply_exchange, stdout, stderr
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
"#{stdout}\n#{stderr}"
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def send_crash_message reply_exchange, output, error
|
16
|
+
reply = {:type => :crash, :hostname => Socket.gethostname,
|
17
|
+
:stdout => output, :stderr => error}
|
18
|
+
reply_exchange.publish(Yajl::Encoder.encode(reply))
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,40 +1,41 @@
|
|
1
1
|
require 'yajl'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Gorgon
|
4
|
+
class FailuresPrinter
|
5
|
+
DEFAULT_OUTPUT_FILE = "/tmp/gorgon-failed-files.json"
|
5
6
|
|
6
|
-
|
7
|
+
attr_reader :output_file
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def initialize(configuration, job_state)
|
10
|
+
@job_state = job_state
|
11
|
+
@job_state.add_observer(self)
|
12
|
+
@output_file = configuration.fetch(:failed_files) { DEFAULT_OUTPUT_FILE }
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def update payload
|
16
|
+
return unless @job_state.is_job_complete? || @job_state.is_job_cancelled?
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
File.open(@output_file, 'w+') do |fd|
|
19
|
+
fd.write(Yajl::Encoder.encode(failed_files + unfinished_files))
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def failed_files
|
26
|
+
failed_files = []
|
27
|
+
@job_state.each_failed_test do |test|
|
28
|
+
failed_files << "#{test[:filename]}"
|
29
|
+
end
|
30
|
+
failed_files
|
28
31
|
end
|
29
|
-
failed_files
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def unfinished_files
|
34
|
+
unfinished_files = []
|
35
|
+
@job_state.each_running_file do |hostname, filename|
|
36
|
+
unfinished_files << "#{filename}"
|
37
|
+
end
|
38
|
+
unfinished_files
|
36
39
|
end
|
37
|
-
unfinished_files
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
data/lib/gorgon/g_logger.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
require "logger"
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module Gorgon
|
4
|
+
module GLogger
|
5
|
+
SIZE_1_MB = 1048576
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def initialize_logger log_file
|
8
|
+
return unless log_file
|
9
|
+
@logger =
|
10
|
+
if log_file == "-"
|
11
|
+
Logger.new($stdout)
|
12
|
+
else
|
13
|
+
Logger.new(log_file, 1, SIZE_1_MB)
|
14
|
+
end
|
15
|
+
@logger.datetime_format = "%Y-%m-%d %H:%M:%S "
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def log text
|
19
|
+
@logger.info(text) if @logger
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def log_error text
|
23
|
+
@logger.error(text) if @logger
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|