Skip to content

Commit

Permalink
Replace use of logger in bin/sequel
Browse files Browse the repository at this point in the history
Logger is moving from stdlib to bundled gems in Ruby 3.5, and will
start warning on Ruby 3.4. To prevent warnings and later errors
for users running bundle exec bin/sequel, this switches to a basic
logging approach. Note that this does not support calling
Database#sql_log_level= with a value other than :debug, :info,
:warn, or :error, but hopefully nobody is doing that in code
using bin/sequel.

One advantage to this change is it results in slightly less
cluttered log output.
  • Loading branch information
jeremyevans committed Jun 7, 2024
1 parent 89f8372 commit c1548a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Remove use of logger library in bin/sequel (jeremyevans)

* Support :connect_opts_proc Database option for late binding options (jeremyevans) (#2164)

=== 5.81.0 (2024-06-01)
Expand Down
21 changes: 17 additions & 4 deletions bin/sequel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ load_dirs = []
exclusive_options = []
loggers = []

logger_class = Class.new do
def initialize(device)
@device = device
end

def debug(msg)
end

[:info, :warn, :error].each do |meth|
define_method(meth) do |msg|
@device.puts("#{Time.now.strftime('%Y-%m-%d %T')} #{meth.to_s.upcase}: #{msg}")
end
end
end

options = OptionParser.new do |opts|
opts.banner = "Sequel: The Database Toolkit for Ruby"
opts.define_head "Usage: sequel [options] <uri|path> [file]"
Expand Down Expand Up @@ -61,17 +76,15 @@ options = OptionParser.new do |opts|
end

opts.on("-E", "--echo", "echo SQL statements") do
require 'logger'
loggers << Logger.new($stdout)
loggers << logger_class.new($stdout)
end

opts.on("-I", "--include dir", "specify $LOAD_PATH directory") do |v|
$: << v
end

opts.on("-l", "--log logfile", "log SQL statements to log file") do |v|
require 'logger'
loggers << Logger.new(v)
loggers << logger_class.new(File.open(v, 'a'))
end

opts.on("-L", "--load-dir DIR", "loads all *.rb under specifed directory") do |v|
Expand Down

0 comments on commit c1548a2

Please sign in to comment.