Module: JetstreamBridge::Logging
- Defined in:
- lib/jetstream_bridge/core/logging.rb
Overview
Logging helpers that route to the configured logger when available, falling back to Rails.logger or STDOUT.
Class Method Summary collapse
- .debug(msg, tag: nil) ⇒ Object
- .default_logger ⇒ Object
- .error(msg, tag: nil) ⇒ Object
- .info(msg, tag: nil) ⇒ Object
- .log(level, msg, tag: nil) ⇒ Object
- .logger ⇒ Object
- .sanitize_url(url) ⇒ Object
- .warn(msg, tag: nil) ⇒ Object
Class Method Details
.debug(msg, tag: nil) ⇒ Object
27 28 29 |
# File 'lib/jetstream_bridge/core/logging.rb', line 27 def debug(msg, tag: nil) log(:debug, msg, tag: tag) end |
.default_logger ⇒ Object
18 19 20 |
# File 'lib/jetstream_bridge/core/logging.rb', line 18 def default_logger @default_logger ||= Logger.new($stdout) end |
.error(msg, tag: nil) ⇒ Object
39 40 41 |
# File 'lib/jetstream_bridge/core/logging.rb', line 39 def error(msg, tag: nil) log(:error, msg, tag: tag) end |
.info(msg, tag: nil) ⇒ Object
31 32 33 |
# File 'lib/jetstream_bridge/core/logging.rb', line 31 def info(msg, tag: nil) log(:info, msg, tag: tag) end |
.log(level, msg, tag: nil) ⇒ Object
22 23 24 25 |
# File 'lib/jetstream_bridge/core/logging.rb', line 22 def log(level, msg, tag: nil) = tag ? "[#{tag}] #{msg}" : msg logger.public_send(level, ) end |
.logger ⇒ Object
12 13 14 15 16 |
# File 'lib/jetstream_bridge/core/logging.rb', line 12 def logger JetstreamBridge.config.logger || (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) || default_logger end |
.sanitize_url(url) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jetstream_bridge/core/logging.rb', line 43 def sanitize_url(url) uri = URI.parse(url) return url unless uri.user || uri.password userinfo = if uri.password # user:pass → keep user, mask pass "#{uri.user}:***" else # token-only userinfo → mask entirely '***' end host = uri.host || '' port = uri.port ? ":#{uri.port}" : '' path = uri.path.to_s # omit query on purpose to avoid leaking tokens frag = uri.fragment ? "##{uri.fragment}" : '' "#{uri.scheme}://#{userinfo}@#{host}#{port}#{path}#{frag}" rescue URI::InvalidURIError # Fallback: redact any userinfo before the '@' url.gsub(%r{(nats|tls)://([^@/]+)@}i) do scheme = Regexp.last_match(1) creds = Regexp.last_match(2) masked = creds&.include?(':') ? "#{creds&.split(':', 2)&.first}:***" : '***' "#{scheme}://#{masked}@" end end |
.warn(msg, tag: nil) ⇒ Object
35 36 37 |
# File 'lib/jetstream_bridge/core/logging.rb', line 35 def warn(msg, tag: nil) log(:warn, msg, tag: tag) end |