Skip to content

Commit

Permalink
Updated to ruby 2.4+. Updated travis credentials. Added bundle audit.…
Browse files Browse the repository at this point in the history
… Updated gem versions. Fixed rubocop violations.
  • Loading branch information
Joe Ebmeier committed Nov 14, 2018
1 parent e93ec6f commit 9e32136
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 81 deletions.
2 changes: 0 additions & 2 deletions .hound.yml

This file was deleted.

17 changes: 10 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
inherit_from: #{RUBOCOP_HOME}/config/default.yml

AllCops:
Include:
- '**/lib/**/*'
TargetRubyVersion: 2.4
Exclude:
- 'bin/**/*'
- '**/Guardfile'
- '**/Gemfile'
- '**/Rakefile'
- 'vendor/**/*'
- 'Guardfile'

CyclomaticComplexity:
Max: 15
Expand Down Expand Up @@ -59,6 +56,12 @@ Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

Style/BlockLength:
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

Style/FrozenStringLiteralComment:
Enabled: false

Style/AccessModifierDeclarations:
EnforcedStyle: inline
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4
17 changes: 6 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
language: ruby
cache: bundler
rvm:
- 2.4.0
- 2.3.3
- 2.2.6
- 2.2.2
rvm: 2.4
script:
- bundle exec rspec
- bundle exec rubocop lib spec
- bundle exec bundle-audit update && bundle exec bundle-audit check
- bundle exec rspec
- bundle exec rubocop lib spec
deploy:
- provider: releases
api_key:
secure: Ob2+ZdkM5msawA9FnJ8hk7wLgUP9tJg+gOIs1VOpOzq7cqHUmbK2tGwJPSWX+yzFA5A9o520SLJB0MAfnO78DjByRenH1e8keg0uxZ17ci8FDWEPhF53cCjuTLhsaC9qxVcbNps4Z8pg5lQ/0IPaef0lVX0u2jPEHagNBmfJdYLthUPH/M/AcoVT/chj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YVzNkBCtRftVy5zYCEPd8MCXxF40S3uv4ta30wQKhdZPWELf4GkzKxCpdbbryWQKoF6ZKceD+LIG18qVlO5AqU=
file_glob: true
file: hedgelog-*.gem
on:
tags: true
rvm: 2.2.2
repo: firespring/hedgelog
- provider: rubygems
api_key:
secure: 0lJg8R4FfcC/V0CQP1+MtvaOTHumMczV6W5wNvW+S4C9A+EhWgNdZDZ1tPbLQDRm4rBhr15k6KpZUmR1hMiu2xpN/O9wpdLqrhFccnP8+3qSYWi4Mqns/lFLQtVwlfQeSjQPejHeel7wEDAo/iFs9lgVzyXtusAgIZ8qQLJIa2T8cLE5Kdh/xfJTfdYCojJkw+5XoxARFmiXz5dIBb+1jiYmAULgRQpNUifz+IspAUxDf8BXjZFi7TZeKf34kOnVRUXLdjFOkTIXSx7F1NlSCFUmQtjf1Ft1PfJUwZ+eh5B0u5AL7JMA3pA9T6WNpqJpedVCD5KvkqKeILYFkYriro7K41MCPXBM4CAXSgpqnwiGCR64eBm85nGaRbYIZ+8AdGKxd1wS+fVkpOv4PxDADDD+qPIVTpuTeIJ2+hZYpHdsD5bYtqhvqdUkVOdilnBZKFYHVwHZvkObOoGyk0g3PzwYOUSnG3BJ3YhinTzNuXkOBhUdGN/eZna314hPLVGySTlmpnnof2lWQFArJXTcJXVQBdkSdlML7vvv4QjttOBNX6ICzOimFDrTDIlf3hkrf3+bGva3v0tBn3cz4bLOZgdvWrhhJ+p6TzPCGoseKUE2e+zvBAsPEzjYI9G+hKkSbtT0rFZ6O/Cr21dL/Mbf2WMz0NfhmTc4J3kdP2Y98Ow=
secure: anM34Z3fd3H5xt46pVbOmC0FnPsD0Pro9+Vmdv4fq22GvjFolexCtNFt8fb8V+M9THvw1qZDvSyHTZ0NKUDMqaVLX+VhDvquhuM0vviAECBu7kqqZ/pBjBJduYrtcFrCpoL3vs3AhXM882XKIhw4YMtOgoh00DpLZYQbtdEVvCZhbIe80N2eRSM1taVNQQwkI7pREBBFliBrjpP82Vfacue7m/iDKg/k1SRv1jXafQLDM0k8UAdYntc/popqTpXCbmxOcPVv6yVghijld6rTirLeRSrbwq1m0Djg24r/BGd8NsFn9Xtvtm8oZN3Xv2Q8AoJFeDCymTndUtJYrFaS8IQe5TLzXLYW+/BjedCuA09bfcRjW7vjuO73yYqf/K+dTbwbuJMpUJt6Mymu66MuPi6ntj00hvDBU9ekHFkZlemUixq3LxvmEPyxK8PKTLVH9UipkTBG0cXWct5fCXhv0KvrxFLeZM2XXqvknnuYGSIE5fvGLHvn2OuX5JESJzwDt8xBNXrPmCIcDX/DOONR+AuPYQkDLybM75/P+vnxSfT6ZMFj7AxZAr23mWOQ1dK+dgvJb+nbBa+5KRCPs9n9M4aW5ybNKgy8v8Mgp6ebTuRLYDUdOB2aMXRy6/0dqSMR+fe0B7HtHXNtp73Nidox6QBFQzmtXg8fzsXA9yFKFZI=
gem: hedgelog
on:
tags: true
rvm: 2.2.2
repo: firespring/hedgelog
15 changes: 8 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ source 'https://rubygems.org'
gemspec

group :test, :development do
gem "rake", "~> 10.0"
gem "rspec", "~> 3.3"
gem "pry"
gem "simplecov", "~> 0.10"
gem "rubocop", "~> 0.51"
gem "timecop"
gem 'benchmark-ips'
gem 'bundler-audit'
gem 'pry'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'simplecov'
gem 'timecop'
end

group :development do
gem 'ruby-prof'
gem 'guard-rspec', require: false
gem 'listen', '~> 3.0.6'
gem 'ruby-prof'
end
18 changes: 9 additions & 9 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec --format progress" do
require "guard/rspec/dsl"
guard :rspec, cmd: 'bundle exec rspec --format progress' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements
Expand All @@ -41,15 +41,15 @@ guard :rspec, cmd: "bundle exec rspec --format progress" do
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
rails = dsl.rails(view_extensions: %w[erb haml slim])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end

Expand All @@ -59,12 +59,12 @@ guard :rspec, cmd: "bundle exec rspec --format progress" do
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
end
end
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Hedgelog
[![Gem Version](https://badge.fury.io/rb/hedgelog.svg)](http://badge.fury.io/rb/hedgelog)
[![Build Status](https://travis-ci.org/firespring/hedgelog.svg?branch=master)](https://travis-ci.org/firespring/hedgelog)
[![Dependency Status](https://gemnasium.com/firespring/hedgelog.svg)](https://gemnasium.com/firespring/hedgelog)
[![Code Climate](https://codeclimate.com/github/firespring/hedgelog/badges/gpa.svg)](https://codeclimate.com/github/firespring/hedgelog)

This gem provides an opinionated Ruby logger for writing structured JSON logs. It attempts to maintain compatibility with the standard Ruby logger api while extending it with functionality relevant to JSON logging.

Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "hedgelog"
require 'bundler/setup'
require 'hedgelog'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "pry"
require 'pry'
Pry.start
7 changes: 3 additions & 4 deletions bin/profile
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "hedgelog"
require 'bundler/setup'
require 'hedgelog'
require 'ruby-prof'
require 'logger'

logger = Hedgelog.new('/dev/null')
logger.level = Logger::INFO

RubyProf.start
10000.times do
10_000.times do
logger.info 'Foo'
end
result = RubyProf.stop
result.eliminate_methods!([/Integer#times/])


# printer = RubyProf::GraphPrinter.new(result)
printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
printer.print(STDOUT)
10 changes: 4 additions & 6 deletions hedgelog.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'hedgelog/version'

Expand All @@ -9,17 +8,16 @@ Gem::Specification.new do |spec|
spec.licenses = ['MIT']
spec.authors = ['Jeff Utter']
spec.email = ['jeff.utter@firespring.com']
spec.homepage = 'https://github.com/firespring/hedgelog'

spec.summary = 'An opinionated/strucutred JSON logger for Ruby'
spec.homepage = 'https://github.com/firespring/hedgelog'
spec.summary = 'A strucutred JSON logger for Ruby'
spec.description = 'An opinionated/structured JSON logger for Ruby'
spec.homepage = 'http://firespring.com'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'yajl-ruby', '~> 1.2'
spec.add_dependency 'yajl-ruby', '~> 1.4'
spec.add_development_dependency 'bundler', '~> 1.7'
end
26 changes: 14 additions & 12 deletions lib/hedgelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Hedgelog
TOP_LEVEL_KEYS = %i[app channel level level_name message request_id timestamp].freeze
RESERVED_KEYS = %i[app level level_name timestamp context caller].freeze

TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%6N%z'.freeze
BACKTRACE_RE = /([^:]+):([0-9]+)(?::in `(.*)')?/
TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%6N%z'
BACKTRACE_RE = Regexp.new("([^:]+):([0-9]+)(?::in `(.*)')?")

attr_reader :level
attr_writer :app
Expand All @@ -44,6 +44,7 @@ def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil)
def level=(level)
int_level = level_to_int(level)
raise ::ArgumentError, "#{self.class}#level= , #{level} is not a valid level." if int_level.nil?

@level = int_level
end

Expand All @@ -59,7 +60,7 @@ def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}

return write(severity, context) if @logdev

@channel.add(severity, nil, progname, context) if @channel
@channel&.add(severity, nil, progname, context)
end

def []=(key, val)
Expand Down Expand Up @@ -119,23 +120,23 @@ def formatter
::Logger::Formatter.new
end

def formatter=(_)
def formatter=(_value)
formatter
end

private

def level_to_int(level)
private def level_to_int(level)
return level if level.is_a?(Integer)

LEVELS[level]
end

def level_from_int(level)
private def level_from_int(level)
return LEVELS[level] if level.is_a?(Integer)

level.to_sym
end

def write(severity, context)
private def write(severity, context)
return true if @logdev.nil?

context.normalize!
Expand All @@ -150,15 +151,15 @@ def write(severity, context)
true
end

def default_data(severity)
private def default_data(severity)
{
timestamp: Time.now.strftime(TIMESTAMP_FORMAT),
level_name: level_from_int(severity),
level: severity
}
end

def extract_top_level_keys(context)
private def extract_top_level_keys(context)
data = {}
TOP_LEVEL_KEYS.each do |key|
data[key] = context.delete(key) if context.key? key
Expand All @@ -167,9 +168,10 @@ def extract_top_level_keys(context)
data
end

def debugharder(callinfo)
private def debugharder(callinfo)
m = BACKTRACE_RE.match(callinfo)
return unless m

path, line, method = m[1..3]
whence = $LOAD_PATH.find { |p| path.start_with?(p) }
file = if whence
Expand Down
5 changes: 2 additions & 3 deletions lib/hedgelog/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Hedgelog
class Context
def initialize(scrubber, normalizer, data = {})
raise ::ArgumentError, "#{self.class}: argument must be Hash got #{data.class}." unless data.is_a? Hash

check_reserved_keys(data)
@data = data
@scrubber = scrubber
Expand Down Expand Up @@ -61,9 +62,7 @@ def to_h
@data
end

private

def check_reserved_keys(hash)
private def check_reserved_keys(hash)
invalid_keys = Hedgelog::RESERVED_KEYS & hash.keys
raise ::ArgumentError, "#{self.class}: The following keys are reserved and cannot be used #{invalid_keys.to_a}." unless invalid_keys.empty?
end
Expand Down
7 changes: 3 additions & 4 deletions lib/hedgelog/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def normalize(data)
d = Marshal.load(Marshal.dump(data))
normalize_hash(d)
end
# rubocop:enable Security/MarshalLoad

def normalize_struct(struct)
normalize_hash(Hash[struct.each_pair.to_a])
Expand All @@ -21,14 +20,14 @@ def normalize_array(array)
array.to_json
end

private

def normalize_thing(thing)
private def normalize_thing(thing)
return '' if thing.nil?

thing = thing.as_json if thing.respond_to?(:as_json)
return normalize_struct(thing) if thing.is_a?(Struct)
return normalize_array(thing) if thing.is_a?(Array)
return normalize_hash(thing) if thing.is_a?(Hash)

thing
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/hedgelog/scrub_replacement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def scrub_string(string)
def scrub_hash(hash)
hash.each do |key, val|
next hash[key] = @replacement if key.to_s.casecmp(@key.to_s).zero?

scrub_thing(val)
end
end
Expand All @@ -28,9 +29,7 @@ def scrub_array(array)
end
end

private

def scrub_thing(thing)
private def scrub_thing(thing)
scrub_string(thing) if thing.is_a?(String)
scrub_array(thing) if thing.is_a?(Array)
scrub_hash(thing) if thing.is_a?(Hash)
Expand Down
1 change: 0 additions & 1 deletion lib/hedgelog/scrubber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ def scrub(data)
end
d
end
# rubocop:enable Security/MarshalLoad
end
end
2 changes: 1 addition & 1 deletion lib/hedgelog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Hedgelog
VERSION = '0.1.10'.freeze
VERSION = '0.1.11'
end
Loading

0 comments on commit 9e32136

Please sign in to comment.