From dde2eefd64b58da4220f6187040bcb789dcc69b0 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 16:10:04 -0400 Subject: [PATCH 01/32] Copy over nitro_logging --- packages/nitro_logging/.gitignore | 13 ++ packages/nitro_logging/.rubocop.yml | 4 + packages/nitro_logging/.rubocop_todo.yml | 20 +++ packages/nitro_logging/Gemfile | 14 ++ packages/nitro_logging/Gemfile.lock | 136 ++++++++++++++++++ packages/nitro_logging/Rakefile | 8 ++ packages/nitro_logging/bin/build | 8 ++ packages/nitro_logging/bin/clean | 5 + packages/nitro_logging/bin/console | 14 ++ packages/nitro_logging/bin/deps | 10 ++ packages/nitro_logging/bin/doc | 11 ++ packages/nitro_logging/bin/rake | 29 ++++ packages/nitro_logging/bin/rspec | 29 ++++ packages/nitro_logging/bin/rubocop | 29 ++++ packages/nitro_logging/bin/schema | 5 + packages/nitro_logging/bin/setup | 6 + packages/nitro_logging/bin/test | 11 ++ packages/nitro_logging/bin/yard | 29 ++++ packages/nitro_logging/bin/yardoc | 29 ++++ packages/nitro_logging/bin/yri | 29 ++++ packages/nitro_logging/docs/README.md | 3 + packages/nitro_logging/lib/nitro_logging.rb | 9 ++ .../lib/nitro_logging/log_chooser.rb | 52 +++++++ .../lib/nitro_logging/railtie.rb | 9 ++ packages/nitro_logging/mkdocs.yml | 5 + packages/nitro_logging/nitro_logging.gemspec | 35 +++++ packages/nitro_logging/portal.yml | 15 ++ packages/nitro_logging/spec/spec_helper.rb | 58 ++++++++ packages/nitro_logging/test.sh | 8 ++ 29 files changed, 633 insertions(+) create mode 100644 packages/nitro_logging/.gitignore create mode 100644 packages/nitro_logging/.rubocop.yml create mode 100644 packages/nitro_logging/.rubocop_todo.yml create mode 100644 packages/nitro_logging/Gemfile create mode 100644 packages/nitro_logging/Gemfile.lock create mode 100644 packages/nitro_logging/Rakefile create mode 100755 packages/nitro_logging/bin/build create mode 100755 packages/nitro_logging/bin/clean create mode 100755 packages/nitro_logging/bin/console create mode 100755 packages/nitro_logging/bin/deps create mode 100755 packages/nitro_logging/bin/doc create mode 100755 packages/nitro_logging/bin/rake create mode 100755 packages/nitro_logging/bin/rspec create mode 100755 packages/nitro_logging/bin/rubocop create mode 100755 packages/nitro_logging/bin/schema create mode 100755 packages/nitro_logging/bin/setup create mode 100755 packages/nitro_logging/bin/test create mode 100755 packages/nitro_logging/bin/yard create mode 100755 packages/nitro_logging/bin/yardoc create mode 100755 packages/nitro_logging/bin/yri create mode 100644 packages/nitro_logging/docs/README.md create mode 100644 packages/nitro_logging/lib/nitro_logging.rb create mode 100644 packages/nitro_logging/lib/nitro_logging/log_chooser.rb create mode 100644 packages/nitro_logging/lib/nitro_logging/railtie.rb create mode 100644 packages/nitro_logging/mkdocs.yml create mode 100644 packages/nitro_logging/nitro_logging.gemspec create mode 100644 packages/nitro_logging/portal.yml create mode 100644 packages/nitro_logging/spec/spec_helper.rb create mode 100755 packages/nitro_logging/test.sh diff --git a/packages/nitro_logging/.gitignore b/packages/nitro_logging/.gitignore new file mode 100644 index 00000000..cb2fc2fa --- /dev/null +++ b/packages/nitro_logging/.gitignore @@ -0,0 +1,13 @@ +/.bundle/ +/.yardoc +/_yardoc/ +coverage +/doc +pkg +/spec/reports/ +**/tmp/* +!**/tmp/.gitkeep +!tmp/.gitignore +vendor/bundle +*.log +*.sqlite3 diff --git a/packages/nitro_logging/.rubocop.yml b/packages/nitro_logging/.rubocop.yml new file mode 100644 index 00000000..41d54493 --- /dev/null +++ b/packages/nitro_logging/.rubocop.yml @@ -0,0 +1,4 @@ +inherit_from: .rubocop_todo.yml + +inherit_gem: + nitro_linting: .rubocop_standard.yml diff --git a/packages/nitro_logging/.rubocop_todo.yml b/packages/nitro_logging/.rubocop_todo.yml new file mode 100644 index 00000000..5b14e966 --- /dev/null +++ b/packages/nitro_logging/.rubocop_todo.yml @@ -0,0 +1,20 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 500` +# on 2021-10-25 18:39:47 UTC using RuboCop version 1.20.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +Style/GlobalStdStream: + Exclude: + - 'lib/nitro_logging/log_chooser.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/nitro_logging/log_chooser.rb' diff --git a/packages/nitro_logging/Gemfile b/packages/nitro_logging/Gemfile new file mode 100644 index 00000000..76732229 --- /dev/null +++ b/packages/nitro_logging/Gemfile @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +source "https://rubygems.org" +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end + +gemspec + +path ".." do + # Dependencies on other components go here + gem "nitro_linting", require: nil +end diff --git a/packages/nitro_logging/Gemfile.lock b/packages/nitro_logging/Gemfile.lock new file mode 100644 index 00000000..18739f1e --- /dev/null +++ b/packages/nitro_logging/Gemfile.lock @@ -0,0 +1,136 @@ +PATH + remote: .. + specs: + nitro_linting (0.0.1) + rubocop (= 1.20.0) + rubocop-cobra (>= 0.4.0) + rubocop-performance (= 1.11.5) + rubocop-powerhome (>= 0.5.0) + rubocop-rails (= 2.12.2) + rubocop-rake (= 0.6.0) + rubocop-rspec (= 2.4.0) + +PATH + remote: . + specs: + nitro_logging (0.0.1) + activesupport (= 5.2.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (5.2.8.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + ast (2.4.2) + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.10) + diff-lcs (1.5.0) + docile (1.1.5) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + json (2.5.1) + method_source (1.0.0) + minitest (5.16.2) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) + power_assert (2.0.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + rack (2.2.4) + rainbow (2.2.2) + rake + rake (13.0.6) + regexp_parser (2.5.0) + rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.2) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.3) + rubocop (1.20.0) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.9.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.19.1) + parser (>= 3.1.1.0) + rubocop-cobra (0.4.0) + rubocop + rubocop-powerhome + rubocop-performance (1.11.5) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-powerhome (0.5.0) + rubocop + rubocop-performance + rubocop-rails + rubocop-rake + rubocop-rspec + rubocop-rails (2.12.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.4.0) + rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) + ruby-progressbar (1.11.0) + simplecov (0.15.1) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + test-unit (3.1.5) + power_assert + thread_safe (0.3.6) + tzinfo (1.2.10) + thread_safe (~> 0.1) + unicode-display_width (2.2.0) + yard (0.9.21) + +PLATFORMS + arm64-darwin-20 + arm64-darwin-21 + ruby + x86_64-darwin-19 + x86_64-darwin-20 + x86_64-darwin-21 + x86_64-linux + +DEPENDENCIES + bundler (~> 2.1) + nitro_linting! + nitro_logging! + parser (>= 2.5, != 2.5.1.1) + pry-byebug (= 3.9.0) + rainbow (= 2.2.2) + rake (~> 13.0) + rspec (~> 3.0) + simplecov (= 0.15.1) + test-unit (= 3.1.5) + yard (= 0.9.21) + +BUNDLED WITH + 2.3.14 diff --git a/packages/nitro_logging/Rakefile b/packages/nitro_logging/Rakefile new file mode 100644 index 00000000..b6ae7341 --- /dev/null +++ b/packages/nitro_logging/Rakefile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/packages/nitro_logging/bin/build b/packages/nitro_logging/bin/build new file mode 100755 index 00000000..0fc1fd43 --- /dev/null +++ b/packages/nitro_logging/bin/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +# Build + +echo ">>> Building" +time bin/rubocop --display-cop-names --extra-details --parallel --display-style-guide --config .rubocop.yml diff --git a/packages/nitro_logging/bin/clean b/packages/nitro_logging/bin/clean new file mode 100755 index 00000000..c4b7887d --- /dev/null +++ b/packages/nitro_logging/bin/clean @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +echo "This component doesn't have a database" diff --git a/packages/nitro_logging/bin/console b/packages/nitro_logging/bin/console new file mode 100755 index 00000000..ada06dc9 --- /dev/null +++ b/packages/nitro_logging/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "nitro_logging" + +# 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. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/packages/nitro_logging/bin/deps b/packages/nitro_logging/bin/deps new file mode 100755 index 00000000..b7e2137b --- /dev/null +++ b/packages/nitro_logging/bin/deps @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +echo ">>> Installing dependencies" +if [ -z $CI ] ; then + time bundle check || bundle install --quiet +else + time bundle check || bundle install +fi diff --git a/packages/nitro_logging/bin/doc b/packages/nitro_logging/bin/doc new file mode 100755 index 00000000..b68f2b30 --- /dev/null +++ b/packages/nitro_logging/bin/doc @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +echo ">>> Documenting" +OUTPUT="$(time bin/yard)" +echo "${OUTPUT}" +if [ "$(echo ${OUTPUT} | grep warn | wc -l)" -gt 0 ]; then + echo "Documentation warnings occurred" + exit 1 +fi diff --git a/packages/nitro_logging/bin/rake b/packages/nitro_logging/bin/rake new file mode 100755 index 00000000..9275675e --- /dev/null +++ b/packages/nitro_logging/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/packages/nitro_logging/bin/rspec b/packages/nitro_logging/bin/rspec new file mode 100755 index 00000000..a6c78521 --- /dev/null +++ b/packages/nitro_logging/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/packages/nitro_logging/bin/rubocop b/packages/nitro_logging/bin/rubocop new file mode 100755 index 00000000..d0c48829 --- /dev/null +++ b/packages/nitro_logging/bin/rubocop @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/packages/nitro_logging/bin/schema b/packages/nitro_logging/bin/schema new file mode 100755 index 00000000..c4b7887d --- /dev/null +++ b/packages/nitro_logging/bin/schema @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +echo "This component doesn't have a database" diff --git a/packages/nitro_logging/bin/setup b/packages/nitro_logging/bin/setup new file mode 100755 index 00000000..d222cb3f --- /dev/null +++ b/packages/nitro_logging/bin/setup @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +bin/deps +bin/schema diff --git a/packages/nitro_logging/bin/test b/packages/nitro_logging/bin/test new file mode 100755 index 00000000..4ae124e2 --- /dev/null +++ b/packages/nitro_logging/bin/test @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +# Test + +echo ">>> Testing" +trap "kill -TERM $PID" TERM +time bin/rspec --format progress --format html --out ./tmp/spec_results/index.html --profile 100 spec & +PID=$! +wait $PID diff --git a/packages/nitro_logging/bin/yard b/packages/nitro_logging/bin/yard new file mode 100755 index 00000000..0ed81a10 --- /dev/null +++ b/packages/nitro_logging/bin/yard @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yard' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("yard", "yard") diff --git a/packages/nitro_logging/bin/yardoc b/packages/nitro_logging/bin/yardoc new file mode 100755 index 00000000..b0979f72 --- /dev/null +++ b/packages/nitro_logging/bin/yardoc @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yardoc' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("yard", "yardoc") diff --git a/packages/nitro_logging/bin/yri b/packages/nitro_logging/bin/yri new file mode 100755 index 00000000..0a772f98 --- /dev/null +++ b/packages/nitro_logging/bin/yri @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yri' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("yard", "yri") diff --git a/packages/nitro_logging/docs/README.md b/packages/nitro_logging/docs/README.md new file mode 100644 index 00000000..e63a1e39 --- /dev/null +++ b/packages/nitro_logging/docs/README.md @@ -0,0 +1,3 @@ +# NitroLogging + +Nitro Logging handles logging output formatting. diff --git a/packages/nitro_logging/lib/nitro_logging.rb b/packages/nitro_logging/lib/nitro_logging.rb new file mode 100644 index 00000000..caf9173b --- /dev/null +++ b/packages/nitro_logging/lib/nitro_logging.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "logger" +require "active_support" +require "nitro_logging/railtie" if defined?(Rails) +require "nitro_logging/log_chooser" + +module NitroLogging +end diff --git a/packages/nitro_logging/lib/nitro_logging/log_chooser.rb b/packages/nitro_logging/lib/nitro_logging/log_chooser.rb new file mode 100644 index 00000000..994bff63 --- /dev/null +++ b/packages/nitro_logging/lib/nitro_logging/log_chooser.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require "active_support/tagged_logging" + +module NitroLogging + class LogChooser + cattr_accessor :log_level + + def self.logger(progname:) + logger = Logger.new(primary_logdev, progname: progname) + logger.level = log_level + logger.formatter = JSONFormatter.new if structured_logging? + logger + end + + # Standard practice for applications running in Docker containers + # is to send their logging output to STDOUT instead of various + # logfiles on disk. + def self.primary_logdev + STDOUT + end + + def self.structured_logging? + ENV.key?("STRUCTURED_LOGGING") + end + end + + class JSONFormatter < ::Logger::Formatter + include ActiveSupport::TaggedLogging::Formatter + + def call(severity, time, progname, data) + data = { message: data.to_s } unless data.is_a?(Hash) + + data.merge!(current_tags.each_with_object({}) do |tag, hash| + if tag.include?("=") + key, value = tag.split("=") + hash[key] = value + else + hash[:tags] ||= [] + hash[:tags] << key + end + hash + end) + + { + level: severity, + time: time, + progname: progname, + }.merge(data).to_json + "\r\n" + end + end +end diff --git a/packages/nitro_logging/lib/nitro_logging/railtie.rb b/packages/nitro_logging/lib/nitro_logging/railtie.rb new file mode 100644 index 00000000..84c90821 --- /dev/null +++ b/packages/nitro_logging/lib/nitro_logging/railtie.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module NitroLogging + class Railtie < Rails::Railtie + initializer "nitro_logging.configurations" do + NitroLogging::LogChooser.log_level = Rails.application.config.log_level + end + end +end diff --git a/packages/nitro_logging/mkdocs.yml b/packages/nitro_logging/mkdocs.yml new file mode 100644 index 00000000..5d0ccb2d --- /dev/null +++ b/packages/nitro_logging/mkdocs.yml @@ -0,0 +1,5 @@ +site_name: Nitro Logging +nav: + - "Home": "README.md" +plugins: + - techdocs-core diff --git a/packages/nitro_logging/nitro_logging.gemspec b/packages/nitro_logging/nitro_logging.gemspec new file mode 100644 index 00000000..b06f4357 --- /dev/null +++ b/packages/nitro_logging/nitro_logging.gemspec @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +$LOAD_PATH.push File.expand_path("lib", __dir__) + +Gem::Specification.new do |s| + s.name = "nitro_logging" + s.version = "0.0.1" + s.authors = ["Nitro Developers"] + s.email = ["dev@powerhrg.com"] + s.homepage = "http://nitro.powerhrg.com" + s.summary = "SomeSummary" + s.description = "SomeLongerDescription" + + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host" + # to allow pushing to a single host or delete this section to allow pushing to any host. + raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless s.respond_to?(:metadata) + + s.metadata["allowed_push_host"] = "http://rubygems.powerhrg.com" + s.license = "LicenseRef-NitroComponent" + + s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] + + s.add_dependency "activesupport", "5.2.8.1" + + s.add_development_dependency "bundler", "~> 2.1" + s.add_development_dependency "nitro_linting", "0.0.1" + s.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" + s.add_development_dependency "pry-byebug", "3.9.0" + s.add_development_dependency "rainbow", "2.2.2" + s.add_development_dependency "rake", "~> 13.0" + s.add_development_dependency "rspec", "~> 3.0" + s.add_development_dependency "simplecov", "0.15.1" + s.add_development_dependency "test-unit", "3.1.5" + s.add_development_dependency "yard", "0.9.21" +end diff --git a/packages/nitro_logging/portal.yml b/packages/nitro_logging/portal.yml new file mode 100644 index 00000000..643831dc --- /dev/null +++ b/packages/nitro_logging/portal.yml @@ -0,0 +1,15 @@ +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: nitro-logging + title: Nitro Logging + description: Handles logging output formatting +spec: + type: library + owner: heroes-for-hire + system: nitro + lifecycle: production + subcomponentOf: nitro-web + dependsOn: + - component:nitro-linting diff --git a/packages/nitro_logging/spec/spec_helper.rb b/packages/nitro_logging/spec/spec_helper.rb new file mode 100644 index 00000000..9271767a --- /dev/null +++ b/packages/nitro_logging/spec/spec_helper.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +require "nitro_logging" + +require "pry-byebug" + +RSpec.configure do |config| + if ENV["CI"] + config.before(:example, :focus) { raise "Should not commit focused specs" } + else + config.filter_run :focus + config.run_all_when_everything_filtered = true + end + config.warnings = false + + config.default_formatter = "doc" if config.files_to_run.one? + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + expectations.syntax = :expect + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + mocks.syntax = :expect + + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended. + mocks.verify_partial_doubles = false + end +end diff --git a/packages/nitro_logging/test.sh b/packages/nitro_logging/test.sh new file mode 100755 index 00000000..68be8870 --- /dev/null +++ b/packages/nitro_logging/test.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +bin/setup +bin/build +bin/doc +bin/test From 4efde8f6e6b45cab43c36a78c303b8a565e3c4c4 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 16:22:13 -0400 Subject: [PATCH 02/32] Rename all files to lumberaxe --- packages/{nitro_logging => lumberaxe}/.gitignore | 0 packages/{nitro_logging => lumberaxe}/.rubocop.yml | 0 packages/{nitro_logging => lumberaxe}/.rubocop_todo.yml | 0 packages/{nitro_logging => lumberaxe}/Gemfile | 0 packages/{nitro_logging => lumberaxe}/Gemfile.lock | 0 packages/{nitro_logging => lumberaxe}/Rakefile | 0 packages/{nitro_logging => lumberaxe}/bin/build | 0 packages/{nitro_logging => lumberaxe}/bin/clean | 0 packages/{nitro_logging => lumberaxe}/bin/console | 0 packages/{nitro_logging => lumberaxe}/bin/deps | 0 packages/{nitro_logging => lumberaxe}/bin/doc | 0 packages/{nitro_logging => lumberaxe}/bin/rake | 0 packages/{nitro_logging => lumberaxe}/bin/rspec | 0 packages/{nitro_logging => lumberaxe}/bin/rubocop | 0 packages/{nitro_logging => lumberaxe}/bin/schema | 0 packages/{nitro_logging => lumberaxe}/bin/setup | 0 packages/{nitro_logging => lumberaxe}/bin/test | 0 packages/{nitro_logging => lumberaxe}/bin/yard | 0 packages/{nitro_logging => lumberaxe}/bin/yardoc | 0 packages/{nitro_logging => lumberaxe}/bin/yri | 0 packages/{nitro_logging => lumberaxe}/docs/README.md | 0 .../lib/nitro_logging.rb => lumberaxe/lib/lumberaxe.rb} | 0 .../lib/nitro_logging => lumberaxe/lib/lumberaxe}/log_chooser.rb | 0 .../lib/nitro_logging => lumberaxe/lib/lumberaxe}/railtie.rb | 0 .../nitro_logging.gemspec => lumberaxe/lumberaxe.gemspec} | 0 packages/{nitro_logging => lumberaxe}/mkdocs.yml | 0 packages/{nitro_logging => lumberaxe}/portal.yml | 0 packages/{nitro_logging => lumberaxe}/spec/spec_helper.rb | 0 packages/{nitro_logging => lumberaxe}/test.sh | 0 29 files changed, 0 insertions(+), 0 deletions(-) rename packages/{nitro_logging => lumberaxe}/.gitignore (100%) rename packages/{nitro_logging => lumberaxe}/.rubocop.yml (100%) rename packages/{nitro_logging => lumberaxe}/.rubocop_todo.yml (100%) rename packages/{nitro_logging => lumberaxe}/Gemfile (100%) rename packages/{nitro_logging => lumberaxe}/Gemfile.lock (100%) rename packages/{nitro_logging => lumberaxe}/Rakefile (100%) rename packages/{nitro_logging => lumberaxe}/bin/build (100%) rename packages/{nitro_logging => lumberaxe}/bin/clean (100%) rename packages/{nitro_logging => lumberaxe}/bin/console (100%) rename packages/{nitro_logging => lumberaxe}/bin/deps (100%) rename packages/{nitro_logging => lumberaxe}/bin/doc (100%) rename packages/{nitro_logging => lumberaxe}/bin/rake (100%) rename packages/{nitro_logging => lumberaxe}/bin/rspec (100%) rename packages/{nitro_logging => lumberaxe}/bin/rubocop (100%) rename packages/{nitro_logging => lumberaxe}/bin/schema (100%) rename packages/{nitro_logging => lumberaxe}/bin/setup (100%) rename packages/{nitro_logging => lumberaxe}/bin/test (100%) rename packages/{nitro_logging => lumberaxe}/bin/yard (100%) rename packages/{nitro_logging => lumberaxe}/bin/yardoc (100%) rename packages/{nitro_logging => lumberaxe}/bin/yri (100%) rename packages/{nitro_logging => lumberaxe}/docs/README.md (100%) rename packages/{nitro_logging/lib/nitro_logging.rb => lumberaxe/lib/lumberaxe.rb} (100%) rename packages/{nitro_logging/lib/nitro_logging => lumberaxe/lib/lumberaxe}/log_chooser.rb (100%) rename packages/{nitro_logging/lib/nitro_logging => lumberaxe/lib/lumberaxe}/railtie.rb (100%) rename packages/{nitro_logging/nitro_logging.gemspec => lumberaxe/lumberaxe.gemspec} (100%) rename packages/{nitro_logging => lumberaxe}/mkdocs.yml (100%) rename packages/{nitro_logging => lumberaxe}/portal.yml (100%) rename packages/{nitro_logging => lumberaxe}/spec/spec_helper.rb (100%) rename packages/{nitro_logging => lumberaxe}/test.sh (100%) diff --git a/packages/nitro_logging/.gitignore b/packages/lumberaxe/.gitignore similarity index 100% rename from packages/nitro_logging/.gitignore rename to packages/lumberaxe/.gitignore diff --git a/packages/nitro_logging/.rubocop.yml b/packages/lumberaxe/.rubocop.yml similarity index 100% rename from packages/nitro_logging/.rubocop.yml rename to packages/lumberaxe/.rubocop.yml diff --git a/packages/nitro_logging/.rubocop_todo.yml b/packages/lumberaxe/.rubocop_todo.yml similarity index 100% rename from packages/nitro_logging/.rubocop_todo.yml rename to packages/lumberaxe/.rubocop_todo.yml diff --git a/packages/nitro_logging/Gemfile b/packages/lumberaxe/Gemfile similarity index 100% rename from packages/nitro_logging/Gemfile rename to packages/lumberaxe/Gemfile diff --git a/packages/nitro_logging/Gemfile.lock b/packages/lumberaxe/Gemfile.lock similarity index 100% rename from packages/nitro_logging/Gemfile.lock rename to packages/lumberaxe/Gemfile.lock diff --git a/packages/nitro_logging/Rakefile b/packages/lumberaxe/Rakefile similarity index 100% rename from packages/nitro_logging/Rakefile rename to packages/lumberaxe/Rakefile diff --git a/packages/nitro_logging/bin/build b/packages/lumberaxe/bin/build similarity index 100% rename from packages/nitro_logging/bin/build rename to packages/lumberaxe/bin/build diff --git a/packages/nitro_logging/bin/clean b/packages/lumberaxe/bin/clean similarity index 100% rename from packages/nitro_logging/bin/clean rename to packages/lumberaxe/bin/clean diff --git a/packages/nitro_logging/bin/console b/packages/lumberaxe/bin/console similarity index 100% rename from packages/nitro_logging/bin/console rename to packages/lumberaxe/bin/console diff --git a/packages/nitro_logging/bin/deps b/packages/lumberaxe/bin/deps similarity index 100% rename from packages/nitro_logging/bin/deps rename to packages/lumberaxe/bin/deps diff --git a/packages/nitro_logging/bin/doc b/packages/lumberaxe/bin/doc similarity index 100% rename from packages/nitro_logging/bin/doc rename to packages/lumberaxe/bin/doc diff --git a/packages/nitro_logging/bin/rake b/packages/lumberaxe/bin/rake similarity index 100% rename from packages/nitro_logging/bin/rake rename to packages/lumberaxe/bin/rake diff --git a/packages/nitro_logging/bin/rspec b/packages/lumberaxe/bin/rspec similarity index 100% rename from packages/nitro_logging/bin/rspec rename to packages/lumberaxe/bin/rspec diff --git a/packages/nitro_logging/bin/rubocop b/packages/lumberaxe/bin/rubocop similarity index 100% rename from packages/nitro_logging/bin/rubocop rename to packages/lumberaxe/bin/rubocop diff --git a/packages/nitro_logging/bin/schema b/packages/lumberaxe/bin/schema similarity index 100% rename from packages/nitro_logging/bin/schema rename to packages/lumberaxe/bin/schema diff --git a/packages/nitro_logging/bin/setup b/packages/lumberaxe/bin/setup similarity index 100% rename from packages/nitro_logging/bin/setup rename to packages/lumberaxe/bin/setup diff --git a/packages/nitro_logging/bin/test b/packages/lumberaxe/bin/test similarity index 100% rename from packages/nitro_logging/bin/test rename to packages/lumberaxe/bin/test diff --git a/packages/nitro_logging/bin/yard b/packages/lumberaxe/bin/yard similarity index 100% rename from packages/nitro_logging/bin/yard rename to packages/lumberaxe/bin/yard diff --git a/packages/nitro_logging/bin/yardoc b/packages/lumberaxe/bin/yardoc similarity index 100% rename from packages/nitro_logging/bin/yardoc rename to packages/lumberaxe/bin/yardoc diff --git a/packages/nitro_logging/bin/yri b/packages/lumberaxe/bin/yri similarity index 100% rename from packages/nitro_logging/bin/yri rename to packages/lumberaxe/bin/yri diff --git a/packages/nitro_logging/docs/README.md b/packages/lumberaxe/docs/README.md similarity index 100% rename from packages/nitro_logging/docs/README.md rename to packages/lumberaxe/docs/README.md diff --git a/packages/nitro_logging/lib/nitro_logging.rb b/packages/lumberaxe/lib/lumberaxe.rb similarity index 100% rename from packages/nitro_logging/lib/nitro_logging.rb rename to packages/lumberaxe/lib/lumberaxe.rb diff --git a/packages/nitro_logging/lib/nitro_logging/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb similarity index 100% rename from packages/nitro_logging/lib/nitro_logging/log_chooser.rb rename to packages/lumberaxe/lib/lumberaxe/log_chooser.rb diff --git a/packages/nitro_logging/lib/nitro_logging/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb similarity index 100% rename from packages/nitro_logging/lib/nitro_logging/railtie.rb rename to packages/lumberaxe/lib/lumberaxe/railtie.rb diff --git a/packages/nitro_logging/nitro_logging.gemspec b/packages/lumberaxe/lumberaxe.gemspec similarity index 100% rename from packages/nitro_logging/nitro_logging.gemspec rename to packages/lumberaxe/lumberaxe.gemspec diff --git a/packages/nitro_logging/mkdocs.yml b/packages/lumberaxe/mkdocs.yml similarity index 100% rename from packages/nitro_logging/mkdocs.yml rename to packages/lumberaxe/mkdocs.yml diff --git a/packages/nitro_logging/portal.yml b/packages/lumberaxe/portal.yml similarity index 100% rename from packages/nitro_logging/portal.yml rename to packages/lumberaxe/portal.yml diff --git a/packages/nitro_logging/spec/spec_helper.rb b/packages/lumberaxe/spec/spec_helper.rb similarity index 100% rename from packages/nitro_logging/spec/spec_helper.rb rename to packages/lumberaxe/spec/spec_helper.rb diff --git a/packages/nitro_logging/test.sh b/packages/lumberaxe/test.sh similarity index 100% rename from packages/nitro_logging/test.sh rename to packages/lumberaxe/test.sh From c0b7cef2cffa3891d0cfd9215c2596e32f8ee6b3 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 16:24:37 -0400 Subject: [PATCH 03/32] Rename all references --- packages/lumberaxe/.rubocop_todo.yml | 4 ++-- packages/lumberaxe/Gemfile.lock | 4 ++-- packages/lumberaxe/bin/console | 2 +- packages/lumberaxe/docs/README.md | 4 ++-- packages/lumberaxe/lib/lumberaxe.rb | 6 +++--- packages/lumberaxe/lib/lumberaxe/log_chooser.rb | 2 +- packages/lumberaxe/lib/lumberaxe/railtie.rb | 6 +++--- packages/lumberaxe/lumberaxe.gemspec | 2 +- packages/lumberaxe/mkdocs.yml | 2 +- packages/lumberaxe/portal.yml | 4 ++-- packages/lumberaxe/spec/spec_helper.rb | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/lumberaxe/.rubocop_todo.yml b/packages/lumberaxe/.rubocop_todo.yml index 5b14e966..0599d757 100644 --- a/packages/lumberaxe/.rubocop_todo.yml +++ b/packages/lumberaxe/.rubocop_todo.yml @@ -10,11 +10,11 @@ # Cop supports --auto-correct. Style/GlobalStdStream: Exclude: - - 'lib/nitro_logging/log_chooser.rb' + - 'lib/lumberaxe/log_chooser.rb' # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Mode. Style/StringConcatenation: Exclude: - - 'lib/nitro_logging/log_chooser.rb' + - 'lib/lumberaxe/log_chooser.rb' diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 18739f1e..fea7a768 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: . specs: - nitro_logging (0.0.1) + lumberaxe (0.0.1) activesupport (= 5.2.8.1) GEM @@ -122,7 +122,7 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1) nitro_linting! - nitro_logging! + lumberaxe! parser (>= 2.5, != 2.5.1.1) pry-byebug (= 3.9.0) rainbow (= 2.2.2) diff --git a/packages/lumberaxe/bin/console b/packages/lumberaxe/bin/console index ada06dc9..c12f487b 100755 --- a/packages/lumberaxe/bin/console +++ b/packages/lumberaxe/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "bundler/setup" -require "nitro_logging" +require "lumberaxe" # 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. diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index e63a1e39..1f757747 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -1,3 +1,3 @@ -# NitroLogging +# Lumberaxe -Nitro Logging handles logging output formatting. +Lumberaxe handles logging output formatting. diff --git a/packages/lumberaxe/lib/lumberaxe.rb b/packages/lumberaxe/lib/lumberaxe.rb index caf9173b..4bd589cf 100644 --- a/packages/lumberaxe/lib/lumberaxe.rb +++ b/packages/lumberaxe/lib/lumberaxe.rb @@ -2,8 +2,8 @@ require "logger" require "active_support" -require "nitro_logging/railtie" if defined?(Rails) -require "nitro_logging/log_chooser" +require "lumberaxe/railtie" if defined?(Rails) +require "lumberaxe/log_chooser" -module NitroLogging +module Lumberaxe end diff --git a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb index 994bff63..9f662b18 100644 --- a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb +++ b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb @@ -2,7 +2,7 @@ require "active_support/tagged_logging" -module NitroLogging +module Lumberaxe class LogChooser cattr_accessor :log_level diff --git a/packages/lumberaxe/lib/lumberaxe/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb index 84c90821..b161d0cd 100644 --- a/packages/lumberaxe/lib/lumberaxe/railtie.rb +++ b/packages/lumberaxe/lib/lumberaxe/railtie.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -module NitroLogging +module Lumberaxe class Railtie < Rails::Railtie - initializer "nitro_logging.configurations" do - NitroLogging::LogChooser.log_level = Rails.application.config.log_level + initializer "lumberaxe.configurations" do + Lumberaxe::LogChooser.log_level = Rails.application.config.log_level end end end diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index b06f4357..aa512fad 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -3,7 +3,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__) Gem::Specification.new do |s| - s.name = "nitro_logging" + s.name = "lumberaxe" s.version = "0.0.1" s.authors = ["Nitro Developers"] s.email = ["dev@powerhrg.com"] diff --git a/packages/lumberaxe/mkdocs.yml b/packages/lumberaxe/mkdocs.yml index 5d0ccb2d..b0513be7 100644 --- a/packages/lumberaxe/mkdocs.yml +++ b/packages/lumberaxe/mkdocs.yml @@ -1,4 +1,4 @@ -site_name: Nitro Logging +site_name: Lumberaxe nav: - "Home": "README.md" plugins: diff --git a/packages/lumberaxe/portal.yml b/packages/lumberaxe/portal.yml index 643831dc..603ef01e 100644 --- a/packages/lumberaxe/portal.yml +++ b/packages/lumberaxe/portal.yml @@ -2,8 +2,8 @@ apiVersion: backstage.io/v1alpha1 kind: Component metadata: - name: nitro-logging - title: Nitro Logging + name: lumberaxe + title: Lumberaxe description: Handles logging output formatting spec: type: library diff --git a/packages/lumberaxe/spec/spec_helper.rb b/packages/lumberaxe/spec/spec_helper.rb index 9271767a..65c8510a 100644 --- a/packages/lumberaxe/spec/spec_helper.rb +++ b/packages/lumberaxe/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) -require "nitro_logging" +require "lumberaxe" require "pry-byebug" From 5d4d2735de39a4c7490d38400d0d730023dea5e5 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 17:32:43 -0400 Subject: [PATCH 04/32] Set up rubocop; remove binstubs --- packages/lumberaxe/.rubocop.yml | 10 +++++-- packages/lumberaxe/Gemfile | 5 ---- packages/lumberaxe/Gemfile.lock | 17 +---------- packages/lumberaxe/bin/build | 8 ----- packages/lumberaxe/bin/clean | 5 ---- packages/lumberaxe/bin/console | 14 --------- packages/lumberaxe/bin/deps | 10 ------- packages/lumberaxe/bin/doc | 11 ------- packages/lumberaxe/bin/rake | 29 ------------------- packages/lumberaxe/bin/rspec | 29 ------------------- packages/lumberaxe/bin/rubocop | 29 ------------------- packages/lumberaxe/bin/schema | 5 ---- packages/lumberaxe/bin/setup | 6 ---- packages/lumberaxe/bin/test | 11 ------- packages/lumberaxe/bin/yard | 29 ------------------- packages/lumberaxe/bin/yardoc | 29 ------------------- packages/lumberaxe/bin/yri | 29 ------------------- .../lumberaxe/lib/lumberaxe/log_chooser.rb | 20 ++++++++----- packages/lumberaxe/lumberaxe.gemspec | 2 +- 19 files changed, 22 insertions(+), 276 deletions(-) delete mode 100755 packages/lumberaxe/bin/build delete mode 100755 packages/lumberaxe/bin/clean delete mode 100755 packages/lumberaxe/bin/console delete mode 100755 packages/lumberaxe/bin/deps delete mode 100755 packages/lumberaxe/bin/doc delete mode 100755 packages/lumberaxe/bin/rake delete mode 100755 packages/lumberaxe/bin/rspec delete mode 100755 packages/lumberaxe/bin/rubocop delete mode 100755 packages/lumberaxe/bin/schema delete mode 100755 packages/lumberaxe/bin/setup delete mode 100755 packages/lumberaxe/bin/test delete mode 100755 packages/lumberaxe/bin/yard delete mode 100755 packages/lumberaxe/bin/yardoc delete mode 100755 packages/lumberaxe/bin/yri diff --git a/packages/lumberaxe/.rubocop.yml b/packages/lumberaxe/.rubocop.yml index 41d54493..0e631c26 100644 --- a/packages/lumberaxe/.rubocop.yml +++ b/packages/lumberaxe/.rubocop.yml @@ -1,4 +1,8 @@ -inherit_from: .rubocop_todo.yml +require: + - rubocop-powerhome -inherit_gem: - nitro_linting: .rubocop_standard.yml +AllCops: + TargetRubyVersion: 2.7 + +Rails: + Enabled: false diff --git a/packages/lumberaxe/Gemfile b/packages/lumberaxe/Gemfile index 76732229..1191de13 100644 --- a/packages/lumberaxe/Gemfile +++ b/packages/lumberaxe/Gemfile @@ -7,8 +7,3 @@ git_source(:github) do |repo_name| end gemspec - -path ".." do - # Dependencies on other components go here - gem "nitro_linting", require: nil -end diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index fea7a768..0c52a87d 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -1,15 +1,3 @@ -PATH - remote: .. - specs: - nitro_linting (0.0.1) - rubocop (= 1.20.0) - rubocop-cobra (>= 0.4.0) - rubocop-performance (= 1.11.5) - rubocop-powerhome (>= 0.5.0) - rubocop-rails (= 2.12.2) - rubocop-rake (= 0.6.0) - rubocop-rspec (= 2.4.0) - PATH remote: . specs: @@ -75,9 +63,6 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.19.1) parser (>= 3.1.1.0) - rubocop-cobra (0.4.0) - rubocop - rubocop-powerhome rubocop-performance (1.11.5) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) @@ -121,13 +106,13 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1) - nitro_linting! lumberaxe! parser (>= 2.5, != 2.5.1.1) pry-byebug (= 3.9.0) rainbow (= 2.2.2) rake (~> 13.0) rspec (~> 3.0) + rubocop-powerhome (= 0.5.0) simplecov (= 0.15.1) test-unit (= 3.1.5) yard (= 0.9.21) diff --git a/packages/lumberaxe/bin/build b/packages/lumberaxe/bin/build deleted file mode 100755 index 0fc1fd43..00000000 --- a/packages/lumberaxe/bin/build +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Build - -echo ">>> Building" -time bin/rubocop --display-cop-names --extra-details --parallel --display-style-guide --config .rubocop.yml diff --git a/packages/lumberaxe/bin/clean b/packages/lumberaxe/bin/clean deleted file mode 100755 index c4b7887d..00000000 --- a/packages/lumberaxe/bin/clean +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo "This component doesn't have a database" diff --git a/packages/lumberaxe/bin/console b/packages/lumberaxe/bin/console deleted file mode 100755 index c12f487b..00000000 --- a/packages/lumberaxe/bin/console +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env ruby - -require "bundler/setup" -require "lumberaxe" - -# 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. - -# (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" -# Pry.start - -require "irb" -IRB.start(__FILE__) diff --git a/packages/lumberaxe/bin/deps b/packages/lumberaxe/bin/deps deleted file mode 100755 index b7e2137b..00000000 --- a/packages/lumberaxe/bin/deps +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo ">>> Installing dependencies" -if [ -z $CI ] ; then - time bundle check || bundle install --quiet -else - time bundle check || bundle install -fi diff --git a/packages/lumberaxe/bin/doc b/packages/lumberaxe/bin/doc deleted file mode 100755 index b68f2b30..00000000 --- a/packages/lumberaxe/bin/doc +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo ">>> Documenting" -OUTPUT="$(time bin/yard)" -echo "${OUTPUT}" -if [ "$(echo ${OUTPUT} | grep warn | wc -l)" -gt 0 ]; then - echo "Documentation warnings occurred" - exit 1 -fi diff --git a/packages/lumberaxe/bin/rake b/packages/lumberaxe/bin/rake deleted file mode 100755 index 9275675e..00000000 --- a/packages/lumberaxe/bin/rake +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rake' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rake", "rake") diff --git a/packages/lumberaxe/bin/rspec b/packages/lumberaxe/bin/rspec deleted file mode 100755 index a6c78521..00000000 --- a/packages/lumberaxe/bin/rspec +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rspec' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rspec-core", "rspec") diff --git a/packages/lumberaxe/bin/rubocop b/packages/lumberaxe/bin/rubocop deleted file mode 100755 index d0c48829..00000000 --- a/packages/lumberaxe/bin/rubocop +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rubocop' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rubocop", "rubocop") diff --git a/packages/lumberaxe/bin/schema b/packages/lumberaxe/bin/schema deleted file mode 100755 index c4b7887d..00000000 --- a/packages/lumberaxe/bin/schema +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo "This component doesn't have a database" diff --git a/packages/lumberaxe/bin/setup b/packages/lumberaxe/bin/setup deleted file mode 100755 index d222cb3f..00000000 --- a/packages/lumberaxe/bin/setup +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -e - -bin/deps -bin/schema diff --git a/packages/lumberaxe/bin/test b/packages/lumberaxe/bin/test deleted file mode 100755 index 4ae124e2..00000000 --- a/packages/lumberaxe/bin/test +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Test - -echo ">>> Testing" -trap "kill -TERM $PID" TERM -time bin/rspec --format progress --format html --out ./tmp/spec_results/index.html --profile 100 spec & -PID=$! -wait $PID diff --git a/packages/lumberaxe/bin/yard b/packages/lumberaxe/bin/yard deleted file mode 100755 index 0ed81a10..00000000 --- a/packages/lumberaxe/bin/yard +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'yard' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("yard", "yard") diff --git a/packages/lumberaxe/bin/yardoc b/packages/lumberaxe/bin/yardoc deleted file mode 100755 index b0979f72..00000000 --- a/packages/lumberaxe/bin/yardoc +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'yardoc' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("yard", "yardoc") diff --git a/packages/lumberaxe/bin/yri b/packages/lumberaxe/bin/yri deleted file mode 100755 index 0a772f98..00000000 --- a/packages/lumberaxe/bin/yri +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'yri' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("yard", "yri") diff --git a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb index 9f662b18..49951fb4 100644 --- a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb +++ b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb @@ -17,7 +17,7 @@ def self.logger(progname:) # is to send their logging output to STDOUT instead of various # logfiles on disk. def self.primary_logdev - STDOUT + $stdout end def self.structured_logging? @@ -31,6 +31,18 @@ class JSONFormatter < ::Logger::Formatter def call(severity, time, progname, data) data = { message: data.to_s } unless data.is_a?(Hash) + formatter = { + level: severity, + time: time, + progname: progname, + }.merge(format_data(data)) + + "#{formatter.to_json}\r\n}" + end + + private + + def format_data(data) data.merge!(current_tags.each_with_object({}) do |tag, hash| if tag.include?("=") key, value = tag.split("=") @@ -41,12 +53,6 @@ def call(severity, time, progname, data) end hash end) - - { - level: severity, - time: time, - progname: progname, - }.merge(data).to_json + "\r\n" end end end diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index aa512fad..1567512b 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -23,12 +23,12 @@ Gem::Specification.new do |s| s.add_dependency "activesupport", "5.2.8.1" s.add_development_dependency "bundler", "~> 2.1" - s.add_development_dependency "nitro_linting", "0.0.1" s.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" s.add_development_dependency "pry-byebug", "3.9.0" s.add_development_dependency "rainbow", "2.2.2" s.add_development_dependency "rake", "~> 13.0" s.add_development_dependency "rspec", "~> 3.0" + s.add_development_dependency "rubocop-powerhome", "0.5.0" s.add_development_dependency "simplecov", "0.15.1" s.add_development_dependency "test-unit", "3.1.5" s.add_development_dependency "yard", "0.9.21" From 0626b1c5c9192b65a2a18802a7b025133aafc80b Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 17:48:32 -0400 Subject: [PATCH 05/32] Add documentation --- docs/README.md | 8 ++++++++ packages/lumberaxe/portal.yml | 15 --------------- portal.yml | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 15 deletions(-) delete mode 100644 packages/lumberaxe/portal.yml diff --git a/docs/README.md b/docs/README.md index bfc2ef5e..a926ad75 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,6 +10,14 @@ power-tools currently contains the following packages (marked for release to rub When included in a Rails application, NitroConfig loads the configuration file at `config/config.yml` within the application directory and makes its values available at `NitroConfig.config`. Config values are loaded based on the Rails environment, permitting the specification of multiple environments' configurations in a single file. +[audit_tracker](https://github.com/powerhome/power-tools/blob/main/packages/audit_tracker/docs/README.md) 💎 + +AuditTracker helps you centralize data tracking configuration to be used across different models. + +[lumberaxe](https://github.com/powerhome/power-tools/blob/main/packages/lumberaxe/docs/README.md) 💎 + +Lumberaxe handles logging output formatting. + ## Installation 🛠 These packages are all meant to install inside of an application and aren't intended to stand alone; currently, they are all published to [RubyGems](https://rubygems.org/) and you can use standard Bundler methods to install them. diff --git a/packages/lumberaxe/portal.yml b/packages/lumberaxe/portal.yml deleted file mode 100644 index 603ef01e..00000000 --- a/packages/lumberaxe/portal.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: lumberaxe - title: Lumberaxe - description: Handles logging output formatting -spec: - type: library - owner: heroes-for-hire - system: nitro - lifecycle: production - subcomponentOf: nitro-web - dependsOn: - - component:nitro-linting diff --git a/portal.yml b/portal.yml index 3b5f763d..c3dc4ea9 100644 --- a/portal.yml +++ b/portal.yml @@ -49,3 +49,19 @@ spec: lifecycle: production subcomponentOf: power-tools system: power-application-framework +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: lumberaxe + title: Lumberaxe + description: Handles logging output formatting + annotations: + backstage.io/techdocs-ref: dir:packages/lumberaxe +spec: + type: library + owner: heroes-for-hire + system: nitro + lifecycle: production + subcomponentOf: power-tools + system: power-application-framework From 8b9abf6fc41d9a046b8e914564d90b6ba2b9a287 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 17:50:13 -0400 Subject: [PATCH 06/32] Set up CI --- .github/workflows/lumberaxe.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/lumberaxe.yml diff --git a/.github/workflows/lumberaxe.yml b/.github/workflows/lumberaxe.yml new file mode 100644 index 00000000..390254d2 --- /dev/null +++ b/.github/workflows/lumberaxe.yml @@ -0,0 +1,13 @@ +name: lumberaxe + +on: + push: + +jobs: + ruby: + uses: ./.github/workflows/_ruby-package.yml + with: + package: ${{ github.workflow }} + ruby: '["2.7.4", "3.1.2"]' + rails: '["7.0.3.1","6.1.6.1","6.0.5.1","5.2.8.1"]' + secrets: inherit From b616f6c970bdd37ee0f79e0716d607bd2b4ac1ad Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 17:56:42 -0400 Subject: [PATCH 07/32] Fix gemspec --- packages/lumberaxe/lumberaxe.gemspec | 44 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index 1567512b..fe2b92d7 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -2,34 +2,34 @@ $LOAD_PATH.push File.expand_path("lib", __dir__) -Gem::Specification.new do |s| - s.name = "lumberaxe" - s.version = "0.0.1" - s.authors = ["Nitro Developers"] - s.email = ["dev@powerhrg.com"] - s.homepage = "http://nitro.powerhrg.com" - s.summary = "SomeSummary" - s.description = "SomeLongerDescription" +Gem::Specification.new do |spec| + spec.name = "lumberaxe" + spec.version = Lumberaxe::VERSION + spec.authors = ["Carlos Palhares", "Jill Klang"] + spec.email = ["chjunior@gmail.com", "jillian.emilie@gmail.com"] + spec.homepage = "http://nitro.powerhrg.com" + spec.summary = "Power-ful logging wrapper" + spec.description = "Lumberaxe handles logging output formatting." # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host" # to allow pushing to a single host or delete this section to allow pushing to any host. raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless s.respond_to?(:metadata) - s.metadata["allowed_push_host"] = "http://rubygems.powerhrg.com" - s.license = "LicenseRef-NitroComponent" + spec.metadata["allowed_push_host"] = "http://rubygems.powerhrg.com" + spec.license = "LicenseRef-NitroComponent" - s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] + spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] - s.add_dependency "activesupport", "5.2.8.1" + spec.add_dependency "activesupport", "5.2.8.1" - s.add_development_dependency "bundler", "~> 2.1" - s.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" - s.add_development_dependency "pry-byebug", "3.9.0" - s.add_development_dependency "rainbow", "2.2.2" - s.add_development_dependency "rake", "~> 13.0" - s.add_development_dependency "rspec", "~> 3.0" - s.add_development_dependency "rubocop-powerhome", "0.5.0" - s.add_development_dependency "simplecov", "0.15.1" - s.add_development_dependency "test-unit", "3.1.5" - s.add_development_dependency "yard", "0.9.21" + spec.add_development_dependency "bundler", "~> 2.1" + spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" + spec.add_development_dependency "pry-byebug", "3.9.0" + spec.add_development_dependency "rainbow", "2.2.2" + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "rubocop-powerhome", "0.5.0" + spec.add_development_dependency "simplecov", "0.15.1" + spec.add_development_dependency "test-unit", "3.1.5" + spec.add_development_dependency "yard", "0.9.21" end From f65e082d4f8c2acf219c902b41c61773756821c7 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 17:56:51 -0400 Subject: [PATCH 08/32] Add publishing info --- packages/lumberaxe/.gitignore | 1 - packages/lumberaxe/Gemfile.lock | 16 +++++++++++++++- .../lumberaxe/doc/dependency_decisions.yml | 3 +++ packages/lumberaxe/lib/lumberaxe/version.rb | 5 +++++ packages/lumberaxe/lumberaxe.gemspec | 18 +++++++++++------- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 packages/lumberaxe/doc/dependency_decisions.yml create mode 100644 packages/lumberaxe/lib/lumberaxe/version.rb diff --git a/packages/lumberaxe/.gitignore b/packages/lumberaxe/.gitignore index cb2fc2fa..8b650730 100644 --- a/packages/lumberaxe/.gitignore +++ b/packages/lumberaxe/.gitignore @@ -2,7 +2,6 @@ /.yardoc /_yardoc/ coverage -/doc pkg /spec/reports/ **/tmp/* diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 0c52a87d..a7e4bbd5 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lumberaxe (0.0.1) + lumberaxe (0.1.0) activesupport (= 5.2.8.1) GEM @@ -21,6 +21,13 @@ GEM i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.5.1) + license_finder (7.0.1) + bundler + rubyzip (>= 1, < 3) + thor (~> 1.2) + tomlrb (>= 1.3, < 2.1) + with_env (= 1.1.0) + xml-simple (~> 1.1.9) method_source (1.0.0) minitest (5.16.2) parallel (1.22.1) @@ -82,6 +89,7 @@ GEM rubocop (~> 1.0) rubocop-ast (>= 1.1.0) ruby-progressbar (1.11.0) + rubyzip (2.3.2) simplecov (0.15.1) docile (~> 1.1.0) json (>= 1.8, < 3) @@ -89,10 +97,15 @@ GEM simplecov-html (0.10.2) test-unit (3.1.5) power_assert + thor (1.2.1) thread_safe (0.3.6) + tomlrb (2.0.3) tzinfo (1.2.10) thread_safe (~> 0.1) unicode-display_width (2.2.0) + with_env (1.1.0) + xml-simple (1.1.9) + rexml yard (0.9.21) PLATFORMS @@ -106,6 +119,7 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1) + license_finder (~> 7.0) lumberaxe! parser (>= 2.5, != 2.5.1.1) pry-byebug (= 3.9.0) diff --git a/packages/lumberaxe/doc/dependency_decisions.yml b/packages/lumberaxe/doc/dependency_decisions.yml new file mode 100644 index 00000000..f734baa9 --- /dev/null +++ b/packages/lumberaxe/doc/dependency_decisions.yml @@ -0,0 +1,3 @@ +--- +- - :inherit_from + - https://raw.githubusercontent.com/powerhome/oss-guide/master/license_rules.yml diff --git a/packages/lumberaxe/lib/lumberaxe/version.rb b/packages/lumberaxe/lib/lumberaxe/version.rb new file mode 100644 index 00000000..fc4054ac --- /dev/null +++ b/packages/lumberaxe/lib/lumberaxe/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Lumberaxe + VERSION = "0.1.0" +end diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index fe2b92d7..bd2df1da 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "lib/lumberaxe/version" + $LOAD_PATH.push File.expand_path("lib", __dir__) Gem::Specification.new do |spec| @@ -7,22 +9,24 @@ Gem::Specification.new do |spec| spec.version = Lumberaxe::VERSION spec.authors = ["Carlos Palhares", "Jill Klang"] spec.email = ["chjunior@gmail.com", "jillian.emilie@gmail.com"] - spec.homepage = "http://nitro.powerhrg.com" + spec.summary = "Power-ful logging wrapper" spec.description = "Lumberaxe handles logging output formatting." + spec.homepage = "https://github.com/powerhome/power-tools" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.7" - # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host" - # to allow pushing to a single host or delete this section to allow pushing to any host. - raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless s.respond_to?(:metadata) - - spec.metadata["allowed_push_host"] = "http://rubygems.powerhrg.com" - spec.license = "LicenseRef-NitroComponent" + spec.metadata["rubygems_mfa_required"] = "true" + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/lumberaxe/docs/CHANGELOG.md" spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] spec.add_dependency "activesupport", "5.2.8.1" spec.add_development_dependency "bundler", "~> 2.1" + spec.add_development_dependency "license_finder", "~> 7.0" spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" spec.add_development_dependency "pry-byebug", "3.9.0" spec.add_development_dependency "rainbow", "2.2.2" From 9d24e123e76fb79ad3249e8bce8d28ced45bf092 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 18:15:59 -0400 Subject: [PATCH 09/32] Include lograge --- packages/lumberaxe/Gemfile.lock | 51 ++++++++++++++++++++++++++++ packages/lumberaxe/lumberaxe.gemspec | 1 + 2 files changed, 52 insertions(+) diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index a7e4bbd5..201507b3 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -3,21 +3,38 @@ PATH specs: lumberaxe (0.1.0) activesupport (= 5.2.8.1) + lograge GEM remote: https://rubygems.org/ specs: + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) ast (2.4.2) + builder (3.2.4) byebug (11.1.3) coderay (1.1.3) concurrent-ruby (1.1.10) + crass (1.0.6) diff-lcs (1.5.0) docile (1.1.5) + erubi (1.11.0) i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.5.1) @@ -28,8 +45,26 @@ GEM tomlrb (>= 1.3, < 2.1) with_env (= 1.1.0) xml-simple (~> 1.1.9) + lograge (0.12.0) + actionpack (>= 4) + activesupport (>= 4) + railties (>= 4) + request_store (~> 1.0) + loofah (2.18.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) method_source (1.0.0) + mini_portile2 (2.8.0) minitest (5.16.2) + nokogiri (1.13.8) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + nokogiri (1.13.8-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.8-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.13.8-x86_64-linux) + racc (~> 1.4) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) @@ -40,11 +75,27 @@ GEM pry-byebug (3.9.0) byebug (~> 11.0) pry (~> 0.13.0) + racc (1.6.0) rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) rainbow (2.2.2) rake rake (13.0.6) regexp_parser (2.5.0) + request_store (1.5.1) + rack (>= 1.4) rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index bd2df1da..2a75d1de 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] spec.add_dependency "activesupport", "5.2.8.1" + spec.add_dependency "lograge" spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "license_finder", "~> 7.0" From 42c1563cac1f17862591762199a2062b3f51080e Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 4 Aug 2022 21:06:42 -0400 Subject: [PATCH 10/32] Specify lograge version --- packages/lumberaxe/Gemfile.lock | 4 ++-- packages/lumberaxe/lumberaxe.gemspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 201507b3..85a292d4 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -3,7 +3,7 @@ PATH specs: lumberaxe (0.1.0) activesupport (= 5.2.8.1) - lograge + lograge (= 0.10.0) GEM remote: https://rubygems.org/ @@ -45,7 +45,7 @@ GEM tomlrb (>= 1.3, < 2.1) with_env (= 1.1.0) xml-simple (~> 1.1.9) - lograge (0.12.0) + lograge (0.10.0) actionpack (>= 4) activesupport (>= 4) railties (>= 4) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index 2a75d1de..a723afe6 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] spec.add_dependency "activesupport", "5.2.8.1" - spec.add_dependency "lograge" + spec.add_dependency "lograge", "0.10.0" spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "license_finder", "~> 7.0" From 1739261a99353a5ad4f44f7da1db56dd68265214 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Fri, 5 Aug 2022 10:15:59 -0400 Subject: [PATCH 11/32] Less rigid versioning --- packages/lumberaxe/Gemfile.lock | 2 +- packages/lumberaxe/lumberaxe.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 85a292d4..a9e164e2 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: lumberaxe (0.1.0) - activesupport (= 5.2.8.1) + activesupport (>= 5.2.8.1) lograge (= 0.10.0) GEM diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index a723afe6..91d3ed93 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] - spec.add_dependency "activesupport", "5.2.8.1" + spec.add_dependency "activesupport", ">= 5.2.8.1" spec.add_dependency "lograge", "0.10.0" spec.add_development_dependency "bundler", "~> 2.1" From 52c08f2f0ee205316177722c887b36d4a0fcc075 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Fri, 5 Aug 2022 10:17:22 -0400 Subject: [PATCH 12/32] Update packages/lumberaxe/lib/lumberaxe/log_chooser.rb Co-authored-by: Carlos Palhares --- packages/lumberaxe/lib/lumberaxe/log_chooser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb index 49951fb4..b17eb328 100644 --- a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb +++ b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb @@ -16,7 +16,7 @@ def self.logger(progname:) # Standard practice for applications running in Docker containers # is to send their logging output to STDOUT instead of various # logfiles on disk. - def self.primary_logdev + cattr_accessor :primary_logdev do $stdout end From d35a944944673a7f9595a86a92a202f746c2c692 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Tue, 9 Aug 2022 09:56:35 -0400 Subject: [PATCH 13/32] Add test coverage --- packages/lumberaxe/Gemfile | 4 ++ packages/lumberaxe/Gemfile.lock | 60 +++++++++++++++++++ packages/lumberaxe/config.ru | 9 +++ .../lumberaxe/lib/lumberaxe/log_chooser.rb | 2 - packages/lumberaxe/lumberaxe.gemspec | 2 + .../internal/app/assets/config/manifest.js | 0 .../spec/internal/config/database.yml | 3 + .../lumberaxe/spec/internal/config/routes.rb | 5 ++ .../spec/internal/config/storage.yml | 3 + packages/lumberaxe/spec/internal/db/schema.rb | 6 ++ .../lumberaxe/spec/internal/log/.gitignore | 1 + .../spec/internal/public/favicon.ico | 0 .../lumberaxe/spec/lumberaxe/railtie_spec.rb | 9 +++ .../lumberaxe/spec/lumberaxe/request_spec.rb | 9 +++ packages/lumberaxe/spec/rails_helper.rb | 6 ++ packages/lumberaxe/spec/spec_helper.rb | 6 +- 16 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 packages/lumberaxe/config.ru create mode 100644 packages/lumberaxe/spec/internal/app/assets/config/manifest.js create mode 100644 packages/lumberaxe/spec/internal/config/database.yml create mode 100644 packages/lumberaxe/spec/internal/config/routes.rb create mode 100644 packages/lumberaxe/spec/internal/config/storage.yml create mode 100644 packages/lumberaxe/spec/internal/db/schema.rb create mode 100644 packages/lumberaxe/spec/internal/log/.gitignore create mode 100644 packages/lumberaxe/spec/internal/public/favicon.ico create mode 100644 packages/lumberaxe/spec/lumberaxe/railtie_spec.rb create mode 100644 packages/lumberaxe/spec/lumberaxe/request_spec.rb create mode 100644 packages/lumberaxe/spec/rails_helper.rb diff --git a/packages/lumberaxe/Gemfile b/packages/lumberaxe/Gemfile index 1191de13..972f6bc5 100644 --- a/packages/lumberaxe/Gemfile +++ b/packages/lumberaxe/Gemfile @@ -7,3 +7,7 @@ git_source(:github) do |repo_name| end gemspec + +rails_version = ENV.fetch("RAILS_VERSION", ">= 5.2.8.1") + +gem "rails", rails_version diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index a9e164e2..9b0ea234 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -8,6 +8,16 @@ PATH GEM remote: https://rubygems.org/ specs: + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) actionpack (5.2.8.1) actionview (= 5.2.8.1) activesupport (= 5.2.8.1) @@ -21,20 +31,40 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) + globalid (>= 0.3.6) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + arel (9.0.0) ast (2.4.2) builder (3.2.4) byebug (11.1.3) coderay (1.1.3) + combustion (1.3.7) + activesupport (>= 3.0.0) + railties (>= 3.0.0) + thor (>= 0.14.6) concurrent-ruby (1.1.10) crass (1.0.6) diff-lcs (1.5.0) docile (1.1.5) erubi (1.11.0) + globalid (1.0.0) + activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.5.1) @@ -53,9 +83,14 @@ GEM loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) method_source (1.0.0) + mini_mime (1.1.2) mini_portile2 (2.8.0) minitest (5.16.2) + nio4r (2.5.8) nokogiri (1.13.8) mini_portile2 (~> 2.8.0) racc (~> 1.4) @@ -79,6 +114,19 @@ GEM rack (2.2.4) rack-test (2.0.2) rack (>= 1.3) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) + bundler (>= 1.3.0) + railties (= 5.2.8.1) + sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -146,6 +194,13 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) + sprockets (4.1.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) test-unit (3.1.5) power_assert thor (1.2.1) @@ -154,6 +209,9 @@ GEM tzinfo (1.2.10) thread_safe (~> 0.1) unicode-display_width (2.2.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) with_env (1.1.0) xml-simple (1.1.9) rexml @@ -170,10 +228,12 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1) + combustion (~> 1.3) license_finder (~> 7.0) lumberaxe! parser (>= 2.5, != 2.5.1.1) pry-byebug (= 3.9.0) + rails (>= 5.2.8.1) rainbow (= 2.2.2) rake (~> 13.0) rspec (~> 3.0) diff --git a/packages/lumberaxe/config.ru b/packages/lumberaxe/config.ru new file mode 100644 index 00000000..1265db9f --- /dev/null +++ b/packages/lumberaxe/config.ru @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "rubygems" +require "bundler" + +Bundler.require :default, :development + +Combustion.initialize! :all +run Combustion::Application diff --git a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb index b17eb328..848e0833 100644 --- a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb +++ b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "active_support/tagged_logging" - module Lumberaxe class LogChooser cattr_accessor :log_level diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index 91d3ed93..78f1031d 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -27,11 +27,13 @@ Gem::Specification.new do |spec| spec.add_dependency "lograge", "0.10.0" spec.add_development_dependency "bundler", "~> 2.1" + spec.add_development_dependency "combustion", "~> 1.3" spec.add_development_dependency "license_finder", "~> 7.0" spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" spec.add_development_dependency "pry-byebug", "3.9.0" spec.add_development_dependency "rainbow", "2.2.2" spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rails", ">= 5.2.8.1" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rubocop-powerhome", "0.5.0" spec.add_development_dependency "simplecov", "0.15.1" diff --git a/packages/lumberaxe/spec/internal/app/assets/config/manifest.js b/packages/lumberaxe/spec/internal/app/assets/config/manifest.js new file mode 100644 index 00000000..e69de29b diff --git a/packages/lumberaxe/spec/internal/config/database.yml b/packages/lumberaxe/spec/internal/config/database.yml new file mode 100644 index 00000000..b9781191 --- /dev/null +++ b/packages/lumberaxe/spec/internal/config/database.yml @@ -0,0 +1,3 @@ +test: + adapter: sqlite3 + database: db/combustion_test.sqlite diff --git a/packages/lumberaxe/spec/internal/config/routes.rb b/packages/lumberaxe/spec/internal/config/routes.rb new file mode 100644 index 00000000..878c8133 --- /dev/null +++ b/packages/lumberaxe/spec/internal/config/routes.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Rails.application.routes.draw do + # Add your own routes here, or remove this file if you don't have need for it. +end diff --git a/packages/lumberaxe/spec/internal/config/storage.yml b/packages/lumberaxe/spec/internal/config/storage.yml new file mode 100644 index 00000000..b24060b3 --- /dev/null +++ b/packages/lumberaxe/spec/internal/config/storage.yml @@ -0,0 +1,3 @@ +test: + service: Disk + root: /Users/jill/power-tools/packages/lumberaxe/tmp/storage diff --git a/packages/lumberaxe/spec/internal/db/schema.rb b/packages/lumberaxe/spec/internal/db/schema.rb new file mode 100644 index 00000000..3b396d0e --- /dev/null +++ b/packages/lumberaxe/spec/internal/db/schema.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +ActiveRecord::Schema.define do + # Set up any tables you need to exist for your test suite that don't belong + # in migrations. +end diff --git a/packages/lumberaxe/spec/internal/log/.gitignore b/packages/lumberaxe/spec/internal/log/.gitignore new file mode 100644 index 00000000..bf0824e5 --- /dev/null +++ b/packages/lumberaxe/spec/internal/log/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/packages/lumberaxe/spec/internal/public/favicon.ico b/packages/lumberaxe/spec/internal/public/favicon.ico new file mode 100644 index 00000000..e69de29b diff --git a/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb b/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb new file mode 100644 index 00000000..776099ae --- /dev/null +++ b/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Lumberaxe::Railtie" do + it "sets the correct log level" do + expect(Lumberaxe::LogChooser.log_level).to eql(::Rails.application.config.log_level) + end +end diff --git a/packages/lumberaxe/spec/lumberaxe/request_spec.rb b/packages/lumberaxe/spec/lumberaxe/request_spec.rb new file mode 100644 index 00000000..0f77d1f4 --- /dev/null +++ b/packages/lumberaxe/spec/lumberaxe/request_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Lumberaxe integration" do + it "prints to stdout" do + expect { print('foo') }.to output(/foo/).to_stdout + end +end diff --git a/packages/lumberaxe/spec/rails_helper.rb b/packages/lumberaxe/spec/rails_helper.rb new file mode 100644 index 00000000..290f2c14 --- /dev/null +++ b/packages/lumberaxe/spec/rails_helper.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +require_relative "spec_helper" +require "lumberaxe/railtie" + +Combustion.initialize! diff --git a/packages/lumberaxe/spec/spec_helper.rb b/packages/lumberaxe/spec/spec_helper.rb index 65c8510a..7f21ad06 100644 --- a/packages/lumberaxe/spec/spec_helper.rb +++ b/packages/lumberaxe/spec/spec_helper.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) -require "lumberaxe" +require "bundler" + +Bundler.require :default, :development +require "lumberaxe" require "pry-byebug" RSpec.configure do |config| From 9ceca44220a0c1a264a07fac2549e48adee44953 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 10 Aug 2022 12:09:52 -0300 Subject: [PATCH 14/32] Add rubocop to CI --- packages/lumberaxe/Rakefile | 27 +++++++++++++++++-- packages/lumberaxe/lumberaxe.gemspec | 2 +- .../lumberaxe/spec/lumberaxe/request_spec.rb | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/lumberaxe/Rakefile b/packages/lumberaxe/Rakefile index b6ae7341..2a2dbf95 100644 --- a/packages/lumberaxe/Rakefile +++ b/packages/lumberaxe/Rakefile @@ -1,8 +1,31 @@ +#!/usr/bin/env rake + # frozen_string_literal: true -require "bundler/gem_tasks" require "rspec/core/rake_task" +require "rubocop/rake_task" + +begin + require "bundler/setup" +rescue LoadError + puts "You must `gem install bundler` and `bundle install` to run rake tasks" +end +begin + require "yard" + YARD::Rake::YardocTask.new do |t| + t.files = ["lib/**/*.rb"] + t.options = [ + "--no-private", + ] + end +rescue LoadError + warn "Could not require() YARD! Install with 'gem install yard' to get the 'yardoc' task" +end + +Bundler::GemHelper.install_tasks RSpec::Core::RakeTask.new(:spec) -task default: :spec +RuboCop::RakeTask.new(:rubocop) + +task default: %i[spec rubocop] diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index 78f1031d..913d53cd 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -31,9 +31,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency "license_finder", "~> 7.0" spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" spec.add_development_dependency "pry-byebug", "3.9.0" + spec.add_development_dependency "rails", ">= 5.2.8.1" spec.add_development_dependency "rainbow", "2.2.2" spec.add_development_dependency "rake", "~> 13.0" - spec.add_development_dependency "rails", ">= 5.2.8.1" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rubocop-powerhome", "0.5.0" spec.add_development_dependency "simplecov", "0.15.1" diff --git a/packages/lumberaxe/spec/lumberaxe/request_spec.rb b/packages/lumberaxe/spec/lumberaxe/request_spec.rb index 0f77d1f4..7ce92a62 100644 --- a/packages/lumberaxe/spec/lumberaxe/request_spec.rb +++ b/packages/lumberaxe/spec/lumberaxe/request_spec.rb @@ -4,6 +4,6 @@ RSpec.describe "Lumberaxe integration" do it "prints to stdout" do - expect { print('foo') }.to output(/foo/).to_stdout + expect { print("foo") }.to output(/foo/).to_stdout end end From 4f891251b8a046867bbf223b1301980ed1554b80 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Wed, 10 Aug 2022 11:12:34 -0400 Subject: [PATCH 15/32] Combustion for spec coverage --- packages/lumberaxe/Gemfile.lock | 11 +++++++++++ packages/lumberaxe/lumberaxe.gemspec | 2 ++ .../app/controllers/application_controller.rb | 4 ++++ .../app/controllers/campgrounds_controller.rb | 14 ++++++++++++++ .../internal/app/models/application_record.rb | 5 +++++ .../spec/internal/app/models/campground.rb | 7 +++++++ .../lumberaxe/spec/internal/config/routes.rb | 2 +- .../spec/internal/db/combustion_test.sqlite | Bin 0 -> 28672 bytes packages/lumberaxe/spec/internal/db/schema.rb | 6 ++++-- .../lumberaxe/spec/lumberaxe/lumberaxe_spec.rb | 13 +++++++++++++ .../lumberaxe/spec/lumberaxe/request_spec.rb | 9 --------- packages/lumberaxe/spec/rails_helper.rb | 4 +++- 12 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 packages/lumberaxe/spec/internal/app/controllers/application_controller.rb create mode 100644 packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb create mode 100644 packages/lumberaxe/spec/internal/app/models/application_record.rb create mode 100644 packages/lumberaxe/spec/internal/app/models/campground.rb create mode 100644 packages/lumberaxe/spec/internal/db/combustion_test.sqlite create mode 100644 packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb delete mode 100644 packages/lumberaxe/spec/lumberaxe/request_spec.rb diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 9b0ea234..2a062768 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -157,6 +157,14 @@ GEM rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) + rspec-rails (4.1.1) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) rspec-support (3.10.3) rubocop (1.20.0) parallel (~> 1.10) @@ -201,6 +209,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + sqlite3 (1.3.13) test-unit (3.1.5) power_assert thor (1.2.1) @@ -237,8 +246,10 @@ DEPENDENCIES rainbow (= 2.2.2) rake (~> 13.0) rspec (~> 3.0) + rspec-rails (= 4.1.1) rubocop-powerhome (= 0.5.0) simplecov (= 0.15.1) + sqlite3 (= 1.3.13) test-unit (= 3.1.5) yard (= 0.9.21) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index 913d53cd..dec8bfef 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -35,8 +35,10 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rainbow", "2.2.2" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "rspec-rails", "4.1.1" spec.add_development_dependency "rubocop-powerhome", "0.5.0" spec.add_development_dependency "simplecov", "0.15.1" + spec.add_development_dependency "sqlite3", "1.3.13" spec.add_development_dependency "test-unit", "3.1.5" spec.add_development_dependency "yard", "0.9.21" end diff --git a/packages/lumberaxe/spec/internal/app/controllers/application_controller.rb b/packages/lumberaxe/spec/internal/app/controllers/application_controller.rb new file mode 100644 index 00000000..7944f9f9 --- /dev/null +++ b/packages/lumberaxe/spec/internal/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class ApplicationController < ActionController::Base +end diff --git a/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb b/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb new file mode 100644 index 00000000..4c9eecf9 --- /dev/null +++ b/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class CampgroundsController < ApplicationController + def create + campground_params = params.require(:campground).permit(:name) + campground = Campground.new(campground_params) + + if campground.save + render json: campground, status: :created + else + render json: campground.errors, status: :unprocessable_entity + end + end +end diff --git a/packages/lumberaxe/spec/internal/app/models/application_record.rb b/packages/lumberaxe/spec/internal/app/models/application_record.rb new file mode 100644 index 00000000..71fbba5b --- /dev/null +++ b/packages/lumberaxe/spec/internal/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/packages/lumberaxe/spec/internal/app/models/campground.rb b/packages/lumberaxe/spec/internal/app/models/campground.rb new file mode 100644 index 00000000..a620946b --- /dev/null +++ b/packages/lumberaxe/spec/internal/app/models/campground.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Campground < ApplicationRecord + self.table_name = "internal_campgrounds" + + validates :name, presence: true +end diff --git a/packages/lumberaxe/spec/internal/config/routes.rb b/packages/lumberaxe/spec/internal/config/routes.rb index 878c8133..eaa5ece4 100644 --- a/packages/lumberaxe/spec/internal/config/routes.rb +++ b/packages/lumberaxe/spec/internal/config/routes.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Rails.application.routes.draw do - # Add your own routes here, or remove this file if you don't have need for it. + resources :campgrounds, only: :create end diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..7f4bb83663c73c395480302a2306eb785c3c7ead GIT binary patch literal 28672 zcmeI)&raJg90zcl(soR=-DT=-v%&?$pEgC+7?&+W)rM9IW38rchsZQuiIzB!xE0*S zUTCNB4m<8CIFBco(*i1Mx&vYoLSHLYli$yA?N5AhUG@FDx~l~H9E3hsY?VABl#-W> z5kk`XmDR7ylF}#Bmlyh-j+{?AO_LS-NiP4BWMj;wU=w^uo*L zJrxYD?XiY!b1alSX{55nYL$L_G3Y%HZC5H0O77XdP~72)C&i|(k0Gf_Jd7{m_}@cV zVn&~PJ#ke_2RfnPN;o!G2GgG}lHmn#y0vdC7gTq^mBRe56D34}&(Zz&qSO=!QX0 zI#E(=>RRhYQkB@;bqp5gx*{B%EX-;(w>KNQjjdWk&!vm`q&?$)-JX9=lhMKtq7M`Z zKmY;|fB*y_009U<00Izz00i!mz$Q(TWy{*|f}Z1X>97qhj{{jLS1QZpwPmx+%<8&n zu9wRz)wPOgnv*lb_5T?uoZY1XqAw7D00bZa0SG_<0uX=z1Rwwb2;4xRNK@6Bq@N%R z*Z-%aaC(DQaSH?>009U<00Izz00bZa0SG_<0{>Cq4NcEIwk#q0ZWu^kNTo!il6Lu5 zE0yQZ68HaynTNWUwD6ng0|f#QfB*y_009U<00Izz00bZaf%_tmPtDDYd~Xo%|LZ^f zLxBJUAOHafKmY;|fB*y_009U<;2sOa`~O(~-{S|2p+Nuw5P$##AOHafKmY;|fB*!v Fz#qtXO$Pt~ literal 0 HcmV?d00001 diff --git a/packages/lumberaxe/spec/internal/db/schema.rb b/packages/lumberaxe/spec/internal/db/schema.rb index 3b396d0e..a59c0223 100644 --- a/packages/lumberaxe/spec/internal/db/schema.rb +++ b/packages/lumberaxe/spec/internal/db/schema.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true ActiveRecord::Schema.define do - # Set up any tables you need to exist for your test suite that don't belong - # in migrations. + create_table(:internal_campgrounds, force: true) do |t| + t.string :name + t.timestamps + end end diff --git a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb new file mode 100644 index 00000000..66af4bb6 --- /dev/null +++ b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Lumberaxe, type: :request do + subject do + post "/campgrounds", params: { campground: { name: "Cloudland Canyon" } } + end + + it "logs creation" do + expect { subject }.to output(/foo/).to_stdout + end +end diff --git a/packages/lumberaxe/spec/lumberaxe/request_spec.rb b/packages/lumberaxe/spec/lumberaxe/request_spec.rb deleted file mode 100644 index 7ce92a62..00000000 --- a/packages/lumberaxe/spec/lumberaxe/request_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "Lumberaxe integration" do - it "prints to stdout" do - expect { print("foo") }.to output(/foo/).to_stdout - end -end diff --git a/packages/lumberaxe/spec/rails_helper.rb b/packages/lumberaxe/spec/rails_helper.rb index 290f2c14..59247d9e 100644 --- a/packages/lumberaxe/spec/rails_helper.rb +++ b/packages/lumberaxe/spec/rails_helper.rb @@ -3,4 +3,6 @@ require_relative "spec_helper" require "lumberaxe/railtie" -Combustion.initialize! +Combustion.initialize! :active_record, :action_controller + +require "rspec/rails" From c5f52dc93f2709a899c1fc708cf798e466dd295b Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 13:41:25 -0400 Subject: [PATCH 16/32] Spec coverage and refactor/modernize --- packages/lumberaxe/lib/lumberaxe.rb | 3 +- .../lumberaxe/lib/lumberaxe/json_formatter.rb | 32 ++++++++++ .../lumberaxe/lib/lumberaxe/log_chooser.rb | 56 ------------------ packages/lumberaxe/lib/lumberaxe/logger.rb | 15 +++++ packages/lumberaxe/lib/lumberaxe/railtie.rb | 14 ++++- .../spec/internal/db/combustion_test.sqlite | Bin 28672 -> 28672 bytes .../spec/lumberaxe/lumberaxe_spec.rb | 22 ++++++- .../lumberaxe/spec/lumberaxe/railtie_spec.rb | 9 --- 8 files changed, 80 insertions(+), 71 deletions(-) create mode 100644 packages/lumberaxe/lib/lumberaxe/json_formatter.rb delete mode 100644 packages/lumberaxe/lib/lumberaxe/log_chooser.rb create mode 100644 packages/lumberaxe/lib/lumberaxe/logger.rb delete mode 100644 packages/lumberaxe/spec/lumberaxe/railtie_spec.rb diff --git a/packages/lumberaxe/lib/lumberaxe.rb b/packages/lumberaxe/lib/lumberaxe.rb index 4bd589cf..1ae1d9b1 100644 --- a/packages/lumberaxe/lib/lumberaxe.rb +++ b/packages/lumberaxe/lib/lumberaxe.rb @@ -3,7 +3,8 @@ require "logger" require "active_support" require "lumberaxe/railtie" if defined?(Rails) -require "lumberaxe/log_chooser" +require "lumberaxe/logger" +require "lumberaxe/json_formatter" module Lumberaxe end diff --git a/packages/lumberaxe/lib/lumberaxe/json_formatter.rb b/packages/lumberaxe/lib/lumberaxe/json_formatter.rb new file mode 100644 index 00000000..4266a25c --- /dev/null +++ b/packages/lumberaxe/lib/lumberaxe/json_formatter.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require "active_support/tagged_logging" + +module Lumberaxe + class JSONFormatter < ::Logger::Formatter + include ActiveSupport::TaggedLogging::Formatter + + def call(severity, time, progname, data) + data = data.is_a?(Hash) ? format_data(data) : { message: data.to_s } + + { + level: severity, + time: Time.now, # rubocop:disable Rails/TimeZone + progname: progname, + }.merge(data).to_json.concat("\r\n") + end + + def format_data(data) + data.merge!(current_tags.each_with_object({}) do |tag, hash| + if tag.include?("=") + key, value = tag.split("=") + hash[key] = value + else + hash[:tags] ||= [] + hash[:tags] << key + end + hash + end) + end + end +end diff --git a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb b/packages/lumberaxe/lib/lumberaxe/log_chooser.rb deleted file mode 100644 index 848e0833..00000000 --- a/packages/lumberaxe/lib/lumberaxe/log_chooser.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module Lumberaxe - class LogChooser - cattr_accessor :log_level - - def self.logger(progname:) - logger = Logger.new(primary_logdev, progname: progname) - logger.level = log_level - logger.formatter = JSONFormatter.new if structured_logging? - logger - end - - # Standard practice for applications running in Docker containers - # is to send their logging output to STDOUT instead of various - # logfiles on disk. - cattr_accessor :primary_logdev do - $stdout - end - - def self.structured_logging? - ENV.key?("STRUCTURED_LOGGING") - end - end - - class JSONFormatter < ::Logger::Formatter - include ActiveSupport::TaggedLogging::Formatter - - def call(severity, time, progname, data) - data = { message: data.to_s } unless data.is_a?(Hash) - - formatter = { - level: severity, - time: time, - progname: progname, - }.merge(format_data(data)) - - "#{formatter.to_json}\r\n}" - end - - private - - def format_data(data) - data.merge!(current_tags.each_with_object({}) do |tag, hash| - if tag.include?("=") - key, value = tag.split("=") - hash[key] = value - else - hash[:tags] ||= [] - hash[:tags] << key - end - hash - end) - end - end -end diff --git a/packages/lumberaxe/lib/lumberaxe/logger.rb b/packages/lumberaxe/lib/lumberaxe/logger.rb new file mode 100644 index 00000000..742ab8f1 --- /dev/null +++ b/packages/lumberaxe/lib/lumberaxe/logger.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Lumberaxe + class Logger < ::ActiveSupport::Logger + def initialize(output = $stdout, level:, progname:) + super output + + self.progname = progname + self.level = level + + self.formatter = JSONFormatter.new + self.extend ActiveSupport::TaggedLogging + end + end +end diff --git a/packages/lumberaxe/lib/lumberaxe/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb index b161d0cd..ee73abaf 100644 --- a/packages/lumberaxe/lib/lumberaxe/railtie.rb +++ b/packages/lumberaxe/lib/lumberaxe/railtie.rb @@ -1,9 +1,19 @@ # frozen_string_literal: true +require "lograge" + module Lumberaxe class Railtie < Rails::Railtie - initializer "lumberaxe.configurations" do - Lumberaxe::LogChooser.log_level = Rails.application.config.log_level + initializer "lumberaxe.configurations", before: :initialize_logger do |app| + Rails.logger = Lumberaxe::Logger.new(progname: "app", level: app.config.log_level) + end + + initializer "lumberaxe.lograge" do + config.lograge.enabled = true + config.lograge.formatter = Lograge::Formatters::Raw.new + config.lograge.custom_options = ->(event) do + { "params" => event.payload[:params].without("controller", "action") } + end end end end diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite index 7f4bb83663c73c395480302a2306eb785c3c7ead..8d347f189b8ae44d61ec5ed77dedee1217a0ab56 100644 GIT binary patch delta 329 zcmZp8z}WDBae_1>$3z)tMvjdMOZa(M_^vSUZ{^S8m*=~(Sy12zACo7`yBI!w(?ER3+~0LyqXfplmin`CNaZft^G z2S{e}R(ScO%>V!Z delta 174 zcmZp8z}WDBae_1>>qHr6M%Il9OZeFs`L{CgZ`~}Yu$rIAlX0@5yqu|lf}yFEp`n$5 zfu5;_k)ffXk%5tsu7QQFA%+Yu0|Nsi|8oZZ=bHr`?($2DGcucUX6BWo7Ud=8#3v`_ g7Ni&Dm*%AuZ!);buZ^VL*vQDz9IL?)nMDo;0Pw;qIRF3v diff --git a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb index 66af4bb6..b7d3191f 100644 --- a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb +++ b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb @@ -4,10 +4,26 @@ RSpec.describe Lumberaxe, type: :request do subject do - post "/campgrounds", params: { campground: { name: "Cloudland Canyon" } } + post "/campgrounds", params: { campground: { name: "Cloudland Canyon" }, format: :json } end - it "logs creation" do - expect { subject }.to output(/foo/).to_stdout + it "contains key/value pairs" do + expect { subject }.to output(/"message":/).to_stdout_from_any_process + end + + it "logs HTTP requests" do + expect { subject }.to output(/"method":"POST","path":"\/campgrounds"/).to_stdout_from_any_process + end + + it "logs any params" do + expect { subject }.to output(/"params":{"campground":{"name":"Cloudland Canyon"}/).to_stdout_from_any_process + end + + it "logs DB requests" do + expect { subject }.to output(/INSERT INTO/).to_stdout_from_any_process + end + + it "logs error response" do + expect { post "/campgrounds", params: { campground: { name: nil } } }.to output(/"status":422/).to_stdout_from_any_process end end diff --git a/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb b/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb deleted file mode 100644 index 776099ae..00000000 --- a/packages/lumberaxe/spec/lumberaxe/railtie_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "Lumberaxe::Railtie" do - it "sets the correct log level" do - expect(Lumberaxe::LogChooser.log_level).to eql(::Rails.application.config.log_level) - end -end From cb452a14e58179296cf6e50db4c7bd4247c35e4f Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 13:46:39 -0400 Subject: [PATCH 17/32] Add instructions to readme --- packages/lumberaxe/docs/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index 1f757747..5c8efbe6 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -1,3 +1,31 @@ # Lumberaxe Lumberaxe handles logging output formatting. + +# Usage + +After installing the gem, add any additional log tags you would like + +```ruby +# application.rb + +config.log_tags = [ + ->(req) { "request_id=#{req.uuid}" }, + ->(req) { "IP=#{req.remote_ip}" }, +] +``` + +Updating the formatter for your webserver is also recommended. + +```ruby +# puma.rb + +log_formatter do |message| + { + level: "INFO", + time: Time.now, + progname: "puma", + message: message, + }.to_json.concat("\r\n") +end +``` From 1a546c412afbc16fc211010333e47dde8d716784 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 13:55:21 -0400 Subject: [PATCH 18/32] Regenerate rubocop todos --- packages/lumberaxe/.rubocop.yml | 2 ++ packages/lumberaxe/.rubocop_todo.yml | 37 ++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/lumberaxe/.rubocop.yml b/packages/lumberaxe/.rubocop.yml index 0e631c26..945569d1 100644 --- a/packages/lumberaxe/.rubocop.yml +++ b/packages/lumberaxe/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + require: - rubocop-powerhome diff --git a/packages/lumberaxe/.rubocop_todo.yml b/packages/lumberaxe/.rubocop_todo.yml index 0599d757..c57e81a2 100644 --- a/packages/lumberaxe/.rubocop_todo.yml +++ b/packages/lumberaxe/.rubocop_todo.yml @@ -1,20 +1,41 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 500` -# on 2021-10-25 18:39:47 UTC using RuboCop version 1.20.0. +# on 2022-08-11 17:54:39 UTC using RuboCop version 1.29.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 -# Cop supports --auto-correct. -Style/GlobalStdStream: +# This cop supports safe auto-correction (--auto-correct). +Lint/RedundantCopDisableDirective: Exclude: - - 'lib/lumberaxe/log_chooser.rb' + - 'lib/lumberaxe/json_formatter.rb' # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Mode. -Style/StringConcatenation: +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: Exclude: - - 'lib/lumberaxe/log_chooser.rb' + - 'lib/lumberaxe/json_formatter.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantSelf: + Exclude: + - 'lib/lumberaxe/logger.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'spec/lumberaxe/lumberaxe_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 126 From 4421d1770f3b4d3cb301bc3dcec6b823bb1a848b Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 15:26:14 -0400 Subject: [PATCH 19/32] Finish docs; backwards compatibility Ensure Nitro can do non-json logging for local dev --- packages/lumberaxe/docs/README.md | 2 ++ packages/lumberaxe/lib/lumberaxe/railtie.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index 5c8efbe6..45a311aa 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -9,6 +9,8 @@ After installing the gem, add any additional log tags you would like ```ruby # application.rb +require "lumberaxe" + config.log_tags = [ ->(req) { "request_id=#{req.uuid}" }, ->(req) { "IP=#{req.remote_ip}" }, diff --git a/packages/lumberaxe/lib/lumberaxe/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb index ee73abaf..57024427 100644 --- a/packages/lumberaxe/lib/lumberaxe/railtie.rb +++ b/packages/lumberaxe/lib/lumberaxe/railtie.rb @@ -5,7 +5,7 @@ module Lumberaxe class Railtie < Rails::Railtie initializer "lumberaxe.configurations", before: :initialize_logger do |app| - Rails.logger = Lumberaxe::Logger.new(progname: "app", level: app.config.log_level) + Rails.logger = app.config.logger || Lumberaxe::Logger.new(progname: "app", level: app.config.log_level) end initializer "lumberaxe.lograge" do From e28692f89b562245a93f357b6017969044b73574 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 15:47:26 -0400 Subject: [PATCH 20/32] Clarify docs; clear rubocop todos --- packages/lumberaxe/.rubocop_todo.yml | 36 +----------------- packages/lumberaxe/docs/README.md | 4 +- .../lumberaxe/lib/lumberaxe/json_formatter.rb | 2 +- packages/lumberaxe/lib/lumberaxe/logger.rb | 2 +- .../spec/internal/db/combustion_test.sqlite | Bin 28672 -> 28672 bytes .../spec/lumberaxe/lumberaxe_spec.rb | 6 ++- 6 files changed, 10 insertions(+), 40 deletions(-) diff --git a/packages/lumberaxe/.rubocop_todo.yml b/packages/lumberaxe/.rubocop_todo.yml index c57e81a2..3665469a 100644 --- a/packages/lumberaxe/.rubocop_todo.yml +++ b/packages/lumberaxe/.rubocop_todo.yml @@ -1,41 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 500` -# on 2022-08-11 17:54:39 UTC using RuboCop version 1.29.1. +# on 2022-08-11 19:45:17 UTC using RuboCop version 1.29.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Lint/RedundantCopDisableDirective: - Exclude: - - 'lib/lumberaxe/json_formatter.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. -Lint/UnusedMethodArgument: - Exclude: - - 'lib/lumberaxe/json_formatter.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -Style/RedundantSelf: - Exclude: - - 'lib/lumberaxe/logger.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'spec/lumberaxe/lumberaxe_spec.rb' - -# Offense count: 1 -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 126 diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index 45a311aa..b809400e 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -17,7 +17,9 @@ config.log_tags = [ ] ``` -Updating the formatter for your webserver is also recommended. +## Setting JSON logging + +To set up JSON logging on puma, add this to your puma config: ```ruby # puma.rb diff --git a/packages/lumberaxe/lib/lumberaxe/json_formatter.rb b/packages/lumberaxe/lib/lumberaxe/json_formatter.rb index 4266a25c..cb690028 100644 --- a/packages/lumberaxe/lib/lumberaxe/json_formatter.rb +++ b/packages/lumberaxe/lib/lumberaxe/json_formatter.rb @@ -11,7 +11,7 @@ def call(severity, time, progname, data) { level: severity, - time: Time.now, # rubocop:disable Rails/TimeZone + time: time, progname: progname, }.merge(data).to_json.concat("\r\n") end diff --git a/packages/lumberaxe/lib/lumberaxe/logger.rb b/packages/lumberaxe/lib/lumberaxe/logger.rb index 742ab8f1..5cce13cd 100644 --- a/packages/lumberaxe/lib/lumberaxe/logger.rb +++ b/packages/lumberaxe/lib/lumberaxe/logger.rb @@ -9,7 +9,7 @@ def initialize(output = $stdout, level:, progname:) self.level = level self.formatter = JSONFormatter.new - self.extend ActiveSupport::TaggedLogging + extend ActiveSupport::TaggedLogging end end end diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite index 8d347f189b8ae44d61ec5ed77dedee1217a0ab56..eafcbeac367503a2bffa24dd38466529bd494c12 100644 GIT binary patch delta 237 zcmZp8z}WDBal>~x4NEH%BP#<_J!4aIOG5)A10y3{0}EY4Lj^-rnaT3<%325^V~x4Rb4FLn}jLJwr1iBQr}Q10y3{0}EY4Lj^-rnaT3<%35$CQ*#pw zBdm(SGM-G673CF?lpC2Fn_yQClJR5&DMvWP#LU9P6svNu%qE2!@=(P_dX}b!rl!W2 KieWN~91H-XhBH+F diff --git a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb index b7d3191f..1b77f0a2 100644 --- a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb +++ b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb @@ -12,7 +12,7 @@ end it "logs HTTP requests" do - expect { subject }.to output(/"method":"POST","path":"\/campgrounds"/).to_stdout_from_any_process + expect { subject }.to output(%r{"method":"POST","path":"/campgrounds"}).to_stdout_from_any_process end it "logs any params" do @@ -24,6 +24,8 @@ end it "logs error response" do - expect { post "/campgrounds", params: { campground: { name: nil } } }.to output(/"status":422/).to_stdout_from_any_process + expect do + post "/campgrounds", params: { campground: { name: nil } } + end.to output(/"status":422/).to_stdout_from_any_process end end From 0e95cf1a6a0d6a64938fa73fb4458edbd8e88a38 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 15:49:16 -0400 Subject: [PATCH 21/32] Ignore sqlite file --- packages/lumberaxe/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/lumberaxe/.gitignore b/packages/lumberaxe/.gitignore index 8b650730..7ffdd21b 100644 --- a/packages/lumberaxe/.gitignore +++ b/packages/lumberaxe/.gitignore @@ -9,4 +9,5 @@ pkg !tmp/.gitignore vendor/bundle *.log +*.sqlite *.sqlite3 From 5f994c8bc6d65020464cc69958d339a3ef203c39 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 15:58:09 -0400 Subject: [PATCH 22/32] Test rails logger output --- .../spec/internal/app/controllers/campgrounds_controller.rb | 2 ++ packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb b/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb index 4c9eecf9..5ed14564 100644 --- a/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb +++ b/packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb @@ -5,6 +5,8 @@ def create campground_params = params.require(:campground).permit(:name) campground = Campground.new(campground_params) + Rails.logger.warn("Creating campground named #{campground.name}") + if campground.save render json: campground, status: :created else diff --git a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb index 1b77f0a2..b45d887a 100644 --- a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb +++ b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb @@ -19,6 +19,10 @@ expect { subject }.to output(/"params":{"campground":{"name":"Cloudland Canyon"}/).to_stdout_from_any_process end + it "logs anything passed to the rails logger" do + expect { subject }.to output(/Creating campground named Cloudland Canyon/).to_stdout_from_any_process + end + it "logs DB requests" do expect { subject }.to output(/INSERT INTO/).to_stdout_from_any_process end From e4de28599cefe79b57960a424b3d683f07a3a48b Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 16:04:57 -0400 Subject: [PATCH 23/32] Specify released files --- packages/lumberaxe/lumberaxe.gemspec | 11 ++++++++++- .../spec/internal/db/combustion_test.sqlite | Bin 28672 -> 28672 bytes 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index dec8bfef..a9d79506 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -21,7 +21,16 @@ Gem::Specification.new do |spec| spec.metadata["source_code_uri"] = spec.homepage spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/lumberaxe/docs/CHANGELOG.md" - spec.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "docs/README.md"] + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] spec.add_dependency "activesupport", ">= 5.2.8.1" spec.add_dependency "lograge", "0.10.0" diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite index eafcbeac367503a2bffa24dd38466529bd494c12..391f33379e524bcf2ea42dc8734e07f12151a8fc 100644 GIT binary patch delta 315 zcmZp8z}WDBae_1>=R_H2M$U~1OZfR%`8pZ+xAJH4%ky2~>)b3TP|nBX$vRn4URlG` z)XKz2&(z4s%+S!tz{p6~z(Uv1P{GjB3R%XJ1*BLFDr9JGVPb++F<54@yu2#RTtg!x zOH=GhK{B39$c`{DH#0WJsu(Qe$%y0#6H8+w6ANsLAu^j3{_``kZZf#V4|TPX3DARP M*fc<77C9II0OB4*9smFU delta 268 zcmZp8z}WDBae_1>$3z)tMvjdMOZa(M_^vSUZ{^S8m*=~(Sy15!ACo7`WJP&pH4`H% z15-U?Q*%p010w??BV7XvT|+|!LrW`UnaT3V`Fm0o=hNfVTw%*EDg-C xDhA7VG9o*|*u=!d9IIlm%qE5Z{ERG{3~up*U2URgX=!0;Y>24=CbP)F008LxI|~2+ From ac525667d782199303e439488a63b1535d8e2fcf Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 16:17:56 -0400 Subject: [PATCH 24/32] Update gemspec --- packages/lumberaxe/Gemfile.lock | 15 +++++++-------- packages/lumberaxe/lumberaxe.gemspec | 6 +++--- .../spec/internal/db/combustion_test.sqlite | Bin 28672 -> 28672 bytes 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index 2a062768..d152b01a 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -157,10 +157,10 @@ GEM rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-rails (4.1.1) - actionpack (>= 4.2) - activesupport (>= 4.2) - railties (>= 4.2) + rspec-rails (5.1.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) rspec-core (~> 3.10) rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) @@ -209,7 +209,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.3.13) + sqlite3 (1.4.4) test-unit (3.1.5) power_assert thor (1.2.1) @@ -236,7 +236,6 @@ PLATFORMS x86_64-linux DEPENDENCIES - bundler (~> 2.1) combustion (~> 1.3) license_finder (~> 7.0) lumberaxe! @@ -246,10 +245,10 @@ DEPENDENCIES rainbow (= 2.2.2) rake (~> 13.0) rspec (~> 3.0) - rspec-rails (= 4.1.1) + rspec-rails (~> 5.1.2) rubocop-powerhome (= 0.5.0) simplecov (= 0.15.1) - sqlite3 (= 1.3.13) + sqlite3 (~> 1.4.2) test-unit (= 3.1.5) yard (= 0.9.21) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index a9d79506..d9055d76 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -35,7 +35,7 @@ Gem::Specification.new do |spec| spec.add_dependency "activesupport", ">= 5.2.8.1" spec.add_dependency "lograge", "0.10.0" - spec.add_development_dependency "bundler", "~> 2.1" + # spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "combustion", "~> 1.3" spec.add_development_dependency "license_finder", "~> 7.0" spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" @@ -44,10 +44,10 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rainbow", "2.2.2" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rspec-rails", "4.1.1" + spec.add_development_dependency "rspec-rails", "~> 5.1.2" spec.add_development_dependency "rubocop-powerhome", "0.5.0" spec.add_development_dependency "simplecov", "0.15.1" - spec.add_development_dependency "sqlite3", "1.3.13" + spec.add_development_dependency "sqlite3", "~> 1.4.2" spec.add_development_dependency "test-unit", "3.1.5" spec.add_development_dependency "yard", "0.9.21" end diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite index 391f33379e524bcf2ea42dc8734e07f12151a8fc..286f5b89467b2b8eb49e47b83dd32bfa92b73e4a 100644 GIT binary patch delta 290 zcmZp8z}WDBal>jkZ6gCKLo+J_6Fmz}eULqi2L8BdnUit-AY2vGxb zOH=IX!7`KO<&}_3H!wCcFu`g%SjLkHWI95jkZ9_{dQ&TGwBRx|iBQrxoBLgENT>}eULqi2L8BdnUit-AY2vI|G z3lkHp>cKLT<>i%-OgA(#vNXl68YJV%1Tq~-y@9!zu{l=tU>Q$FRM(hT8XK8dU{eo~ Y*`#n?9^rN)6QEDcu&IW~EOIaa0QDa|>;M1& From 3fe24a778583d7a3c89b55288367091f89b2f92a Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 16:18:56 -0400 Subject: [PATCH 25/32] Remove gitignored file --- .../spec/internal/db/combustion_test.sqlite | Bin 28672 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 packages/lumberaxe/spec/internal/db/combustion_test.sqlite diff --git a/packages/lumberaxe/spec/internal/db/combustion_test.sqlite b/packages/lumberaxe/spec/internal/db/combustion_test.sqlite deleted file mode 100644 index 286f5b89467b2b8eb49e47b83dd32bfa92b73e4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28672 zcmeI)O;6h}7zc2hzKw~tyG-SV6)qs&l0azTvSp~+s+Gc6(ZqI$yvBoUO#*3J!ENle zPqWkb4m(cTXV`swf;lZku%;7}*n#SArK;n{d20XSi<_!1UsRn?uy=mo@{lc)2ZU1c zm@z`gxO`>gt6vhblI)+zcY38htU68>t;uZe8%a-`ll*k zGE)ZP3Y$?nB528r71rTF?^HI;ojvxvyfUfYvY``Gjh$lS3N7RB~OaCNaTbGN=#smUCh<(gbe7wbuSM&r6Y|EwfS z8h?TsHFu>W4gMot*)ypizQ7js>{P8mE_G+sl_!TK2{m9w-oi00bZa0SG_<0uX=z1Rwwb2;6Cb zNt!Td+%FJPz5V|g$)DZn31aXNfB*y_009U<00Izz00bZafe{pVMpM%dO;dOsC-6O2 zcws17Vcb)GW2K}T#_-5}sYCO>h&)gr009U<00Izz00bZa0SG_<0uUG#fm~vG{L1$R z(er=#r++9AfB*y_009U<00Izz00bZa0SJt+K=k|{`~MNX!I&BZAOHafKmY;|fB*y_ L009U Date: Thu, 11 Aug 2022 17:15:11 -0400 Subject: [PATCH 26/32] More gemspec updates --- packages/lumberaxe/Gemfile.lock | 3 ++- packages/lumberaxe/lumberaxe.gemspec | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock index d152b01a..40a09fc4 100644 --- a/packages/lumberaxe/Gemfile.lock +++ b/packages/lumberaxe/Gemfile.lock @@ -236,8 +236,9 @@ PLATFORMS x86_64-linux DEPENDENCIES + bundler (~> 2.1) combustion (~> 1.3) - license_finder (~> 7.0) + license_finder (>= 7.0) lumberaxe! parser (>= 2.5, != 2.5.1.1) pry-byebug (= 3.9.0) diff --git a/packages/lumberaxe/lumberaxe.gemspec b/packages/lumberaxe/lumberaxe.gemspec index d9055d76..151d75ff 100644 --- a/packages/lumberaxe/lumberaxe.gemspec +++ b/packages/lumberaxe/lumberaxe.gemspec @@ -35,9 +35,9 @@ Gem::Specification.new do |spec| spec.add_dependency "activesupport", ">= 5.2.8.1" spec.add_dependency "lograge", "0.10.0" - # spec.add_development_dependency "bundler", "~> 2.1" + spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "combustion", "~> 1.3" - spec.add_development_dependency "license_finder", "~> 7.0" + spec.add_development_dependency "license_finder", ">= 7.0" spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" spec.add_development_dependency "pry-byebug", "3.9.0" spec.add_development_dependency "rails", ">= 5.2.8.1" From cd1536c1f272d819a89aab6c87031907f5a0ef0c Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 11 Aug 2022 18:21:16 -0300 Subject: [PATCH 27/32] Ignore Gemfile.lock --- packages/lumberaxe/.gitignore | 1 + packages/lumberaxe/Gemfile.lock | 257 -------------------------------- 2 files changed, 1 insertion(+), 257 deletions(-) delete mode 100644 packages/lumberaxe/Gemfile.lock diff --git a/packages/lumberaxe/.gitignore b/packages/lumberaxe/.gitignore index 7ffdd21b..2f3de776 100644 --- a/packages/lumberaxe/.gitignore +++ b/packages/lumberaxe/.gitignore @@ -11,3 +11,4 @@ vendor/bundle *.log *.sqlite *.sqlite3 +Gemfile.lock diff --git a/packages/lumberaxe/Gemfile.lock b/packages/lumberaxe/Gemfile.lock deleted file mode 100644 index 40a09fc4..00000000 --- a/packages/lumberaxe/Gemfile.lock +++ /dev/null @@ -1,257 +0,0 @@ -PATH - remote: . - specs: - lumberaxe (0.1.0) - activesupport (>= 5.2.8.1) - lograge (= 0.10.0) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.2.8.1) - actionpack (= 5.2.8.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) - globalid (>= 0.3.6) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) - activestorage (5.2.8.1) - actionpack (= 5.2.8.1) - activerecord (= 5.2.8.1) - marcel (~> 1.0.0) - activesupport (5.2.8.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (9.0.0) - ast (2.4.2) - builder (3.2.4) - byebug (11.1.3) - coderay (1.1.3) - combustion (1.3.7) - activesupport (>= 3.0.0) - railties (>= 3.0.0) - thor (>= 0.14.6) - concurrent-ruby (1.1.10) - crass (1.0.6) - diff-lcs (1.5.0) - docile (1.1.5) - erubi (1.11.0) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - json (2.5.1) - license_finder (7.0.1) - bundler - rubyzip (>= 1, < 3) - thor (~> 1.2) - tomlrb (>= 1.3, < 2.1) - with_env (= 1.1.0) - xml-simple (~> 1.1.9) - lograge (0.10.0) - actionpack (>= 4) - activesupport (>= 4) - railties (>= 4) - request_store (~> 1.0) - loofah (2.18.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.16.2) - nio4r (2.5.8) - nokogiri (1.13.8) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - nokogiri (1.13.8-arm64-darwin) - racc (~> 1.4) - nokogiri (1.13.8-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.13.8-x86_64-linux) - racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.0) - ast (~> 2.4.1) - power_assert (2.0.0) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - racc (1.6.0) - rack (2.2.4) - rack-test (2.0.2) - rack (>= 1.3) - rails (5.2.8.1) - actioncable (= 5.2.8.1) - actionmailer (= 5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - activemodel (= 5.2.8.1) - activerecord (= 5.2.8.1) - activestorage (= 5.2.8.1) - activesupport (= 5.2.8.1) - bundler (>= 1.3.0) - railties (= 5.2.8.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (2.2.2) - rake - rake (13.0.6) - regexp_parser (2.5.0) - request_store (1.5.1) - rack (>= 1.4) - rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.2) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-rails (5.1.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.10.3) - rubocop (1.20.0) - parallel (~> 1.10) - parser (>= 3.0.0.0) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.9.1, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.19.1) - parser (>= 3.1.1.0) - rubocop-performance (1.11.5) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-powerhome (0.5.0) - rubocop - rubocop-performance - rubocop-rails - rubocop-rake - rubocop-rspec - rubocop-rails (2.12.2) - activesupport (>= 4.2.0) - rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-rake (0.6.0) - rubocop (~> 1.0) - rubocop-rspec (2.4.0) - rubocop (~> 1.0) - rubocop-ast (>= 1.1.0) - ruby-progressbar (1.11.0) - rubyzip (2.3.2) - simplecov (0.15.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sprockets (4.1.1) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - sqlite3 (1.4.4) - test-unit (3.1.5) - power_assert - thor (1.2.1) - thread_safe (0.3.6) - tomlrb (2.0.3) - tzinfo (1.2.10) - thread_safe (~> 0.1) - unicode-display_width (2.2.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - with_env (1.1.0) - xml-simple (1.1.9) - rexml - yard (0.9.21) - -PLATFORMS - arm64-darwin-20 - arm64-darwin-21 - ruby - x86_64-darwin-19 - x86_64-darwin-20 - x86_64-darwin-21 - x86_64-linux - -DEPENDENCIES - bundler (~> 2.1) - combustion (~> 1.3) - license_finder (>= 7.0) - lumberaxe! - parser (>= 2.5, != 2.5.1.1) - pry-byebug (= 3.9.0) - rails (>= 5.2.8.1) - rainbow (= 2.2.2) - rake (~> 13.0) - rspec (~> 3.0) - rspec-rails (~> 5.1.2) - rubocop-powerhome (= 0.5.0) - simplecov (= 0.15.1) - sqlite3 (~> 1.4.2) - test-unit (= 3.1.5) - yard (= 0.9.21) - -BUNDLED WITH - 2.3.14 From b7ff4fb0f576b2040db4695f5737080fcaea7e64 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 17:44:48 -0400 Subject: [PATCH 28/32] Abstract logging config --- packages/lumberaxe/docs/README.md | 9 +-------- packages/lumberaxe/lib/lumberaxe.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index b809400e..b53d2868 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -24,12 +24,5 @@ To set up JSON logging on puma, add this to your puma config: ```ruby # puma.rb -log_formatter do |message| - { - level: "INFO", - time: Time.now, - progname: "puma", - message: message, - }.to_json.concat("\r\n") -end +log_formatter &Lumberaxe.puma_formatter ``` diff --git a/packages/lumberaxe/lib/lumberaxe.rb b/packages/lumberaxe/lib/lumberaxe.rb index 1ae1d9b1..36ce3797 100644 --- a/packages/lumberaxe/lib/lumberaxe.rb +++ b/packages/lumberaxe/lib/lumberaxe.rb @@ -7,4 +7,14 @@ require "lumberaxe/json_formatter" module Lumberaxe + def self.puma_formatter(level: "INFO", progname: "puma") + ->(message) do + { + level: level, + time: Time.now, + progname: progname, + message: message, + }.to_json.concat("\r\n") + end + end end From 228f8200d791c51ddfbb7b85e66cf3a95cdbe4bc Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Thu, 11 Aug 2022 18:24:49 -0400 Subject: [PATCH 29/32] Set default log tags --- packages/lumberaxe/docs/README.md | 7 +------ packages/lumberaxe/lib/lumberaxe/railtie.rb | 5 +++++ .../lumberaxe/spec/lumberaxe/lumberaxe_spec.rb | 14 +++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index b53d2868..7f338b29 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -4,17 +4,12 @@ Lumberaxe handles logging output formatting. # Usage -After installing the gem, add any additional log tags you would like +After installing the gem, require it as part of your application configuration. ```ruby # application.rb require "lumberaxe" - -config.log_tags = [ - ->(req) { "request_id=#{req.uuid}" }, - ->(req) { "IP=#{req.remote_ip}" }, -] ``` ## Setting JSON logging diff --git a/packages/lumberaxe/lib/lumberaxe/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb index 57024427..f9a0a05e 100644 --- a/packages/lumberaxe/lib/lumberaxe/railtie.rb +++ b/packages/lumberaxe/lib/lumberaxe/railtie.rb @@ -6,6 +6,11 @@ module Lumberaxe class Railtie < Rails::Railtie initializer "lumberaxe.configurations", before: :initialize_logger do |app| Rails.logger = app.config.logger || Lumberaxe::Logger.new(progname: "app", level: app.config.log_level) + + app.config.log_tags = [ + ->(req) { "request_id=#{req.uuid}" }, + ->(req) { "IP=#{req.remote_ip}" }, + ] end initializer "lumberaxe.lograge" do diff --git a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb index b45d887a..94dd6edd 100644 --- a/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb +++ b/packages/lumberaxe/spec/lumberaxe/lumberaxe_spec.rb @@ -7,7 +7,19 @@ post "/campgrounds", params: { campground: { name: "Cloudland Canyon" }, format: :json } end - it "contains key/value pairs" do + it "tags request_id" do + expect { subject }.to output(/"request_id":/).to_stdout_from_any_process + end + + it "tags IP" do + expect { subject }.to output(/"IP":/).to_stdout_from_any_process + end + + it "contains the defined progname" do + expect { subject }.to output(/"progname":"app"/).to_stdout_from_any_process + end + + it "contains message key/value pairs" do expect { subject }.to output(/"message":/).to_stdout_from_any_process end From 6962dbbad002ef175aa5b834877d49fb6788eb5f Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Fri, 12 Aug 2022 09:43:53 -0400 Subject: [PATCH 30/32] Set default log level from app --- packages/lumberaxe/lib/lumberaxe/logger.rb | 4 +++- packages/lumberaxe/lib/lumberaxe/railtie.rb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/lumberaxe/lib/lumberaxe/logger.rb b/packages/lumberaxe/lib/lumberaxe/logger.rb index 5cce13cd..0b310646 100644 --- a/packages/lumberaxe/lib/lumberaxe/logger.rb +++ b/packages/lumberaxe/lib/lumberaxe/logger.rb @@ -2,7 +2,9 @@ module Lumberaxe class Logger < ::ActiveSupport::Logger - def initialize(output = $stdout, level:, progname:) + cattr_accessor :log_level + + def initialize(output = $stdout, level: log_level, progname:) super output self.progname = progname diff --git a/packages/lumberaxe/lib/lumberaxe/railtie.rb b/packages/lumberaxe/lib/lumberaxe/railtie.rb index f9a0a05e..792908d2 100644 --- a/packages/lumberaxe/lib/lumberaxe/railtie.rb +++ b/packages/lumberaxe/lib/lumberaxe/railtie.rb @@ -11,6 +11,8 @@ class Railtie < Rails::Railtie ->(req) { "request_id=#{req.uuid}" }, ->(req) { "IP=#{req.remote_ip}" }, ] + + Lumberaxe::Logger.log_level = app.config.log_level end initializer "lumberaxe.lograge" do From fedbed246db0f9dd8aceff8ccfdb5de4ded9a4b3 Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Fri, 12 Aug 2022 09:50:49 -0400 Subject: [PATCH 31/32] Update for rubocop rules --- packages/lumberaxe/docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lumberaxe/docs/README.md b/packages/lumberaxe/docs/README.md index 7f338b29..b6db5ea0 100644 --- a/packages/lumberaxe/docs/README.md +++ b/packages/lumberaxe/docs/README.md @@ -19,5 +19,5 @@ To set up JSON logging on puma, add this to your puma config: ```ruby # puma.rb -log_formatter &Lumberaxe.puma_formatter +log_formatter(&Lumberaxe.puma_formatter) ``` From 8143d123063cff7d77f43c8abb305d2429bffe4c Mon Sep 17 00:00:00 2001 From: Jill Klang Date: Fri, 12 Aug 2022 09:53:59 -0400 Subject: [PATCH 32/32] Address rubocop violation --- packages/lumberaxe/lib/lumberaxe/logger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lumberaxe/lib/lumberaxe/logger.rb b/packages/lumberaxe/lib/lumberaxe/logger.rb index 0b310646..c4806957 100644 --- a/packages/lumberaxe/lib/lumberaxe/logger.rb +++ b/packages/lumberaxe/lib/lumberaxe/logger.rb @@ -4,7 +4,7 @@ module Lumberaxe class Logger < ::ActiveSupport::Logger cattr_accessor :log_level - def initialize(output = $stdout, level: log_level, progname:) + def initialize(output = $stdout, progname:, level: log_level) super output self.progname = progname