Class: BuildpackSupport::Logging::LoggerFactory

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoggerFactory

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

#initializedObject (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

Deprecated.

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

Parameters:

  • klass (Class)

    the class that the logger is created for

Returns:

  • (Logger)

    the logger that was requested



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.

Parameters:

  • klass (Class)

    the class that the logger is created for

Returns:

  • (Logger)

    the logger that was requested



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_filePathname

Returns the location of the log file. If this is called before the setup() method, a failure will be generated.

Returns:

  • (Pathname)

    the location of the log file



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

#resetVoid

Resets the configuration of the factory

Returns:

  • (Void)


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

Parameters:

  • app_dir (Pathname)

    the application directory

Returns:

  • (Void)


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