Class: PiscinaLogger
- Inherits:
-
Object
- Object
- PiscinaLogger
- Defined in:
- lib/piscina/piscina_logger.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Configure!.
- .construct_path_to_log(log_name) ⇒ Object
- .create_logger(log_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(log_name) ⇒ PiscinaLogger
constructor
A new instance of PiscinaLogger.
- #shutdown ⇒ Object
- #write(message, level) ⇒ Object
Constructor Details
#initialize(log_name) ⇒ PiscinaLogger
Returns a new instance of PiscinaLogger.
8 9 10 11 12 13 14 |
# File 'lib/piscina/piscina_logger.rb', line 8 def initialize(log_name) # Create a buffered pool of size one that will handle writing to the logs @thread_pool = Executors.newFixedThreadPool(1) # Creates a standard Ruby Logger @logger = PiscinaLogger.create_logger(log_name) end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/piscina/piscina_logger.rb', line 5 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
Configure!
55 56 57 58 |
# File 'lib/piscina/piscina_logger.rb', line 55 def self.configure self.configuration ||= Configuration.new yield(configuration) end |
.construct_path_to_log(log_name) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/piscina/piscina_logger.rb', line 29 def self.construct_path_to_log(log_name) raise "No logging directory defined" unless PiscinaLogger.configuration.log_directory log_dir = PiscinaLogger.configuration.log_directory File.join(log_dir, "#{log_name}_piscina.log") end |
.create_logger(log_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/piscina/piscina_logger.rb', line 16 def self.create_logger(log_name) log_path = construct_path_to_log(log_name) logger = Logger.new(log_path, 'daily') logger.formatter = proc do |severity, datetime, progname, msg| "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}]: #{msg}\n" end logger.level = PiscinaLogger.configuration.logging_level logger end |
Instance Method Details
#shutdown ⇒ Object
48 49 50 51 52 |
# File 'lib/piscina/piscina_logger.rb', line 48 def shutdown # TODO wait for pool to close down before closing logger @thread_pool.shutdown @logger.close end |
#write(message, level) ⇒ Object
36 37 38 39 40 |
# File 'lib/piscina/piscina_logger.rb', line 36 def write(, level) @thread_pool.execute do @logger.send(level, ) end end |