Class: BuildpackSupport::Logging::LoggerFactory
- Inherits:
-
Object
- Object
- BuildpackSupport::Logging::LoggerFactory
- Includes:
- Singleton
- Defined in:
- lib/buildpack_support/logging/logger_factory.rb
Overview
Responsible for configuring and creating all Logger
instances. Loggers created by the factory log all messages to a file located at app_dir/.buildpack.log
. They also log all messages, filtered by the configured severity, to $stderr. Severity can be configured (in decreasing priority) by using the JBP_LOG_LEVEL
environment variable, the Ruby $DEBUG and $VERBOSE flags, and the config/logging.yml
file. If none of these is set, then the severity defaults to INFO
.
Instance Attribute Summary collapse
-
#initialized ⇒ Object
readonly
Returns the value of attribute initialized.
Class Method Summary collapse
-
.get_logger(klass) ⇒ Logger
deprecated
Deprecated.
use LoggerFactory.instance.get_logger(klass) instead
Instance Method Summary collapse
-
#get_logger(klass) ⇒ Logger
Returns a configured logger for a given
Class
. -
#initialize ⇒ LoggerFactory
constructor
A new instance of LoggerFactory.
-
#log_file ⇒ Pathname
Returns the location of the log file.
-
#reset ⇒ Void
Resets the configuration of the factory.
-
#setup(app_dir) ⇒ Void
Sets up the logger factory.
Constructor Details
#initialize ⇒ LoggerFactory
Returns a new instance of LoggerFactory.
38 39 40 41 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 38 def initialize @configuration_utils = BuildpackSupport::ConfigurationUtils.new false @monitor = Monitor.new end |
Instance Attribute Details
#initialized ⇒ Object (readonly)
Returns the value of attribute initialized.
36 37 38 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 36 def initialized @initialized end |
Class Method Details
.get_logger(klass) ⇒ Logger
use LoggerFactory.instance.get_logger(klass) instead
Returns a configured logger for a given Class
. The Class
that is passed in is used as the progname
, for all messages logged by the logger. If this is called before the setup() method, a failure will be generated. Note this
94 95 96 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 94 def get_logger(klass) LoggerFactory.instance.get_logger(klass) end |
Instance Method Details
#get_logger(klass) ⇒ Logger
Returns a configured logger for a given Class
. The Class
that is passed in is used as the progname
, for all messages logged by the logger. If this is called before the setup() method, a failure will be generated.
60 61 62 63 64 65 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 60 def get_logger(klass) @monitor.synchronize do fail "Attempted to get Logger for #{short_class(klass)} before initialization" unless @initialized DelegatingLogger.new wrapped_short_class(klass), @delegates end end |
#log_file ⇒ Pathname
Returns the location of the log file. If this is called before the setup() method, a failure will be generated.
70 71 72 73 74 75 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 70 def log_file @monitor.synchronize do fail 'Attempted to get log file before initialization' unless @initialized @log_file end end |
#reset ⇒ Void
Resets the configuration of the factory
80 81 82 83 84 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 80 def reset @monitor.synchronize do @initialized = false end end |
#setup(app_dir) ⇒ Void
Sets up the logger factory
47 48 49 50 51 52 53 |
# File 'lib/buildpack_support/logging/logger_factory.rb', line 47 def setup(app_dir) @monitor.synchronize do @log_file = app_dir + '.buildpack.log' @delegates = [file_logger, console_logger] @initialized = true end end |