On Tuesday, January 19, 2021 at 12:25:55 AM UTC+1 Jeremy Evans wrote:

> On Mon, Jan 18, 2021 at 2:38 PM José Oliver Segura <[email protected]> 
> wrote:
>
>> Hi all,
>>
>> I haven't been able to find how to do this, so I would like to ask if 
>> it's somehow supported or not.
>>
>> During development, logging of SQL statements include the full statement, 
>> including blobs contents when they're involved. For some large blobs, this 
>> slows down development and makes logging almost unusable, since you need to 
>> do a lot of scroll to find where things where happening.
>>
>> So, is there any way to make Sequel suppress part of those blobs when 
>> logging? I'll be happy with just some start/end bytes (something like 
>> Blob.inspect does)
>>
>
> Sequel logs the full SQL statement submitted, there is nothing available 
> currently to log different SQL than what is submitted to the database.  
> You'll have to use a custom log formatter if you want to modify the logged 
> output.  Maybe something similar to:
>
> require 'logger'
> logger = Logger.new
> logger.formatter = proc do |severity, datetime, progname, msg|
>   msg = msg.gsub(/blob_col = '([^']+)'/){"blob_col = [#{$1.size} bytes]"}  
>   "#{datetime}: #{msg}\n"
> end
> DB.logger = logger
>
> Thanks,
> Jeremy
>

Thanks for the hint. I've modified it a little bit, since the SQL command 
issued doesn't match
the regexp for "blob_col = '...'".

Here's my modified version, just in case someone finds it useful. Note that 
the regexp probably
may fail if there is more than one blob in the statement or depending on 
the columns/values. This
works for my case, so take it with a little bit of care if you want to use 
it:

  LOGGER.formatter = proc do |severity, datetime, progname, 
msg|                
    if msg =~ / VALUES 
.+(X'[^']+')/                                            
      if $1.size > 
18                                                           
        blb_short = "BLOB(#{$1.size} bytes, start=#{$1[2..10]}, 
end=#{$1[-9..-2]})"
        msg = msg.gsub($1, 
blb_short)                                           
      
end                                                                       
    
end                                                                         
    "#{datetime}: 
#{msg}\n"                                                     
  
end                                                                          
 
  DB.loggers << LOGGER                       
                                   
Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/e2fedd94-8499-4356-b402-c7dc05fc89fan%40googlegroups.com.

Reply via email to