Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Typesense.configuration = {
protocol: 'http' # For Typesense Cloud use https
}],
api_key: 'your-api-key',
connection_timeout_seconds: 2
connection_timeout_seconds: 2,
log_level: :info # Optional: Set logging level (:debug, :info, :warn, :error, :fatal, :unknown)
}
```

Expand Down
12 changes: 6 additions & 6 deletions lib/typesense-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require "logger"
Rails.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
Rails.logger.level = Logger::INFO
Rails.logger.level = Logger::WARN

module Typesense
class NotConfigured < StandardError; end
Expand Down Expand Up @@ -269,7 +269,7 @@ def typesense_create_collection(collection_name, settings = nil)
metadata ? { "metadata" => metadata } : {}
)
)
Rails.logger.info "Collection '#{collection_name}' created!"
Rails.logger.debug "Collection '#{collection_name}' created!"

typesense_multi_way_synonyms(collection_name, multi_way_synonyms) if multi_way_synonyms

Expand Down Expand Up @@ -542,7 +542,7 @@ def typesense_index_objects_async(objects, batch_size = Typesense::IndexSettings
end
jsonl_object = documents.join("\n")
ImportJob.perform(jsonl_object, collection_obj[:alias_name], batch_size)
Rails.logger.info "#{objects.length} objects enqueued for import into #{collection_obj[:collection_name]}"
Rails.logger.debug "#{objects.length} objects enqueued for import into #{collection_obj[:collection_name]}"
end
nil
end
Expand All @@ -557,7 +557,7 @@ def typesense_index_objects(objects, batch_size = Typesense::IndexSettings::DEFA
end
jsonl_object = documents.join("\n")
import_documents(jsonl_object, "upsert", collection_obj[:alias_name], batch_size: batch_size)
Rails.logger.info "#{objects.length} objects upserted into #{collection_obj[:collection_name]}!"
Rails.logger.debug "#{objects.length} objects upserted into #{collection_obj[:collection_name]}!"
end
nil
end
Expand Down Expand Up @@ -613,7 +613,7 @@ def typesense_remove_from_index!(object)
rescue Typesense::Error::ObjectNotFound => e
Rails.logger.error "Object #{object_id} could not be removed from #{collection_obj[:collection_name]} collection! Use reindex to update the collection."
end
Rails.logger.info "Removed document with object id '#{object_id}' from #{collection_obj[:collection_name]}"
Rails.logger.debug "Removed document with object id '#{object_id}' from #{collection_obj[:collection_name]}"
end
nil
end
Expand All @@ -626,7 +626,7 @@ def typesense_clear_index!
collection_obj = typesense_ensure_init(options, settings, false)

delete_collection(collection_obj[:alias_name])
Rails.logger.info "Deleted #{collection_obj[:alias_name]} collection!"
Rails.logger.debug "Deleted #{collection_obj[:alias_name]} collection!"
@typesense_indexes[settings] = nil
end
nil
Expand Down
26 changes: 26 additions & 0 deletions lib/typesense/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,39 @@ def configuration

def configuration=(configuration)
@@pagination_backend = configuration[:pagination_backend] if configuration.key?(:pagination_backend)
@@log_level = configuration[:log_level] if configuration.key?(:log_level)
@@configuration = configuration

Rails.logger.level = log_level_to_const(configuration[:log_level])
end

def pagination_backend
@@pagination_backend
end

def log_level
@@log_level
end

def log_level_to_const(level)
case level
when :debug
Logger::DEBUG
when :info
Logger::INFO
when :warn
Logger::WARN
when :error
Logger::ERROR
when :fatal
Logger::FATAL
when :unknown
Logger::UNKNOWN
else
Logger::WARN # default fallback
end
end

def client
setup_client if @client.nil?
@client
Expand Down