require 'logworm' require 'logworm_client/logger' require 'logworm_client/rack' require 'logworm_client/rails' def lw_log (logname, values) Logworm::Logger.log(logname, values) end ### # Perform a query against the logworm server # # Requires a log table, and a query # The query can be provided as a JSON string, following the syntax described in http://www.logworm.com/docs/query # or as a Hash of options, with the following keys (all optional) # :fields => String with a comma-separated list of fields (quoted or not), or Array of Strings # :aggregate_function => String # :aggregate_argument => String # :aggregate_group => String with a comma-separated list of fields (quoted or not), or Array of Strings # :conditions => String with comma-separated conditions (in MongoDB syntax), or Array of Strings # :start => String or Integer (for year) # :end => String or Integer (for year) # :limit => String or Integer # # See Logworm::QueryBuilder # # Returns Hash with # id ==> id of the query # query_url ==> URL to GET information about the query # results_url ==> URL to GET the results for the query # created ==> First creation of the query # updated ==> most recent update of the query and/or its results # execution_time ==> time in ms to run the query # results ==> array of hashmaps. Each element corresponds to a log entry, with its fields # # raises Logworm::DatabaseException, Logworm::ForbiddenAccessException, Logworm::InvalidQueryException # or just a regular Exception if it cannot find the URL to the logging database ### def lw_query(table, query) db = Logworm::DB.from_config_or_die # Establish connection to DB query = Logworm::QueryBuilder.new(query).to_json if query.is_a? Hash # Turn query into proper JSON string query_data = db.query(table, query) # POST to create query db.results(query_data["results_uri"]) # GET from query's results uri end