Module: Adhearsion::Logging
- Defined in:
- lib/adhearsion/logging.rb
Defined Under Namespace
Modules: HasLogger
Constant Summary collapse
- LOG_LEVELS =
%w(TRACE DEBUG INFO WARN ERROR FATAL)
Class Method Summary collapse
- .adhearsion_pattern_options ⇒ Object
- .default_appenders ⇒ Object
- .formatter ⇒ Object (also: layout)
- .formatter=(formatter) ⇒ Object (also: layout=)
- .get_logger(logger_name) ⇒ Object
- .init ⇒ Object
- .logging_level ⇒ Object (also: level)
- .logging_level=(new_logging_level) ⇒ Object (also: level=)
- .outputters ⇒ Object (also: appenders)
- .outputters=(outputters) ⇒ Object (also: appenders=)
-
.reopen_logs ⇒ Object
Close logfiles and reopen them.
- .sanitized_logger_name(name) ⇒ Object
-
.silence! ⇒ Object
Silence Adhearsion’s logging, printing only FATAL messages.
- .start(_appenders = nil, level = :info, formatter = nil) ⇒ Object
-
.toggle_trace! ⇒ Object
Toggle between the configured log level and :trace Useful for debugging a live Adhearsion instance.
-
.unsilence! ⇒ Object
Restore the default configured logging level.
Class Method Details
.adhearsion_pattern_options ⇒ Object
37 38 39 40 41 42 |
# File 'lib/adhearsion/logging.rb', line 37 def { :pattern => '[%d] %-5l %c: %m\n', :date_pattern => '%Y-%m-%d %H:%M:%S.%L' } end |
.default_appenders ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/adhearsion/logging.rb', line 89 def default_appenders [::Logging.appenders.stdout( 'stdout', :layout => ::Logging.layouts.pattern( .merge( :color_scheme => 'bright' ) ), :auto_flushing => 2, :flush_period => 2 )] end |
.formatter ⇒ Object Also known as: layout
142 143 144 |
# File 'lib/adhearsion/logging.rb', line 142 def formatter ::Logging.logger.root.appenders.first.layout end |
.formatter=(formatter) ⇒ Object Also known as: layout=
134 135 136 137 138 |
# File 'lib/adhearsion/logging.rb', line 134 def formatter=(formatter) ::Logging.logger.root.appenders.each do |appender| appender.layout = formatter end end |
.get_logger(logger_name) ⇒ Object
112 113 114 |
# File 'lib/adhearsion/logging.rb', line 112 def get_logger(logger_name) ::Logging::Logger[logger_name] end |
.init ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/adhearsion/logging.rb', line 73 def init ::Logging.init LOG_LEVELS LOG_LEVELS.each do |level| Adhearsion::Logging.const_defined?(level) or Adhearsion::Logging.const_set(level, ::Logging::LEVELS[::Logging.levelify(level)]) end end |
.logging_level ⇒ Object Also known as: level
108 109 110 |
# File 'lib/adhearsion/logging.rb', line 108 def logging_level ::Logging.logger.root.level end |
.logging_level=(new_logging_level) ⇒ Object Also known as: level=
102 103 104 |
# File 'lib/adhearsion/logging.rb', line 102 def logging_level=(new_logging_level) ::Logging.logger.root.level = new_logging_level end |
.outputters ⇒ Object Also known as: appenders
128 129 130 |
# File 'lib/adhearsion/logging.rb', line 128 def outputters ::Logging.logger.root.appenders end |
.outputters=(outputters) ⇒ Object Also known as: appenders=
122 123 124 |
# File 'lib/adhearsion/logging.rb', line 122 def outputters=(outputters) ::Logging.logger.root.appenders = outputters end |
.reopen_logs ⇒ Object
Close logfiles and reopen them. Useful for log rotation.
67 68 69 70 71 |
# File 'lib/adhearsion/logging.rb', line 67 def reopen_logs logger.info "Closing logfiles." ::Logging.reopen logger.info "Logfiles reopened." end |
.sanitized_logger_name(name) ⇒ Object
118 119 120 |
# File 'lib/adhearsion/logging.rb', line 118 def sanitized_logger_name(name) name.to_s.gsub(/\W/, '').downcase end |
.silence! ⇒ Object
Silence Adhearsion’s logging, printing only FATAL messages
45 46 47 |
# File 'lib/adhearsion/logging.rb', line 45 def silence! self.logging_level = :fatal end |
.start(_appenders = nil, level = :info, formatter = nil) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/adhearsion/logging.rb', line 81 def start(_appenders = nil, level = :info, formatter = nil) ::Logging.logger.root.appenders = _appenders.nil? ? default_appenders : _appenders ::Logging.logger.root.level = level self.formatter = formatter if formatter end |
.toggle_trace! ⇒ Object
Toggle between the configured log level and :trace Useful for debugging a live Adhearsion instance
56 57 58 59 60 61 62 63 64 |
# File 'lib/adhearsion/logging.rb', line 56 def toggle_trace! if level == ::Logging.level_num(Adhearsion.config.platform.logging['level']) logger.warn "Turning TRACE logging ON." self.level = :trace else logger.warn "Turning TRACE logging OFF." self.level = Adhearsion.config.platform.logging['level'] end end |
.unsilence! ⇒ Object
Restore the default configured logging level
50 51 52 |
# File 'lib/adhearsion/logging.rb', line 50 def unsilence! self.logging_level = Adhearsion.config.platform.logging['level'] end |