Module: Baltix::Log
- Included in:
- CLI, Loader, Baltix::Loader::Certain, Source::Base, Space
- Defined in:
- lib/baltix/log.rb
Constant Summary collapse
- DEFAULT_IO_NAMES =
{ none: nil, error: 'stderr', warn: 'stderr', info: 'stderr', debug: 'stderr', }
Class Method Summary collapse
- .default_prefix(ios) ⇒ Object
- .io_name_parse(io_names) ⇒ Object
- .ios ⇒ Object
- .level ⇒ Object
- .prefix ⇒ Object
- .prefix_for(kind, prefix) ⇒ Object
- .setup(level = :info, io_names = DEFAULT_IO_NAMES, prefix = nil) ⇒ Object
- .setup_kind(kind, io) ⇒ Object
Instance Method Summary collapse
Class Method Details
.default_prefix(ios) ⇒ Object
31 32 33 |
# File 'lib/baltix/log.rb', line 31 def default_prefix ios ios.keys.map {|kind| [kind, "[baltix][#{kind.upcase}]> " ] }.to_h end |
.io_name_parse(io_names) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/baltix/log.rb', line 53 def io_name_parse io_names io_names.map do |(kind, io_name)| io = case io_name when '-', 'stdout' $stdout when '--', 'stderr' $stderr when '', nil nil else File.open(io_name, 'a+') end [kind, io] end.to_h end |
.ios ⇒ Object
39 40 41 |
# File 'lib/baltix/log.rb', line 39 def ios @@ios ||= io_name_parse(DEFAULT_IO_NAMES) end |
.level ⇒ Object
43 44 45 |
# File 'lib/baltix/log.rb', line 43 def level @@level ||= :info end |
.prefix ⇒ Object
27 28 29 |
# File 'lib/baltix/log.rb', line 27 def prefix @@prefix ||= default_prefix(ios) end |
.prefix_for(kind, prefix) ⇒ Object
23 24 25 |
# File 'lib/baltix/log.rb', line 23 def prefix_for kind, prefix @@prefix[kind] = prefix end |
.setup(level = :info, io_names = DEFAULT_IO_NAMES, prefix = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/baltix/log.rb', line 47 def setup level = :info, io_names = DEFAULT_IO_NAMES, prefix = nil @@ios = io_name_parse(io_names) @@level = level @@prefix = prefix || default_prefix(ios) end |
.setup_kind(kind, io) ⇒ Object
35 36 37 |
# File 'lib/baltix/log.rb', line 35 def setup_kind kind, io ios[kind] = io end |