Class: GitStatistics::Log
- Inherits:
-
Object
- Object
- GitStatistics::Log
- Includes:
- Singleton
- Defined in:
- lib/git_statistics/log.rb
Instance Attribute Summary collapse
-
#base_directory ⇒ Object
Returns the value of attribute base_directory.
-
#debugging ⇒ Object
Returns the value of attribute debugging.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .method_missing(method, *args, &blk) ⇒ Object
-
.parse_caller(message) ⇒ Object
Determine the file, method, line number of the caller.
- .respond_to_missing?(method, include_all = false) ⇒ Boolean
- .use_debug ⇒ Object
- .valid_method?(method) ⇒ Boolean
Instance Method Summary collapse
-
#initialize ⇒ Log
constructor
A new instance of Log.
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
10 11 12 13 14 15 16 17 18 |
# File 'lib/git_statistics/log.rb', line 10 def initialize @base_directory = File.("../..", __FILE__) + "/" @debugging = false @logger = Logger.new(STDOUT) @logger.level = Logger::ERROR @logger.formatter = proc do |sev, datetime, progname, msg| "#{msg}\n" end end |
Instance Attribute Details
#base_directory ⇒ Object
Returns the value of attribute base_directory.
8 9 10 |
# File 'lib/git_statistics/log.rb', line 8 def base_directory @base_directory end |
#debugging ⇒ Object
Returns the value of attribute debugging.
8 9 10 |
# File 'lib/git_statistics/log.rb', line 8 def debugging @debugging end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/git_statistics/log.rb', line 8 def logger @logger end |
Class Method Details
.method_missing(method, *args, &blk) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/git_statistics/log.rb', line 37 def self.method_missing(method, *args, &blk) if valid_method? method instance.logger.progname = parse_caller(caller(1).first) if instance.debugging instance.logger.send(method, *args, &blk) else super end end |
.parse_caller(message) ⇒ Object
Determine the file, method, line number of the caller
28 29 30 31 32 33 34 35 |
# File 'lib/git_statistics/log.rb', line 28 def self.parse_caller() if /^(?<file>.+?):(?<line>\d+)(?::in `(?<method>.*)')?/ =~ file = Regexp.last_match[:file] line = Regexp.last_match[:line] method = Regexp.last_match[:method] "#{file.sub(instance.base_directory, "")}:#{line}" end end |
.respond_to_missing?(method, include_all = false) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/git_statistics/log.rb', line 46 def self.respond_to_missing?(method, include_all=false) if valid_method? method true else super end end |
.use_debug ⇒ Object
20 21 22 23 24 25 |
# File 'lib/git_statistics/log.rb', line 20 def self.use_debug instance.debugging = true instance.logger.formatter = proc do |sev, datetime, progname, msg| "#{sev} [#{progname}]: #{msg}\n" end end |
.valid_method?(method) ⇒ Boolean
54 55 56 |
# File 'lib/git_statistics/log.rb', line 54 def self.valid_method?(method) instance.logger.respond_to? method end |