Skip to content

Commit 6e99b08

Browse files
committed
#48 - add logger;
1 parent 7a4af47 commit 6e99b08

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.rbc
22
*.sassc
3+
*.log
34
.sass-cache
45
capybara-*.html
56
.rspec

bin/veye

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ flag :timeout, :default_value => 180
4444
desc 'force open timeout (in seconds)'
4545
flag :open_timeout, :default_value => 20
4646

47+
desc 'set log level'
48+
flag :log_level, :default_value => 'debug'
49+
4750
pre do |global_options, command, args|
4851
check_config_file
4952
$global_options = init_environment

lib/veye.rb

+26-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# you just need to require this one file in your bin file
33
require 'rest-client'
44
require 'yaml'
5+
require 'logger'
56

67
require 'veye/helpers/format_helpers.rb'
78

@@ -30,7 +31,7 @@ def config_exists?
3031

3132
def check_config_file
3233
unless config_exists?
33-
p format(
34+
printf(
3435
"%s: %s\n",
3536
'config file doesnt exist.'.color(:red),
3637
'Use `veye initconfig` to initialize settings file.'
@@ -57,7 +58,7 @@ def init_environment
5758
def check_api_key(global_opts)
5859
result = false
5960
if global_opts[:api_key].nil? || global_opts[:api_key].match("add your api key")
60-
print format(
61+
printf(
6162
"%s: %s\n",
6263
'Warning: API key is missing.'.color(:yellow),
6364
'You cant access private data.'
@@ -74,9 +75,31 @@ def save_configs
7475
File.open(filepath, 'w') do |f|
7576
f.puts $global_options.to_yaml
7677
end
77-
print format(
78+
printf(
7879
"%s: %s",
7980
'Success'.color(:green),
8081
"new settings are saved into file: `#{filepath}`"
8182
)
8283
end
84+
85+
86+
#-- initialize logger
87+
module Veye
88+
class << self
89+
attr_writer :logger
90+
91+
def logger
92+
@logger ||= Logger.new('veye.log').tap do |log|
93+
log.level = case $global_options.fetch(:log_level, 'debug')
94+
when 'info' then Logger::INFO
95+
when 'debug' then Logger::DEBUG
96+
when 'warn' then Logger::INFO
97+
when 'error' then Logger::ERROR
98+
when 'fatal' then Logger::FATAL
99+
else Logger::DEBUG
100+
end
101+
log.progname = self.name
102+
end
103+
end
104+
end
105+
end

lib/veye/api/project.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def self.get_list(api_key, org_name, team_name = nil)
3636
end
3737

3838
def self.upload(api_key, filename, org_name = nil, team_name = nil, temporary = false, public =true, name = nil)
39+
Veye.logger.info("Uploading `#{filename}` under #{org_name}, temporary? #{temporary}, organization? #{public} ")
3940
project_api = Resource.new(RESOURCE_PATH)
4041
file_path = check_file(filename)
4142
return if file_path.nil?

lib/veye/base_executor.rb

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def self.show_results(output_formats, results, options = {}, paging = nil)
2222
def self.valid_response?(response, msg)
2323
if response.nil? || response.success != true
2424
printf "#{msg.to_s.color(:red)}: #{response.data}\n"
25+
Veye.logger.error "API returned error - #{response.code}, #{response.data}"
2526
return false
2627
end
2728

lib/veye/project/check.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Check < BaseExecutor
2424
}
2525

2626
def self.get_list(api_key, org_name = 'private', team_name = nil, options)
27+
Veye.logger.info "Fetching a list of project for #{org_name}, team:#{team_name}"
2728
results = Veye::API::Project.get_list(api_key, org_name, team_name)
2829
valid_response?(results, 'Can not read list of projects.')
2930
show_results(@output_formats, results.data, options)

0 commit comments

Comments
 (0)