class BigKeeper::LeanCloudLogger
Attributes
command[RW]
end_timestamp[RW]
is_success[RW]
need_log[RW]
parameter[RW]
path[RW]
start_timestamp[RW]
user[RW]
version[RW]
Public Class Methods
new()
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 12 def initialize @need_log = "true" end
Public Instance Methods
end_log(is_success, is_show_log)
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 33 def end_log(is_success, is_show_log) @end_timestamp = Time.new.to_i @is_success = is_success @version = BigkeeperParser.version if @version == 'Version in Bigkeeper file' # require parameter = {'start_timestamp' => @start_timestamp, 'end_timestamp' =>@end_timestamp, 'user' =>@user, 'is_success' =>@is_success} # optional parameter = parameter.merge('command' => @command) unless @command == nil parameter = parameter.merge('version' => @version) unless @version == nil || @version == "" parameter = parameter.merge('parameter' => @parameter) unless @parameter == nil || @parameter == "" if @command leancloud_file = @command.split("/").first send_log_cloud(leancloud_file, parameter, is_show_log) end end
is_need_log()
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 20 def is_need_log @need_log == "true" end
set_command(set_command)
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 16 def set_command(set_command) @command = set_command end
start_log(global_options, args)
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 24 def start_log(global_options, args) @start_timestamp = Time.new.to_i @user = global_options['user'].to_s @parameter = args.join(",") @version = global_options['ver'] @path = global_options['path'] @need_log = "#{global_options[:log]}" end
Protected Instance Methods
assemble_request()
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 78 def assemble_request return {'Content-Type' =>'application/json', 'X-LC-Id' =>BigkeeperParser.global_configs("LeanCloudId"), 'X-LC-Key' =>BigkeeperParser.global_configs("LeanCloudKey")} end
send_log_cloud(file_name, parameter, is_show_log)
click to toggle source
# File lib/big_keeper/util/leancloud_logger.rb, line 52 def send_log_cloud(file_name, parameter, is_show_log) if file_name == nil return end if BigkeeperParser.global_configs("LeanCloudId") == nil || BigkeeperParser.global_configs("LeanCloudKey") == nil return end header = assemble_request uri = URI.parse("https://api.leancloud.cn/1.1/classes/#{file_name}") https = Net::HTTP.new(uri.host, 443) https.use_ssl = true https.ssl_version = :TLSv1 https.verify_mode = OpenSSL::SSL::VERIFY_PEER req = Net::HTTP::Post.new(uri.path, header) req.body = parameter.to_json res = https.request(req) if is_show_log == true Logger.highlight("Send LeanCloud success, response #{res.body}") end end