Module: NewspaperWorks::Logging
- Included in:
- Ingest::BatchIssueIngester, Ingest::NDNP::BatchIngester, Ingest::NDNP::IssueIngester, Ingest::NDNP::PageIngester, Ingest::PubFinder
- Defined in:
- lib/newspaper_works/logging.rb
Class Attribute Summary collapse
-
.configured ⇒ Object
Returns the value of attribute configured.
Instance Method Summary collapse
-
#configure_logger(name) ⇒ Object
Should be called by consuming class, prior to use of .logger method has checks to prevent duplicate configuration if already configured.
-
#log(severity, msg, progname = nil, &block) ⇒ Object
Log message, as in standard logger, but use message_format on message.
- #logger ⇒ Object
-
#message_format(msg) ⇒ Object
format message, distinct from per-output formatting, to be used in all logging channels Rails.logger broadcasts to.
-
#write_log(msg, severity = Logger::INFO, progname = nil) ⇒ Object
Simpler alternative to .log, with default severity, message_format wrapping.
Class Attribute Details
.configured ⇒ Object
Returns the value of attribute configured.
4 5 6 |
# File 'lib/newspaper_works/logging.rb', line 4 def configured @configured end |
Instance Method Details
#configure_logger(name) ⇒ Object
Should be called by consuming class, prior to use of .logger method
has checks to prevent duplicate configuration if already configured.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/newspaper_works/logging.rb', line 40 def configure_logger(name) @logger = Rails.logger return if NewspaperWorks::Logging.configured.include?(name) path = Rails.root.join("log/#{name}.log") @named_log = ActiveSupport::Logger.new(path) @named_log.formatter = proc do |_severity, datetime, _progname, msg| "#{datetime}: #{msg}\n" end # rails will log to named_log in addition to any other configured # or default logging destinations: @logger.extend(ActiveSupport::Logger.broadcast(@named_log)) NewspaperWorks::Logging.configured.push(name) end |
#log(severity, msg, progname = nil, &block) ⇒ Object
Log message, as in standard logger, but use message_format on message.
16 17 18 |
# File 'lib/newspaper_works/logging.rb', line 16 def log(severity, msg, progname = nil, &block) logger.add(severity, (msg), progname, &block) end |
#logger ⇒ Object
8 9 10 |
# File 'lib/newspaper_works/logging.rb', line 8 def logger @logger = Rails.logger end |
#message_format(msg) ⇒ Object
format message, distinct from per-output formatting, to be used in
all logging channels Rails.logger broadcasts to. This wrapping
indicates in parenthetical prefix which class is acting to
produce message.
34 35 36 |
# File 'lib/newspaper_works/logging.rb', line 34 def (msg) "(#{self.class}) #{msg}" end |
#write_log(msg, severity = Logger::INFO, progname = nil) ⇒ Object
Simpler alternative to .log, with default severity, message_format
wrapping.
25 26 27 |
# File 'lib/newspaper_works/logging.rb', line 25 def write_log(msg, severity = Logger::INFO, progname = nil) logger.add(severity, (msg), progname) end |