Module: PunchblockConsole::Logging
- Defined in:
- lib/punchblock/console/logging.rb
Constant Summary collapse
- LOG_LEVELS =
%w(TRACE DEBUG INFO WARN ERROR FATAL)
Class Method Summary collapse
- .formatter ⇒ Object (also: layout)
- .formatter=(formatter) ⇒ Object (also: layout=)
- .get_logger(logger_name) ⇒ Object
- .logging_level ⇒ Object (also: level)
- .logging_level=(new_logging_level) ⇒ Object (also: level=)
- .outputters ⇒ Object (also: appenders)
- .outputters=(outputters) ⇒ Object (also: appenders=)
- .reset ⇒ Object
- .sanitized_logger_name(name) ⇒ Object
- .silence! ⇒ Object
- .start(log_file = nil) ⇒ Object
- .unsilence! ⇒ Object
Class Method Details
.formatter ⇒ Object Also known as: layout
102 103 104 |
# File 'lib/punchblock/console/logging.rb', line 102 def formatter ::Logging.logger.root.appenders.first.layout end |
.formatter=(formatter) ⇒ Object Also known as: layout=
96 97 98 |
# File 'lib/punchblock/console/logging.rb', line 96 def formatter=(formatter) _set_formatter formatter end |
.get_logger(logger_name) ⇒ Object
74 75 76 |
# File 'lib/punchblock/console/logging.rb', line 74 def get_logger(logger_name) ::Logging::Logger[logger_name] end |
.logging_level ⇒ Object Also known as: level
70 71 72 |
# File 'lib/punchblock/console/logging.rb', line 70 def logging_level ::Logging::Logger[:root].level end |
.logging_level=(new_logging_level) ⇒ Object Also known as: level=
64 65 66 |
# File 'lib/punchblock/console/logging.rb', line 64 def logging_level=(new_logging_level) ::Logging::Logger[:root].level = new_logging_level end |
.outputters ⇒ Object Also known as: appenders
90 91 92 |
# File 'lib/punchblock/console/logging.rb', line 90 def outputters ::Logging.logger.root.appenders end |
.outputters=(outputters) ⇒ Object Also known as: appenders=
84 85 86 |
# File 'lib/punchblock/console/logging.rb', line 84 def outputters=(outputters) ::Logging.logger.root.appenders = Array(outputters) end |
.reset ⇒ Object
40 41 42 |
# File 'lib/punchblock/console/logging.rb', line 40 def reset ::Logging.reset end |
.sanitized_logger_name(name) ⇒ Object
80 81 82 |
# File 'lib/punchblock/console/logging.rb', line 80 def sanitized_logger_name(name) name.to_s.gsub(/\W/, '').downcase end |
.silence! ⇒ Object
32 33 34 |
# File 'lib/punchblock/console/logging.rb', line 32 def silence! self.logging_level = :fatal end |
.start(log_file = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/punchblock/console/logging.rb', line 44 def start(log_file = nil) opts = { :layout => ::Logging.layouts.pattern( :pattern => '[%d] %-5l %c: %m\n', :color_scheme => 'bright' ) } self.outputters = if log_file ::Logging.appenders.file log_file, opts else ::Logging.appenders.stdout 'stdout', opts end ::Logging.init LOG_LEVELS LOG_LEVELS.each do |level| PunchblockConsole::Logging.const_defined?(level) or PunchblockConsole::Logging.const_set(level, ::Logging::LEVELS[::Logging.levelify(level)]) end end |
.unsilence! ⇒ Object
36 37 38 |
# File 'lib/punchblock/console/logging.rb', line 36 def unsilence! self.logging_level = :info end |