Class: GitCommitNotifier::Logger
- Inherits:
-
Object
- Object
- GitCommitNotifier::Logger
- Defined in:
- lib/git_commit_notifier/logger.rb
Constant Summary collapse
- DEFAULT_LOG_DIRECTORY =
Dir.tmpdir.freeze
- LOG_NAME =
'git-commit-notifier.log'.freeze
Instance Attribute Summary collapse
-
#log_directory ⇒ Object
readonly
Returns the value of attribute log_directory.
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #debug? ⇒ Boolean
- #file(file_path) ⇒ Object
-
#initialize(config) ⇒ Logger
constructor
A new instance of Logger.
- #log_path ⇒ Object
Constructor Details
#initialize(config) ⇒ Logger
Returns a new instance of Logger.
11 12 13 14 |
# File 'lib/git_commit_notifier/logger.rb', line 11 def initialize(config) @enabled = !!(config['debug'] && config['debug']['enabled']) @log_directory = debug? ? (config['debug']['log_directory'] || DEFAULT_LOG_DIRECTORY) : nil end |
Instance Attribute Details
#log_directory ⇒ Object (readonly)
Returns the value of attribute log_directory.
9 10 11 |
# File 'lib/git_commit_notifier/logger.rb', line 9 def log_directory @log_directory end |
Instance Method Details
#debug(msg) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/git_commit_notifier/logger.rb', line 25 def debug(msg) return unless debug? File.open(log_path, 'a') do |f| f.puts msg end end |
#debug? ⇒ Boolean
16 17 18 |
# File 'lib/git_commit_notifier/logger.rb', line 16 def debug? @enabled end |
#file(file_path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/git_commit_notifier/logger.rb', line 32 def file(file_path) return unless debug? orig_dest_name = File.join(log_directory, File.basename(file_path)) dest_name = orig_dest_name counter = 1 while File.exists?(dest_name) counter += 1 dest_name = "#{orig_dest_name}.#{counter}" end debug("Save file #{file_path} for debugging purposes to #{dest_name}") File.copy(file_path, dest_name) end |
#log_path ⇒ Object
20 21 22 23 |
# File 'lib/git_commit_notifier/logger.rb', line 20 def log_path return nil unless debug? File.join(log_directory, LOG_NAME) end |