Created
August 10, 2024 13:06
-
-
Save motebaya/d3436ec35874a342e01da10170c85bca to your computer and use it in GitHub Desktop.
remove all unnecessary characters that are displayed in the console during debug mode for net/http or HTTParty. Related: https://github.com/jnunemaker/httparty/issues/806
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'logger' | |
class Logging | |
def initialize(progname:, level: Logger::INFO) | |
@logger = Logger.new($stdout, progname: progname) | |
@logger.level = level | |
end | |
# crlf -> \r\n" at endline | |
# hexadecimal inside double quote -> "000070a" | |
# read/reading bytes section -> reading/read <int> bytes... | |
# unicode escape bytes -> "\x1F\x8B.....\b\x00\"" | |
def <<(msg) | |
msg = msg.strip.gsub('\\r\\n"', '"') | |
return if msg.empty? || msg.match(/reading\s\d+\sbytes|<-|read\s\d+\sbytes/) || msg.match(/"[^"]{1,5}"/) || msg.match(/->\s""/) || msg.match(/->.*\\x[0-9A-Fa-f]{2}.*/) || msg.match(/->\s"[\d+]*"$/) || msg.match?(/->\s"\h+"$/) | |
@logger.debug(msg.strip) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call:
res: