Class: TestaLogger::Logger::Options
- Inherits:
-
Object
- Object
- TestaLogger::Logger::Options
- Defined in:
- lib/testa_logger/logger/options.rb
Instance Attribute Summary collapse
- #faye_token ⇒ String
- #faye_url ⇒ String
- #filepath ⇒ String?
- #formatter ⇒ Proc
- #level ⇒ Integer
- #live ⇒ TrueClass, FalseClass
- #persist ⇒ TrueClass, FalseClass
- #s3_credentials ⇒ Hash
- #shift_age ⇒ String, Integer
- #stdout ⇒ TrueClass, FalseClass
- #tag_length ⇒ Integer
Instance Method Summary collapse
- #format_app_and_groups(app, group, subgroup) ⇒ Object
- #handle_user_options(options) ⇒ Object
-
#initialize(app, group, subgroup, options) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(app, group, subgroup, options) ⇒ Options
Returns a new instance of Options.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/testa_logger/logger/options.rb', line 26 def initialize(app, group, subgroup, ) app_and_groups = format_app_and_groups(app, group, subgroup) @shift_age = "daily" @level = DEBUG @formatter = proc do |severity, datetime, _, msg| "#{app_and_groups}[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{format('%-5.5s', severity)} -- : #{msg}\n" end @live = false @stdout = false @filepath = nil @tag_length = 13 @persist = true # requires aws credentials set in env variables @faye_url = ENV.fetch("WEB_SOCKET_URL") { "http://ws-service:9292/faye" } @faye_token = ENV["FAYE_TOKEN"] @s3_credentials = { region: ENV["AWS_REGION"], access_key_id: ENV["AWS_ACCESS_KEY_ID"], secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"], bucket_name: ENV["S3_BUCKET_NAME"], } () @live = false if app == "ws" # will cause endless loop otherwise end |
Instance Attribute Details
#faye_token ⇒ String
21 22 23 |
# File 'lib/testa_logger/logger/options.rb', line 21 def faye_token @faye_token end |
#faye_url ⇒ String
21 22 23 |
# File 'lib/testa_logger/logger/options.rb', line 21 def faye_url @faye_url end |
#filepath ⇒ String?
18 19 20 |
# File 'lib/testa_logger/logger/options.rb', line 18 def filepath @filepath end |
#formatter ⇒ Proc
12 13 14 |
# File 'lib/testa_logger/logger/options.rb', line 12 def formatter @formatter end |
#level ⇒ Integer
9 10 11 |
# File 'lib/testa_logger/logger/options.rb', line 9 def level @level end |
#live ⇒ TrueClass, FalseClass
15 16 17 |
# File 'lib/testa_logger/logger/options.rb', line 15 def live @live end |
#persist ⇒ TrueClass, FalseClass
15 16 17 |
# File 'lib/testa_logger/logger/options.rb', line 15 def persist @persist end |
#s3_credentials ⇒ Hash
24 25 26 |
# File 'lib/testa_logger/logger/options.rb', line 24 def s3_credentials @s3_credentials end |
#shift_age ⇒ String, Integer
6 7 8 |
# File 'lib/testa_logger/logger/options.rb', line 6 def shift_age @shift_age end |
#stdout ⇒ TrueClass, FalseClass
15 16 17 |
# File 'lib/testa_logger/logger/options.rb', line 15 def stdout @stdout end |
#tag_length ⇒ Integer
9 10 11 |
# File 'lib/testa_logger/logger/options.rb', line 9 def tag_length @tag_length end |
Instance Method Details
#format_app_and_groups(app, group, subgroup) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/testa_logger/logger/options.rb', line 51 def format_app_and_groups(app, group, subgroup) string = "[ #{app} | #{group} " if subgroup.nil? string += "]" else string += "| #{subgroup} ]" end string end |
#handle_user_options(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/testa_logger/logger/options.rb', line 61 def () .deep_symbolize_keys! @shift_age = [:shift_age] unless [:shift_age].nil? unless [:level].nil? [:level] = SEV_LABEL.index([:level].to_s.upcase).to_i unless [:level].is_a?(Integer) @level = [:level] end @formatter = [:formatter] unless [:formatter].nil? @live = [:live] unless [:live].nil? @stdout = [:stdout] unless [:stdout].nil? @filepath = File.([:filepath]) unless [:filepath].nil? @tag_length = [:tag_length] unless [:tag_length].nil? @persist = [:persist] unless [:persist].nil? @faye_url = [:faye_url] unless [:faye_url].nil? @faye_token = [:faye_token] unless [:faye_token].nil? @s3_credentials = [:s3_credentials].deep_symbolize_keys if [:s3_credentials].present? end |