forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove deprecated remote logging. Addresses #213
API v3 used to have an endpoint for accepting remote log entries. This is no longer in place so remote logging needs to be removed.
- Loading branch information
Showing
2 changed files
with
3 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,13 @@ | ||
require 'rest_client' | ||
# Log using local methods | ||
# Local: provide the log level as a symbol (:debug, :info, :error, etc) | ||
|
||
class LOG | ||
def self.add(level, message) | ||
|
||
# Log using local or remote methods | ||
# Local: provide the log level as a symbol (:debug, :info, :error, etc) | ||
# Remote: provide the request and a parameter hash | ||
# Common Parameters: | ||
# :ontology_id | ||
# :ontology_name | ||
# :virtual_id | ||
# :concept_id | ||
# :concept_name | ||
def self.add(level, message, request = nil, remote_params = nil) | ||
if request | ||
if !$REMOTE_LOGGING.nil? && $REMOTE_LOGGING | ||
remote(level, message, request, remote_params) | ||
end | ||
else | ||
local(level, message) | ||
end | ||
end | ||
|
||
private | ||
|
||
def self.remote(level, event, request, params) | ||
params = {} if params.nil? | ||
params = convert_params(params) unless params.empty? | ||
|
||
log = RestClient::Resource.new $LEGACY_REST_URL + "/log", :timeout => 30 | ||
|
||
session = request.session | ||
params[:user] = session[:user].username rescue "" | ||
params[:userid] = session[:user].id rescue "" | ||
params[:ipaddress] = request.remote_ip | ||
params[:sessionid] = request.session_options[:id] | ||
params[:eventtype] = event | ||
params[:apikey] = $API_KEY | ||
params[:requesturl] = request.url | ||
|
||
begin | ||
ms = Benchmark.ms { log.post(params) } | ||
LOG.add :debug, "Logging action remotely (#{ms}ms)" | ||
rescue Exception=>e | ||
LOG.add :debug, "Remote logging failed: #{e.message}" | ||
end | ||
end | ||
|
||
# Convert parameter names before making the call. Removes underscores. | ||
def self.convert_params(params) | ||
params[:ontologyversionid] = params[:ontology_id] if params[:ontology_id] | ||
params[:ontologyid] = params[:virtual_id] if params[:ontologyid] | ||
params[:ontologyname] = params[:ontology_name] if params[:ontology_name] | ||
params[:conceptid] = params[:concept_id] if params[:concept_id] | ||
params[:conceptname] = params[:concept_name] if params[:concept_name] | ||
params[:query] = params[:search_term] if params[:search_term] | ||
params[:numsearchresults] = params[:result_count] if params[:result_count] | ||
params | ||
end | ||
|
||
def self.local(level, message) | ||
if defined? Rails.logger | ||
Rails.logger.send(level, message) | ||
else | ||
p "#{level} || #{message}" | ||
end | ||
end | ||
|
||
end |