Skip to content

Instantly share code, notes, and snippets.

@bettse
Created March 5, 2026 04:16
Show Gist options
  • Select an option

  • Save bettse/0a456b7a0d791fcde49afd436694d7e7 to your computer and use it in GitHub Desktop.

Select an option

Save bettse/0a456b7a0d791fcde49afd436694d7e7 to your computer and use it in GitHub Desktop.
class Logger < ::ActiveSupport::Logger
def with_field(key, value)
Thread.current['lograge.data'] ||= {}
Thread.current['lograge.data'][key] = value
return self
end
def with_fields(hash)
if hash.is_a?(Hash)
Thread.current['lograge.data'] ||= {}
Thread.current['lograge.data'].merge!(hash)
end
return self
end
def with_local_fields(hash)
if hash.is_a?(Hash)
Thread.current[LOCAL_LOG_FIELDS] ||= {}
Thread.current[LOCAL_LOG_FIELDS].merge!(hash)
end
yield(self) if block_given?
return self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment