Skip to content

Commit 9db3c0a

Browse files
committed
feat(logger): add configurable log levels and default to warn
1 parent 04f3f6b commit 9db3c0a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/typesense/config.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,39 @@ def configuration
1111

1212
def configuration=(configuration)
1313
@@pagination_backend = configuration[:pagination_backend] if configuration.key?(:pagination_backend)
14+
@@log_level = configuration[:log_level] if configuration.key?(:log_level)
1415
@@configuration = configuration
16+
17+
Rails.logger.level = log_level_to_const(configuration[:log_level])
1518
end
1619

1720
def pagination_backend
1821
@@pagination_backend
1922
end
2023

24+
def log_level
25+
@@log_level
26+
end
27+
28+
def log_level_to_const(level)
29+
case level
30+
when :debug
31+
Logger::DEBUG
32+
when :info
33+
Logger::INFO
34+
when :warn
35+
Logger::WARN
36+
when :error
37+
Logger::ERROR
38+
when :fatal
39+
Logger::FATAL
40+
when :unknown
41+
Logger::UNKNOWN
42+
else
43+
Logger::WARN # default fallback
44+
end
45+
end
46+
2147
def client
2248
setup_client if @client.nil?
2349
@client

0 commit comments

Comments
 (0)