Skip to content

Commit fbebb48

Browse files
author
Thomas Dalous
committed
fix(debug): make sure it always fallback to stderr
1 parent 337d639 commit fbebb48

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/algolia/logger_helper.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ class LoggerHelper
55
# @param debug_file [nil|String] file used to output the logs
66
#
77
def self.create(debug_file = nil)
8-
file = debug_file || (ENV['ALGOLIA_DEBUG'] ? File.open('debug.log', 'a+') : $stderr)
9-
instance = ::Logger.new file
8+
file = debug_file
9+
10+
if file.nil? && ENV['ALGOLIA_DEBUG']
11+
begin
12+
file = File.new('debug.log', 'a+')
13+
rescue Errno::EACCES, Errno::ENOENT => e
14+
puts "Failed to open debug.log: #{e.message}. Falling back to $stderr."
15+
end
16+
end
17+
18+
instance = ::Logger.new(file || $stderr)
1019
instance.progname = 'algolia'
1120
instance
1221
end

0 commit comments

Comments
 (0)