Class: ActiveCypher::Utils::Logger
- Inherits:
-
Object
- Object
- ActiveCypher::Utils::Logger
- Includes:
- Singleton
- Defined in:
- lib/active_cypher/utils/logger.rb
Overview
A singleton logger class for ActiveCypher
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .configure(options = {}) ⇒ Object
- .level ⇒ Object
- .level=(level) ⇒ Object
-
.setup ⇒ self
Setup with standard configuration for all examples.
-
.standard_formatter ⇒ Proc
Returns a standard formatter with time stamp.
Instance Method Summary collapse
-
#configure(options = {}) ⇒ Object
Configure the logger.
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#level ⇒ Integer
Get the current logger level.
-
#level=(level) ⇒ Object
Set the logger level.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
14 15 16 17 18 |
# File 'lib/active_cypher/utils/logger.rb', line 14 def initialize @logger = ::Logger.new($stdout) @logger.level = ::Logger::INFO @logger.formatter = self.class.standard_formatter end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/active_cypher/utils/logger.rb', line 12 def logger @logger end |
Class Method Details
.configure(options = {}) ⇒ Object
66 67 68 |
# File 'lib/active_cypher/utils/logger.rb', line 66 def configure( = {}) instance.configure() end |
.level ⇒ Object
70 71 72 |
# File 'lib/active_cypher/utils/logger.rb', line 70 def level instance.level end |
.level=(level) ⇒ Object
74 75 76 |
# File 'lib/active_cypher/utils/logger.rb', line 74 def level=(level) instance.level = level end |
.setup ⇒ self
Setup with standard configuration for all examples
89 90 91 |
# File 'lib/active_cypher/utils/logger.rb', line 89 def setup configure(formatter: standard_formatter) end |
.standard_formatter ⇒ Proc
Returns a standard formatter with time stamp
80 81 82 83 84 85 |
# File 'lib/active_cypher/utils/logger.rb', line 80 def standard_formatter proc do |severity, time, _progname, msg| time_str = time.strftime('%H:%M:%S.%L') "[#{time_str}] #{severity}: #{msg}\n" end end |
Instance Method Details
#configure(options = {}) ⇒ Object
Configure the logger
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_cypher/utils/logger.rb', line 25 def configure( = {}) @logger = ::Logger.new([:output]) if [:output] if [:level] level = [:level] level = ::Logger.const_get(level.to_s.upcase) if level.is_a?(Symbol) @logger.level = level end @logger.formatter = [:formatter] if [:formatter] self end |
#level ⇒ Integer
Get the current logger level
53 54 55 |
# File 'lib/active_cypher/utils/logger.rb', line 53 def level @logger.level end |
#level=(level) ⇒ Object
Set the logger level
59 60 61 62 |
# File 'lib/active_cypher/utils/logger.rb', line 59 def level=(level) level = ::Logger.const_get(level.to_s.upcase) if level.is_a?(Symbol) @logger.level = level end |