Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from codacy/debug-stdout
Browse files Browse the repository at this point in the history
Add the option to print DEBUG logger to stdout
  • Loading branch information
machadoit committed Dec 16, 2015
2 parents 2c2627b + 63c8d6b commit 1291bb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ This will install the required dependencies. Then just run the tests:
bundle exec rspec
```

By default, the debug info will be logged into a file. If you want the debug info to be printed to stdout you can:

```
export DEBUG_STDOUT=true
```

You can now check your coverage results in the Codacy dashboard of your project.
23 changes: 15 additions & 8 deletions lib/codacy/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ module Codacy
module Configuration

def self.logger
log_filename = self.temp_dir + 'codacy-coverage_' + Date.today.to_s + '.log'
log_file = File.open(log_filename, 'a')

logger_file = Logger.new(log_file)
logger_file.level = Logger::DEBUG
logger_info = logger_to_stdout
logger_info.level = Logger::INFO

logger_stdout = Logger.new(STDOUT)
logger_stdout.level = Logger::INFO
logger_debug = ENV["DEBUG_STDOUT"] ? logger_to_stdout : logger_to_file
logger_debug.level = Logger::DEBUG

log = MultiLogger.new(logger_stdout, logger_file)
log = MultiLogger.new(logger_info, logger_debug)

log
end

def self.logger_to_stdout
Logger.new(STDOUT)
end

def self.logger_to_file
log_filename = self.temp_dir + 'codacy-coverage_' + Date.today.to_s + '.log'
log_file = File.open(log_filename, 'a')
Logger.new(log_file)
end

def self.temp_dir
directory_name = Dir.tmpdir + "/codacy-coverage/"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
Expand Down

0 comments on commit 1291bb0

Please sign in to comment.