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) ⇒ void
-
.default_logger ⇒ Logger
Returns a default STDOUT logger, memoized for reuse.
- .error(msg, tag: nil) ⇒ void
- .info(msg, tag: nil) ⇒ void
-
.log(level, msg, tag: nil) ⇒ void
Log a message at the given level with an optional tag prefix.
-
.logger ⇒ Logger
Returns the active logger instance.
- .sanitize_url(url) ⇒ Object
- .warn(msg, tag: nil) ⇒ void
Class Method Details
.debug(msg, tag: nil) ⇒ void
This method returns an undefined value.
44 45 46 |
# File 'lib/jetstream_bridge/core/logging.rb', line 44 def debug(msg, tag: nil) log(:debug, msg, tag: tag) end |
.default_logger ⇒ Logger
Returns a default STDOUT logger, memoized for reuse.
26 27 28 |
# File 'lib/jetstream_bridge/core/logging.rb', line 26 def default_logger @default_logger ||= Logger.new($stdout) end |
.error(msg, tag: nil) ⇒ void
This method returns an undefined value.
65 66 67 |
# File 'lib/jetstream_bridge/core/logging.rb', line 65 def error(msg, tag: nil) log(:error, msg, tag: tag) end |
.info(msg, tag: nil) ⇒ void
This method returns an undefined value.
51 52 53 |
# File 'lib/jetstream_bridge/core/logging.rb', line 51 def info(msg, tag: nil) log(:info, msg, tag: tag) end |
.log(level, msg, tag: nil) ⇒ void
This method returns an undefined value.
Log a message at the given level with an optional tag prefix.
36 37 38 39 |
# File 'lib/jetstream_bridge/core/logging.rb', line 36 def log(level, msg, tag: nil) = tag ? "[#{tag}] #{msg}" : msg logger.public_send(level, ) end |
.logger ⇒ Logger
Returns the active logger instance.
Resolution order: configured logger, Rails.logger, STDOUT fallback.
17 18 19 20 21 |
# File 'lib/jetstream_bridge/core/logging.rb', line 17 def logger JetstreamBridge.config.logger || (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) || default_logger end |
.sanitize_url(url) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/jetstream_bridge/core/logging.rb', line 69 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) ⇒ void
This method returns an undefined value.
58 59 60 |
# File 'lib/jetstream_bridge/core/logging.rb', line 58 def warn(msg, tag: nil) log(:warn, msg, tag: tag) end |